-
Notifications
You must be signed in to change notification settings - Fork 204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create conversion graph #1627
Merged
Merged
Create conversion graph #1627
Changes from 14 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
43179f9
Add FindHubTypeName() to ConversionGraph and test
theunrepentantgeek 196b165
Move shared test values into test package
theunrepentantgeek 3218606
Add CreateConversionGraph() pipeline stage
theunrepentantgeek 41193e6
Integrate into the pipeline
theunrepentantgeek c4f42b6
Code gardening
theunrepentantgeek 6ca3b81
Fix stage naming
theunrepentantgeek 58dcf5e
Fix bug in IsPreview() affecting tests
theunrepentantgeek c2202a5
Implement GroupConversionGraphBuilder and test
theunrepentantgeek 5756d23
Implement ConversionGraphBuilder and test
theunrepentantgeek 85de224
Convert pipeline stage
theunrepentantgeek b58002e
Update tests
theunrepentantgeek 9a876ce
Tweaks for CI
theunrepentantgeek 48fb6c8
Update golden file
theunrepentantgeek 9acaa7f
Merge branch 'master' into feature/create-conversion-graph
theunrepentantgeek cca7dd8
Attempt downgrade of controller-runtime
theunrepentantgeek d28068b
Attempt downgrade of controller-runtime, take II
theunrepentantgeek 9472d0b
Update as per PR comment
theunrepentantgeek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
hack/generator/pkg/codegen/pipeline/create_conversion_graph.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright (c) Microsoft Corporation. | ||
* Licensed under the MIT license. | ||
*/ | ||
|
||
package pipeline | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/pkg/errors" | ||
|
||
"github.com/Azure/azure-service-operator/hack/generator/pkg/astmodel" | ||
"github.com/Azure/azure-service-operator/hack/generator/pkg/codegen/storage" | ||
) | ||
|
||
// CreateConversionGraphStageId is the unique identifier for this stage | ||
const CreateConversionGraphStageId = "createConversionGraph" | ||
|
||
// CreateConversionGraph walks the set of available types and creates a graph of conversions that will be used to | ||
// convert resources to/from the designated storage (or hub) version | ||
func CreateConversionGraph() Stage { | ||
stage := MakeStage( | ||
CreateConversionGraphStageId, | ||
"Create the graph of conversions between versions of each resource group", | ||
func(ctx context.Context, state *State) (*State, error) { | ||
// Collect all distinct references | ||
allReferences := astmodel.NewPackageReferenceSet() | ||
for _, def := range state.Types() { | ||
allReferences.AddReference(def.Name().PackageReference) | ||
} | ||
|
||
builder := storage.NewConversionGraphBuilder() | ||
builder.AddAll(allReferences) | ||
graph, err := builder.Build() | ||
if err != nil { | ||
// Shouldn't have any non-local references, if we do, abort | ||
return nil, errors.Wrapf(err, "creating conversion graph") | ||
} | ||
|
||
return state.WithConversionGraph(graph), nil | ||
}) | ||
|
||
return stage | ||
} |
69 changes: 69 additions & 0 deletions
69
hack/generator/pkg/codegen/pipeline/create_conversion_graph_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright (c) Microsoft Corporation. | ||
* Licensed under the MIT license. | ||
*/ | ||
|
||
package pipeline | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
. "github.com/onsi/gomega" | ||
|
||
"github.com/Azure/azure-service-operator/hack/generator/pkg/astmodel" | ||
"github.com/Azure/azure-service-operator/hack/generator/pkg/test" | ||
) | ||
|
||
func TestCreateConversionGraph(t *testing.T) { | ||
g := NewGomegaWithT(t) | ||
|
||
person2020 := test.CreateSpec(test.Pkg2020, "Person", test.FullNameProperty, test.KnownAsProperty, test.FamilyNameProperty) | ||
person2021 := test.CreateSpec(test.Pkg2021, "Person", test.FullNameProperty, test.KnownAsProperty, test.FamilyNameProperty) | ||
person2022 := test.CreateSpec(test.Pkg2022, "Person", test.FullNameProperty, test.KnownAsProperty, test.FamilyNameProperty) | ||
|
||
types := make(astmodel.Types) | ||
types.AddAll(person2020, person2021, person2022) | ||
|
||
initialState := NewState().WithTypes(types) | ||
stage := CreateConversionGraph() | ||
finalState, err := stage.Run(context.TODO(), initialState) | ||
g.Expect(err).To(Succeed()) | ||
g.Expect(finalState.Types()).To(Equal(types)) | ||
g.Expect(finalState.ConversionGraph()).NotTo(BeNil()) | ||
|
||
graph := finalState.ConversionGraph() | ||
|
||
// Expect to have a link from Pkg2020 to a matching storage version | ||
storage2020, ok := graph.LookupTransition(test.Pkg2020) | ||
g.Expect(ok).To(BeTrue()) | ||
g.Expect(storage2020.String()).To(ContainSubstring(test.Pkg2020.Version())) | ||
|
||
// Expect to have a link from Pkg2021 to a matching storage version | ||
storage2021, ok := graph.LookupTransition(test.Pkg2021) | ||
g.Expect(ok).To(BeTrue()) | ||
g.Expect(storage2021.String()).To(ContainSubstring(test.Pkg2021.Version())) | ||
|
||
// Expect to have a link from Pkg2022 to a matching storage version | ||
storage2022, ok := graph.LookupTransition(test.Pkg2022) | ||
g.Expect(ok).To(BeTrue()) | ||
g.Expect(storage2022.String()).To(ContainSubstring(test.Pkg2022.Version())) | ||
|
||
// Expect to have a link from Storage2020 to Storage2021 | ||
linkedFrom2020, ok := graph.LookupTransition(storage2020) | ||
g.Expect(ok).To(BeTrue()) | ||
g.Expect(linkedFrom2020).To(Equal(storage2021)) | ||
|
||
// Expect to have a link from Storage2021 version Storage2022 | ||
linkedFrom2021, ok := graph.LookupTransition(storage2021) | ||
g.Expect(ok).To(BeTrue()) | ||
g.Expect(linkedFrom2021).To(Equal(storage2022)) | ||
|
||
// Expect NOT to have a link from Storage2022 | ||
_, ok = graph.LookupTransition(storage2022) | ||
g.Expect(ok).To(BeFalse()) | ||
|
||
// Finally, check that the five links we've verified are the only ones there | ||
// We check this last, so that a failure doesn't block more detailed checks | ||
g.Expect(graph.TransitionCount()).To(Equal(5)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it worth having some unrelated types in here to make sure there aren't any links created between Person and OtherType?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted for a followup PR.