Skip to content

Commit

Permalink
Integrate into the pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
theunrepentantgeek committed Jul 7, 2021
1 parent baae2e6 commit 4c39ccf
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 392 deletions.
1 change: 1 addition & 0 deletions hack/generator/pkg/codegen/code_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ func createAllPipelineStages(idFactory astmodel.IdentifierFactory, configuration

// Create Storage types
//TODO: For now only used for ARM
pipeline.CreateConversionGraph(graph).UsedFor(pipeline.ARMTarget),
pipeline.InjectOriginalVersionFunction(idFactory).UsedFor(pipeline.ARMTarget),
pipeline.CreateStorageTypes(graph).UsedFor(pipeline.ARMTarget),
pipeline.InjectOriginalVersionProperty().UsedFor(pipeline.ARMTarget),
Expand Down
7 changes: 3 additions & 4 deletions hack/generator/pkg/codegen/pipeline/create_storage_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func CreateStorageTypes(conversionGraph *storage.ConversionGraph) Stage {
typesToConvert := types.Where(isPropertyContainer).Where(isNotARMType)

storageTypes := make(astmodel.Types)
typeConverter := storage.NewTypeConverter(types)
typeConverter := storage.NewTypeConverter(types, conversionGraph)

// Create storage variants
for name, def := range typesToConvert {
Expand All @@ -50,14 +50,13 @@ func CreateStorageTypes(conversionGraph *storage.ConversionGraph) Stage {
}

storageTypes.Add(storageDef)
conversionGraph.AddLink(name.PackageReference, storageDef.Name().PackageReference)
}

result := types.Copy()
result.AddTypes(storageTypes)
result = result.OverlayWith(storageTypes)
return result, nil
})

result.RequiresPrerequisiteStages(injectOriginalVersionFunctionStageId)
result.RequiresPrerequisiteStages(InjectOriginalVersionFunctionStageId, CreateConversionGraphStageId)
return result
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ func InjectOriginalGVKFunction(idFactory astmodel.IdentifierFactory) Stage {
return result, nil
})

stage.RequiresPrerequisiteStages(injectOriginalVersionFunctionStageId)
stage.RequiresPrerequisiteStages(InjectOriginalVersionFunctionStageId)
return stage
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
"github.com/Azure/azure-service-operator/hack/generator/pkg/functions"
)

// injectOriginalVersionFunctionStageId is the unique identifier for this pipeline stage
const injectOriginalVersionFunctionStageId = "injectOriginalVersionFunction"
// InjectOriginalVersionFunctionStageId is the unique identifier for this pipeline stage
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
Expand All @@ -25,7 +25,7 @@ const injectOriginalVersionFunctionStageId = "injectOriginalVersionFunction"
func InjectOriginalVersionFunction(idFactory astmodel.IdentifierFactory) Stage {

stage := MakeStage(
injectOriginalVersionFunctionStageId,
InjectOriginalVersionFunctionStageId,
"Inject the function OriginalVersion() into each Spec type",
func(ctx context.Context, types astmodel.Types) (astmodel.Types, error) {
injector := storage.NewFunctionInjector()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ func InjectOriginalVersionProperty() Stage {
return result, nil
})

stage.RequiresPrerequisiteStages(injectOriginalVersionFunctionStageId)
stage.RequiresPrerequisiteStages(InjectOriginalVersionFunctionStageId)
return stage
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ import (
"github.com/Azure/azure-service-operator/hack/generator/pkg/functions"
)

// injectPropertyAssignmentFunctionsStageId is the unique identifier for this pipeline stage
const injectPropertyAssignmentFunctionsStageId = "injectPropertyAssignmentFunctions"
// InjectPropertyAssignmentFunctionsStageId is the unique identifier for this pipeline stage
const InjectPropertyAssignmentFunctionsStageId = "injectPropertyAssignmentFunctions"

// InjectPropertyAssignmentFunctions injects property assignment functions AssignTo*() and AssignFrom*() into both
// resources and object types. These functions do the heavy lifting of the conversions between versions of each type and
// are the building blocks of the main CovertTo*() and ConvertFrom*() methods.
func InjectPropertyAssignmentFunctions(graph *storage.ConversionGraph, idFactory astmodel.IdentifierFactory) Stage {

stage := MakeStage(
injectPropertyAssignmentFunctionsStageId,
InjectPropertyAssignmentFunctionsStageId,
"Inject property assignment functions AssignFrom() and AssignTo() into resources and objects",
func(ctx context.Context, types astmodel.Types) (astmodel.Types, error) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
//Storage version of v20200101.Person
type Person struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand All @@ -15,25 +16,23 @@ type Person struct {
}

// +kubebuilder:object:root=true
//Storage version of v20200101.Person
type PersonList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Person `json:"items"`
}

//Storage version of v20200101.Person_Spec
type Person_Spec struct {
//FamilyName: Shared name of the family
FamilyName string `json:"familyName"`

//FullName: As would be used to address mail
FullName string `json:"fullName"`

//KnownAs: How the person is generally known
KnownAs string `json:"knownAs"`
FamilyName *string `json:"familyName,omitempty"`
FullName *string `json:"fullName,omitempty"`
KnownAs *string `json:"knownAs,omitempty"`
}

//Storage version of v20200101.Person_Status
type Person_Status struct {
Status string `json:"status"`
Status *string `json:"status,omitempty"`
}

func init() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,20 @@
// Licensed under the MIT license.
package v20211231

import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
import (
"github.com/Azure/azure-service-operator/testing/microsoft.person/v20211231storage"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

//Storage version of v20211231.Address
type Address struct {
City *string `json:"city,omitempty"`
FullAddress *string `json:"fullAddress,omitempty"`
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
//Storage version of v20211231.Person
type Person struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand All @@ -15,35 +25,25 @@ type Person struct {
}

// +kubebuilder:object:root=true
//Storage version of v20211231.Person
type PersonList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Person `json:"items"`
}

//Storage version of v20211231.Person_Spec
type Person_Spec struct {
//FamilyName: Shared name of the family
FamilyName string `json:"familyName"`

//FullName: As would be used to address mail
FullName string `json:"fullName"`

//KnownAs: How the person is generally known
KnownAs string `json:"knownAs"`
PostalAddress Address `json:"postalAddress"`
ResidentialAddress Address `json:"residentialAddress"`
FamilyName *string `json:"familyName,omitempty"`
FullName *string `json:"fullName,omitempty"`
KnownAs *string `json:"knownAs,omitempty"`
PostalAddress *v20211231storage.Address `json:"postalAddress,omitempty"`
ResidentialAddress *v20211231storage.Address `json:"residentialAddress,omitempty"`
}

//Storage version of v20211231.Person_Status
type Person_Status struct {
Status string `json:"status"`
}

type Address struct {
//City: City or town (or nearest)
City string `json:"city"`

//FullAddress: Full written address for map or postal use
FullAddress string `json:"fullAddress"`
Status *string `json:"status,omitempty"`
}

func init() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,159 +3,36 @@
// Licensed under the MIT license.
package v20200101

import (
"github.com/Azure/azure-service-operator/testing/microsoft.person/v20200101storage"
"github.com/pkg/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
//Storage version of v20200101.Person
type Person struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec Person_Spec `json:"spec,omitempty"`
Status Person_Status `json:"status,omitempty"`
}

// AssignPropertiesFromPerson populates our Person from the provided source Person
func (person *Person) AssignPropertiesFromPerson(source *v20200101storage.Person) error {

// Spec
var spec Person_Spec
err := spec.AssignPropertiesFromPersonSpec(&source.Spec)
if err != nil {
return errors.Wrap(err, "populating Spec from Spec, calling AssignPropertiesFromPersonSpec()")
}
person.Spec = spec

// Status
var status Person_Status
err = status.AssignPropertiesFromPersonStatus(&source.Status)
if err != nil {
return errors.Wrap(err, "populating Status from Status, calling AssignPropertiesFromPersonStatus()")
}
person.Status = status

// No error
return nil
}

// AssignPropertiesToPerson populates the provided destination Person from our Person
func (person *Person) AssignPropertiesToPerson(destination *v20200101storage.Person) error {

// Spec
var spec v20200101storage.Person_Spec
err := person.Spec.AssignPropertiesToPersonSpec(&spec)
if err != nil {
return errors.Wrap(err, "populating Spec from Spec, calling AssignPropertiesToPersonSpec()")
}
destination.Spec = spec

// Status
var status v20200101storage.Person_Status
err = person.Status.AssignPropertiesToPersonStatus(&status)
if err != nil {
return errors.Wrap(err, "populating Status from Status, calling AssignPropertiesToPersonStatus()")
}
destination.Status = status

// No error
return nil
}

// +kubebuilder:object:root=true
//Storage version of v20200101.Person
type PersonList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Person `json:"items"`
}

//Storage version of v20200101.Person_Spec
type Person_Spec struct {
//FamilyName: Shared name of the family
FamilyName string `json:"familyName"`

//FullName: As would be used to address mail
FullName string `json:"fullName"`

//KnownAs: How the person is generally known
KnownAs string `json:"knownAs"`
}

// AssignPropertiesFromPersonSpec populates our Person_Spec from the provided source Person_Spec
func (personSpec *Person_Spec) AssignPropertiesFromPersonSpec(source *v20200101storage.Person_Spec) error {

// FamilyName
if source.FamilyName != nil {
personSpec.FamilyName = *source.FamilyName
} else {
personSpec.FamilyName = ""
}

// FullName
if source.FullName != nil {
personSpec.FullName = *source.FullName
} else {
personSpec.FullName = ""
}

// KnownAs
if source.KnownAs != nil {
personSpec.KnownAs = *source.KnownAs
} else {
personSpec.KnownAs = ""
}

// No error
return nil
}

// AssignPropertiesToPersonSpec populates the provided destination Person_Spec from our Person_Spec
func (personSpec *Person_Spec) AssignPropertiesToPersonSpec(destination *v20200101storage.Person_Spec) error {

// FamilyName
familyName := personSpec.FamilyName
destination.FamilyName = &familyName

// FullName
fullName := personSpec.FullName
destination.FullName = &fullName

// KnownAs
knownA := personSpec.KnownAs
destination.KnownAs = &knownA

// No error
return nil
FamilyName *string `json:"familyName,omitempty"`
FullName *string `json:"fullName,omitempty"`
KnownAs *string `json:"knownAs,omitempty"`
}

//Storage version of v20200101.Person_Status
type Person_Status struct {
Status string `json:"status"`
}

// AssignPropertiesFromPersonStatus populates our Person_Status from the provided source Person_Status
func (personStatus *Person_Status) AssignPropertiesFromPersonStatus(source *v20200101storage.Person_Status) error {

// Status
if source.Status != nil {
personStatus.Status = *source.Status
} else {
personStatus.Status = ""
}

// No error
return nil
}

// AssignPropertiesToPersonStatus populates the provided destination Person_Status from our Person_Status
func (personStatus *Person_Status) AssignPropertiesToPersonStatus(destination *v20200101storage.Person_Status) error {

// Status
status := personStatus.Status
destination.Status = &status

// No error
return nil
Status *string `json:"status,omitempty"`
}

func init() {
Expand Down
Loading

0 comments on commit 4c39ccf

Please sign in to comment.