From 3be33dfd4501f0bf3f3166ed8fea1ce1348427ee Mon Sep 17 00:00:00 2001 From: Bevan Arps Date: Wed, 7 Jul 2021 13:35:04 +1200 Subject: [PATCH] Make it explicit that we inject OriginalVersion() before creating storate types --- hack/generator/pkg/codegen/pipeline/create_storage_types.go | 4 ++-- .../codegen/pipeline/inject_original_version_function.go | 6 +++++- .../codegen/pipeline/inject_original_version_property.go | 6 +++--- .../pipeline/inject_property_assignment_functions.go | 2 +- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/hack/generator/pkg/codegen/pipeline/create_storage_types.go b/hack/generator/pkg/codegen/pipeline/create_storage_types.go index 55b9b251036..aca9533ce38 100644 --- a/hack/generator/pkg/codegen/pipeline/create_storage_types.go +++ b/hack/generator/pkg/codegen/pipeline/create_storage_types.go @@ -14,14 +14,14 @@ import ( "github.com/Azure/azure-service-operator/hack/generator/pkg/codegen/storage" ) -const createStorageTypesStageId = "createStorageTypes" +const CreateStorageTypesStageId = "createStorageTypes" // CreateStorageTypes returns a pipeline stage that creates dedicated storage types for each resource and nested object. // Storage versions are created for *all* API versions to allow users of older versions of the operator to easily // upgrade. This is of course a bit odd for the first release, but defining the approach from day one is useful. func CreateStorageTypes(conversionGraph *storage.ConversionGraph) Stage { result := MakeStage( - createStorageTypesStageId, + CreateStorageTypesStageId, "Create storage versions of CRD types", func(ctx context.Context, types astmodel.Types) (astmodel.Types, error) { diff --git a/hack/generator/pkg/codegen/pipeline/inject_original_version_function.go b/hack/generator/pkg/codegen/pipeline/inject_original_version_function.go index cb441a7bf01..fea37b6d2c4 100644 --- a/hack/generator/pkg/codegen/pipeline/inject_original_version_function.go +++ b/hack/generator/pkg/codegen/pipeline/inject_original_version_function.go @@ -21,9 +21,10 @@ const injectOriginalVersionFunctionStageId = "injectOriginalVersionFunction" // InjectOriginalVersionFunction injects the function OriginalVersion() into each Spec type // This function allows us to recover the original version used to create each custom resource, giving the operator the // information needed to interact with ARM using the correct API version. +// We run this stage before we create any storage types, ensuring only API versions get the function. func InjectOriginalVersionFunction(idFactory astmodel.IdentifierFactory) Stage { - return MakeStage( + stage := MakeStage( injectOriginalVersionFunctionStageId, "Inject the function OriginalVersion() into each Spec type", func(ctx context.Context, types astmodel.Types) (astmodel.Types, error) { @@ -43,4 +44,7 @@ func InjectOriginalVersionFunction(idFactory astmodel.IdentifierFactory) Stage { return result, nil }) + + stage.RequiresPostrequisiteStages(CreateStorageTypesStageId, InjectOriginalVersionPropertyId) + return stage } diff --git a/hack/generator/pkg/codegen/pipeline/inject_original_version_property.go b/hack/generator/pkg/codegen/pipeline/inject_original_version_property.go index f4f97f4814a..a7f4c4482cb 100644 --- a/hack/generator/pkg/codegen/pipeline/inject_original_version_property.go +++ b/hack/generator/pkg/codegen/pipeline/inject_original_version_property.go @@ -14,8 +14,8 @@ import ( "github.com/Azure/azure-service-operator/hack/generator/pkg/codegen/storage" ) -// injectOriginalVersionPropertyId is the unique identifier for this pipeline stage -const injectOriginalVersionPropertyId = "injectOriginalVersionProperty" +// InjectOriginalVersionPropertyId is the unique identifier for this pipeline stage +const InjectOriginalVersionPropertyId = "injectOriginalVersionProperty" // InjectOriginalVersionProperty injects the property OriginalVersion into each Storage Spec type // This property gets populated by reading from the OriginalVersion() function previously injected into the API Spec @@ -24,7 +24,7 @@ const injectOriginalVersionPropertyId = "injectOriginalVersionProperty" func InjectOriginalVersionProperty() Stage { stage := MakeStage( - injectOriginalVersionPropertyId, + InjectOriginalVersionPropertyId, "Inject the property OriginalVersion into each Storage Spec type", func(ctx context.Context, types astmodel.Types) (astmodel.Types, error) { injector := storage.NewPropertyInjector() diff --git a/hack/generator/pkg/codegen/pipeline/inject_property_assignment_functions.go b/hack/generator/pkg/codegen/pipeline/inject_property_assignment_functions.go index 66820d1b4dd..b62fcf5a2bc 100644 --- a/hack/generator/pkg/codegen/pipeline/inject_property_assignment_functions.go +++ b/hack/generator/pkg/codegen/pipeline/inject_property_assignment_functions.go @@ -70,7 +70,7 @@ func InjectPropertyAssignmentFunctions(graph *storage.ConversionGraph, idFactory }) // Needed to populate the conversion graph - stage.RequiresPrerequisiteStages(createStorageTypesStageId) + stage.RequiresPrerequisiteStages(CreateStorageTypesStageId) return stage }