functions

package
v0.0.0-...-8ad424e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 1, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ReceiverTypePtr    = ReceiverType("ptr")
	ReceiverTypeStruct = ReceiverType("struct")
)
View Source
const (
	ValidationKindCreate = ValidationKind("Create")
	ValidationKindUpdate = ValidationKind("Update")
	ValidationKindDelete = ValidationKind("Delete")
)
View Source
const (
	ReadProperty = OriginalVersionKind("property")
	ReadFunction = OriginalVersionKind("function")
)
View Source
const (
	ExtendedResourcesFunctionName = "GetExtendedResources"
)
View Source
const JSONMarshalFunctionName string = "MarshalJSON"
View Source
const JSONUnmarshalFunctionName string = "UnmarshalJSON"

Variables

View Source
var GetAPIVersionFunctionName = "Get" + astmodel.APIVersionProperty

Functions

func GetConditionsFunction

func GetConditionsFunction(
	k *ResourceFunction,
	codeGenerationContext *astmodel.CodeGenerationContext,
	receiver astmodel.TypeName,
	methodName string,
) (*dst.FuncDecl, error)

GetConditionsFunction returns a function declaration containing the implementation of the GetConditions() function.

func (r *<receiver>) GetConditions() genruntime.Conditions {
    return r.Status.Conditions
}

func NewGetAPIVersionFunction

func NewGetAPIVersionFunction(
	apiVersionTypeName astmodel.TypeName,
	apiVersionEnumValue astmodel.EnumValue,
	idFactory astmodel.IdentifierFactory,
) astmodel.Function

NewGetAPIVersionFunction returns a function that returns a static API Version enum value ('APIVersion_Value')

func NewGetTypeFunction

func NewGetTypeFunction(
	armType string,
	idFactory astmodel.IdentifierFactory,
	receiverType ReceiverType,
) astmodel.Function

NewGetTypeFunction returns a function "GetType" that returns a static string value for the ResourceType of a resource

func NewHubFunction

func NewHubFunction(idFactory astmodel.IdentifierFactory) astmodel.Function

NewHubFunction creates an empty Hub() function that satisfies the Hub interface required by the controller See https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/conversion#Hub

func NewInitializeSpecFunction

func NewInitializeSpecFunction(
	def astmodel.TypeDefinition,
	specInitializeFunction string,
	idFactory astmodel.IdentifierFactory,
) (astmodel.Function, error)

NewInitializeSpecFunction creates a function that initializes a resource's spec from its status. Used as a part of implementing the ImportableResource interface. def is the resource definition that we're generating the function for. specInitializeFunction is the name of the function on the spec that initializes it from the status. idFactory is used to create identifiers for the function.

func NewLocatableResource

func NewLocatableResource(
	idFactory astmodel.IdentifierFactory,
	resourceType *astmodel.ResourceType,
) *astmodel.InterfaceImplementation

func NewNewEmptyARMValueFunc

func NewNewEmptyARMValueFunc(
	armType astmodel.TypeName,
	idFactory astmodel.IdentifierFactory,
) astmodel.Function

NewNewEmptyARMValueFunc returns a function that creates an empty value suitable for using with PopulateFromARM. It should be equivalent to ConvertToARM("") on a default struct value.

func SetConditionsFunction

func SetConditionsFunction(
	k *ResourceFunction,
	codeGenerationContext *astmodel.CodeGenerationContext,
	receiver astmodel.TypeName,
	methodName string,
) (*dst.FuncDecl, error)

SetConditionsFunction returns a function declaration containing the implementation of the SetConditions() function.

func (r *<receiver>) SetConditions(conditions genruntime.Conditions) {
    r.Status.Conditions = conditions
}

Types

type ChainedConversionFunction

type ChainedConversionFunction struct {
	// contains filtered or unexported fields
}

ChainedConversionFunction implements conversions to/from another type that implements a conversion function

We use this for Spec types, implementing genruntime.ConvertibleSpec, and for Status types, implementing genruntime.ConvertibleStatus

Existing PropertyAssignment functions are used to implement stepwise conversion.

For most types, we check to see if the type we're passed is one we can convert directly. If it is, we use the preexisting AssignProperties*() method. Otherwise, we chain to that type to do the conversion to an intermediate instance and then convert using that.

func (r <receiver>) ConvertFrom(instance <interfaceType>) error {
	   source, ok := instance.(*<otherType>)
	   if !ok {
        // Need indirect conversion
        source = &<otherType>{}
        source.ConvertFrom(instance)
    }

    return r.AssignPropertiesFrom(source)
}

func NewSpecChainedConversionFunction

func NewSpecChainedConversionFunction(
	propertyFunction *PropertyAssignmentFunction,
	idFactory astmodel.IdentifierFactory,
) *ChainedConversionFunction

NewSpecChainedConversionFunction creates a chained conversion function that converts between two Spec types implementing the interface genruntime.ConvertibleSpec, using the provided property assignment function as a basis. hubType is the TypeName of our hub type propertyFunction is the function we will call to copy properties across between specs idFactory is an identifier factory to use for generating local identifiers

func NewStatusChainedConversionFunction

func NewStatusChainedConversionFunction(
	propertyFunction *PropertyAssignmentFunction,
	idFactory astmodel.IdentifierFactory,
) *ChainedConversionFunction

NewStatusChainedConversionFunction creates a chained conversion function that converts between two Status types implementing the interface genruntime.ConvertibleStatus, using the provided property assignment function as a basis. hubType is the TypeName of our hub type propertyFunction is the function we will call to copy properties across between specs idFactory is an identifier factory to use for generating local identifiers

func (*ChainedConversionFunction) AsFunc

func (fn *ChainedConversionFunction) AsFunc(
	codeGenerationContext *astmodel.CodeGenerationContext,
	receiver astmodel.InternalTypeName,
) (*dst.FuncDecl, error)

func (*ChainedConversionFunction) Equals

func (*ChainedConversionFunction) Name

func (fn *ChainedConversionFunction) Name() string

func (*ChainedConversionFunction) References

func (*ChainedConversionFunction) RequiredPackageReferences

func (fn *ChainedConversionFunction) RequiredPackageReferences() *astmodel.PackageReferenceSet

type DefaulterBuilder

type DefaulterBuilder struct {
	// contains filtered or unexported fields
}

DefaulterBuilder helps in building an interface implementation for admissions.Defaulter.

func NewDefaulterBuilder

func NewDefaulterBuilder(
	resourceName astmodel.InternalTypeName,
	resource *astmodel.ResourceType,
	idFactory astmodel.IdentifierFactory,
) *DefaulterBuilder

NewDefaulterBuilder creates a new DefaulterBuilder for the given object type.

func (*DefaulterBuilder) AddDefault

func (d *DefaulterBuilder) AddDefault(f *ResourceFunction)

AddDefault adds a default function to the set of default functions to be applied to the given object

func (*DefaulterBuilder) ToInterfaceImplementation

func (d *DefaulterBuilder) ToInterfaceImplementation() *astmodel.InterfaceImplementation

ToInterfaceImplementation creates an InterfaceImplementation that implements the admissions.Defaulter interface. This implementation includes calls to all defaults registered with this DefaulterBuilder via the AddDefault function, as well as helper functions that allow additional handcrafted defaults to be injected by implementing the genruntime.Defaulter interface.

type GetExtendedResourcesFunction

type GetExtendedResourcesFunction struct {
	// contains filtered or unexported fields
}

func NewGetExtendedResourcesFunction

func NewGetExtendedResourcesFunction(
	idFactory astmodel.IdentifierFactory,
	resources []astmodel.InternalTypeName,
) *GetExtendedResourcesFunction

NewGetExtendedResourcesFunction creates a new GetExtendedResources

func (*GetExtendedResourcesFunction) AsFunc

func (ext *GetExtendedResourcesFunction) AsFunc(
	codeGenerationContext *astmodel.CodeGenerationContext,
	receiver astmodel.InternalTypeName,
) (*dst.FuncDecl, error)

AsFunc returns the generated code for the GetExtendedResources() function

func (*GetExtendedResourcesFunction) Equals

Equals returns true if the passed function is equal to us, or false otherwise

func (*GetExtendedResourcesFunction) Name

Name returns the name of this function, which is always GetExtendedResources()

func (*GetExtendedResourcesFunction) References

References shows that GetExtendedResources() references other generated types

func (*GetExtendedResourcesFunction) RequiredPackageReferences

func (ext *GetExtendedResourcesFunction) RequiredPackageReferences() *astmodel.PackageReferenceSet

RequiredPackageReferences returns the set of packages required by GetExtendedResources()

type IndexRegistrationFunction

type IndexRegistrationFunction struct {
	// contains filtered or unexported fields
}

IndexRegistrationFunction is a function for registering an index for a given property chain. The leaf of the property chain is expected to implement the genruntime.Indexer interface

func NewIndexRegistrationFunction

func NewIndexRegistrationFunction(
	idFactory astmodel.IdentifierFactory,
	name string,
	resourceTypeName astmodel.InternalTypeName,
	indexKey string,
	propertyChain []*astmodel.PropertyDefinition,
) *IndexRegistrationFunction

NewIndexRegistrationFunction returns a new index registration function

func (*IndexRegistrationFunction) AsFunc

AsFunc returns the function as a go dst

func (*IndexRegistrationFunction) Equals

Equals determines if this function is equal to the passed in function

func (*IndexRegistrationFunction) IndexKey

func (f *IndexRegistrationFunction) IndexKey() string

IndexKey returns the index key used in the index function

func (*IndexRegistrationFunction) Name

func (*IndexRegistrationFunction) References

References returns the set of types to which this function refers. SHOULD include any types which this function references but its receiver doesn't. SHOULD NOT include the receiver of this function.

func (*IndexRegistrationFunction) RequiredPackageReferences

func (f *IndexRegistrationFunction) RequiredPackageReferences() *astmodel.PackageReferenceSet

RequiredPackageReferences returns a set of references to packages required by this

type KubernetesExporterBuilder

type KubernetesExporterBuilder struct {
	// contains filtered or unexported fields
}

KubernetesExporterBuilder is a builder for creating genruntime.KubernetesExporter interface implementations.

func NewKubernetesExporterBuilder

func NewKubernetesExporterBuilder(
	resourceName astmodel.TypeName,
	resource *astmodel.ResourceType,
	idFactory astmodel.IdentifierFactory,
	mappings map[string][]*astmodel.PropertyDefinition,
) *KubernetesExporterBuilder

NewKubernetesExporterBuilder creates a new KubernetesExporterBuilder for the specified resource

func (*KubernetesExporterBuilder) ToInterfaceImplementation

func (d *KubernetesExporterBuilder) ToInterfaceImplementation() *astmodel.InterfaceImplementation

ToInterfaceImplementation creates an InterfaceImplementation from the KubernetesExporterBuilder

type ObjectFunction

type ObjectFunction struct {
	// contains filtered or unexported fields
}

ObjectFunction is a simple helper that implements the Function interface. It is intended for use for functions that only need information about the object they are operating on

func NewEmptyStatusFunction

func NewEmptyStatusFunction(
	status astmodel.TypeName,
	idFactory astmodel.IdentifierFactory,
) *ObjectFunction

NewEmptyStatusFunction creates a new function to generate NewEmptyStatus() on resource types

func NewGetSpecFunction

func NewGetSpecFunction(idFactory astmodel.IdentifierFactory) *ObjectFunction

NewGetSpecFunction returns a new function to GetSpec() on resource types

func NewGetStatusFunction

func NewGetStatusFunction(idFactory astmodel.IdentifierFactory) *ObjectFunction

NewGetStatusFunction returns a function to generate GetStatus() on resource types

func NewObjectFunction

func NewObjectFunction(
	name string,
	idFactory astmodel.IdentifierFactory,
	asFunc ObjectFunctionHandler,
) *ObjectFunction

NewObjectFunction creates a new object function

func (*ObjectFunction) AddPackageReference

func (fn *ObjectFunction) AddPackageReference(refs ...astmodel.PackageReference)

AddPackageReference adds one or more required package references

func (*ObjectFunction) AddReferencedTypes

func (fn *ObjectFunction) AddReferencedTypes(types ...astmodel.TypeName)

AddReferencedTypes adds one or more types that are required Their packages are automatically included as well.

func (*ObjectFunction) AsFunc

func (fn *ObjectFunction) AsFunc(
	codeGenerationContext *astmodel.CodeGenerationContext,
	receiver astmodel.InternalTypeName,
) (*dst.FuncDecl, error)

AsFunc renders the current instance as a Go abstract syntax tree

func (*ObjectFunction) Equals

Equals checks if this function is equal to the passed in function

func (*ObjectFunction) IdFactory

func (fn *ObjectFunction) IdFactory() astmodel.IdentifierFactory

func (*ObjectFunction) Name

func (fn *ObjectFunction) Name() string

Name returns the unique name of this function (You can't have two functions with the same name on the same object or resource)

func (*ObjectFunction) References

func (fn *ObjectFunction) References() astmodel.TypeNameSet

References returns the set of types to which this function refers. SHOULD include any types which this function references but its receiver doesn't. SHOULD NOT include the receiver of this function.

func (*ObjectFunction) RequiredPackageReferences

func (fn *ObjectFunction) RequiredPackageReferences() *astmodel.PackageReferenceSet

RequiredPackageReferences returns the set of required packages for this function

type ObjectFunctionHandler

type ObjectFunctionHandler func(
	f *ObjectFunction,
	codeGenerationContext *astmodel.CodeGenerationContext,
	receiver astmodel.TypeName,
	methodName string,
) (*dst.FuncDecl, error)

type OneOfJSONMarshalFunction

type OneOfJSONMarshalFunction struct {
	// contains filtered or unexported fields
}

OneOfJSONMarshalFunction is a function for marshalling discriminated unions (types with only mutually exclusive properties) to JSON

func NewOneOfJSONMarshalFunction

func NewOneOfJSONMarshalFunction(oneOfObject *astmodel.ObjectType, idFactory astmodel.IdentifierFactory) *OneOfJSONMarshalFunction

NewOneOfJSONMarshalFunction creates a new OneOfJSONMarshalFunction struct

func (*OneOfJSONMarshalFunction) AsFunc

func (f *OneOfJSONMarshalFunction) AsFunc(
	codeGenerationContext *astmodel.CodeGenerationContext,
	receiver astmodel.InternalTypeName,
) (*dst.FuncDecl, error)

AsFunc returns the function as a go dst

func (*OneOfJSONMarshalFunction) Equals

Equals determines if this function is equal to the passed in function

func (*OneOfJSONMarshalFunction) Name

func (f *OneOfJSONMarshalFunction) Name() string

func (*OneOfJSONMarshalFunction) References

References returns the set of types to which this function refers. SHOULD include any types which this function references but its receiver doesn't. SHOULD NOT include the receiver of this function.

func (*OneOfJSONMarshalFunction) RequiredPackageReferences

func (f *OneOfJSONMarshalFunction) RequiredPackageReferences() *astmodel.PackageReferenceSet

RequiredPackageReferences returns a set of references to packages required by this

type OneOfJSONUnmarshalFunction

type OneOfJSONUnmarshalFunction struct {
	// contains filtered or unexported fields
}

OneOfJSONUnmarshalFunction is a function for unmarshalling discriminated unions (types with only mutually exclusive properties) from JSON

func NewOneOfJSONUnmarshalFunction

func NewOneOfJSONUnmarshalFunction(oneOfObject *astmodel.ObjectType, idFactory astmodel.IdentifierFactory) *OneOfJSONUnmarshalFunction

NewOneOfJSONUnmarshalFunction creates a new OneOfJSONUnmarshalFunction struct

func (*OneOfJSONUnmarshalFunction) AsFunc

func (f *OneOfJSONUnmarshalFunction) AsFunc(
	codeGenerationContext *astmodel.CodeGenerationContext,
	receiver astmodel.InternalTypeName,
) (*dst.FuncDecl, error)

AsFunc returns the function as a go dst

func (*OneOfJSONUnmarshalFunction) Equals

Equals determines if this function is equal to the passed in function

func (*OneOfJSONUnmarshalFunction) Name

func (*OneOfJSONUnmarshalFunction) References

References returns the set of types to which this function refers. SHOULD include any types which this function references but its receiver doesn't. SHOULD NOT include the receiver of this function.

func (*OneOfJSONUnmarshalFunction) RequiredPackageReferences

func (f *OneOfJSONUnmarshalFunction) RequiredPackageReferences() *astmodel.PackageReferenceSet

RequiredPackageReferences returns a set of references to packages required by this

type OriginalGVKFunction

type OriginalGVKFunction struct {
	// contains filtered or unexported fields
}

OriginalGVKFunction implements a function to return the GVK for the type on which it is called We put these on our resource types, giving us a way to obtain the right type of instance when the reconciler is working with ARM. The code differs slightly depending on whether we're injecting into an API or storage variant.

func (resource *SomeResource) OriginalGVK() scheme.GroupVersionKind {
    return scheme.GroupVersionKind{
        Group: GroupVersion.Group,
        Version: resource.Spec.OriginalVersion,
        Kind: "SomeResource",
    }
}

func NewOriginalGVKFunction

func NewOriginalGVKFunction(originalVersion OriginalVersionKind, idFactory astmodel.IdentifierFactory) *OriginalGVKFunction

NewOriginalGVKFunction creates a new OriginalGVKFunction

func (*OriginalGVKFunction) AsFunc

func (o *OriginalGVKFunction) AsFunc(
	codeGenerationContext *astmodel.CodeGenerationContext,
	receiver astmodel.InternalTypeName,
) (*dst.FuncDecl, error)

AsFunc returns the generated code for the OriginalGVK() function

func (*OriginalGVKFunction) Equals

Equals returns true if the passed function is equal to us, or false otherwise

func (*OriginalGVKFunction) Name

func (o *OriginalGVKFunction) Name() string

Name returns the name of this function, which is always OriginalGVK()

func (*OriginalGVKFunction) References

func (o *OriginalGVKFunction) References() astmodel.TypeNameSet

References shows that OriginalGVK() references no other generated types

func (*OriginalGVKFunction) RequiredPackageReferences

func (o *OriginalGVKFunction) RequiredPackageReferences() *astmodel.PackageReferenceSet

RequiredPackageReferences returns the set of packages required by OriginalGVK()

type OriginalVersionFunction

type OriginalVersionFunction struct {
	// contains filtered or unexported fields
}

OriginalVersionFunction implements a function to return the version for the type on which it is called We put these on the *API* versions of our spec types, giving us a way to obtain the right type of instance when the reconciler is working with ARM.

func (spec *SomeSpec) OriginalVersion() string {
    return GroupVersion.Version
}

func NewOriginalVersionFunction

func NewOriginalVersionFunction(idFactory astmodel.IdentifierFactory) *OriginalVersionFunction

NewOriginalVersionFunction creates a new OriginalVersionFunction

func (*OriginalVersionFunction) AsFunc

func (o *OriginalVersionFunction) AsFunc(
	codeGenerationContext *astmodel.CodeGenerationContext,
	receiver astmodel.InternalTypeName,
) (*dst.FuncDecl, error)

AsFunc returns the generated code for the OriginalVersion() function

func (*OriginalVersionFunction) Equals

Equals returns true if the passed function is equal to us, or false otherwise

func (*OriginalVersionFunction) Name

func (o *OriginalVersionFunction) Name() string

Name returns the name of this function, which is always OriginalVersion()

func (*OriginalVersionFunction) References

References shows that OriginalVersion() references no other generated types

func (*OriginalVersionFunction) RequiredPackageReferences

func (o *OriginalVersionFunction) RequiredPackageReferences() *astmodel.PackageReferenceSet

RequiredPackageReferences returns the set of packages required by OriginalVersion()

func (*OriginalVersionFunction) ReturnType

func (o *OriginalVersionFunction) ReturnType() astmodel.Type

ReturnType indicates that this function returns a string

type OriginalVersionKind

type OriginalVersionKind string

type PivotConversionFunction

type PivotConversionFunction struct {
	// contains filtered or unexported fields
}

PivotConversionFunction implements a pivot that's used when a conversion reaches a hub type but hasn't yet found the innermost required conversion needed.

We use this for Spec types, implementing genruntime.ConvertibleSpec, and for Status types, implementing genruntime.ConvertibleStatus.

If the two instances involved in conversion are not in the same "spoke" leading to this "hub" version, we'll pivot to the reverse conversion, starting at the far end of that "spoke":

func (s <hubtype>) ConvertFrom(instance <interfaceType>>) error {
    return instance.ConvertTo(s)
}

The pivot is needed when following the package references from resource version to resource version won't lead us to encounter the other type that's involved in the conversion, as we can see if we're trying to convert between v1 and v2:

##################                  #################                  +---------------+
#       v1       #                  #       v2      #                  |       v3      |
#     Person     #                  #     Person    #                  |     Person    |
##################                  #################                  +---------------+
        |                                   |                                  |
        v                                   v                                  v
+----------------+                  +---------------+                  +---------------+
|    v1storage   |                  |    v2storage  |                  |    v3storage  |
|     Person     |----------------->|     Person    |----------------->|     Person    |
+----------------+                  +---------------+                  +---------------+

Following package references from v1 leads us, in turn, to v1storage, v2storage, and finally v3storage (our hub version), none of is the version we need to terminate the conversion path.

By having a pivot conversion on v3, we can restart the conversion path with v2.

The entire conversion works as follows:

v1.Person.ConvertTo(v2.Person) --> v1storage.Person.ConvertTo(v2.Person)

--> v2storage.Person.ConvertTo(v2.Person)
  --> v3storage.Person.ConvertTo(v2.Person)              // Pivot!
    --> v2.Person.ConvertFrom(v3storage.Person)          // Change of direction
      --> v2storage.Person.ConvertFrom(v3storage.Person)

Note that conversions like this always pivot through the hub version.

func NewSpecPivotConversionFunction

func NewSpecPivotConversionFunction(
	direction conversions.Direction,
	idFactory astmodel.IdentifierFactory,
) *PivotConversionFunction

NewSpecPivotConversionFunction creates a pivot conversion function that works to convert between two Spec types implementing the interface genruntime.ConvertibleSpec. direction is the direction of our conversion idFactory is an identifier factory to use for generating local identifiers

func NewStatusPivotConversionFunction

func NewStatusPivotConversionFunction(
	direction conversions.Direction,
	idFactory astmodel.IdentifierFactory,
) *PivotConversionFunction

NewStatusPivotConversionFunction creates a pivot conversion function that works to convert between two Status types implementing the interface genruntime.ConvertibleStatus. direction is the direction of our conversion idFactory is an identifier factory to use for generating local identifiers

func (*PivotConversionFunction) AsFunc

func (fn *PivotConversionFunction) AsFunc(
	codeGenerationContext *astmodel.CodeGenerationContext,
	receiver astmodel.InternalTypeName,
) (*dst.FuncDecl, error)

func (*PivotConversionFunction) Equals

func (*PivotConversionFunction) Name

func (fn *PivotConversionFunction) Name() string

func (*PivotConversionFunction) References

func (fn *PivotConversionFunction) References() astmodel.TypeNameSet

func (*PivotConversionFunction) RequiredPackageReferences

func (fn *PivotConversionFunction) RequiredPackageReferences() *astmodel.PackageReferenceSet

type PropertyAssignmentFunction

type PropertyAssignmentFunction struct {
	// contains filtered or unexported fields
}

PropertyAssignmentFunction represents a function that assigns all the properties from one resource or object to another. Used to perform a single step of the conversions required to/from the hub version, or to convert from status to spec.

func (*PropertyAssignmentFunction) AsFunc

func (fn *PropertyAssignmentFunction) AsFunc(
	codeGenerationContext *astmodel.CodeGenerationContext,
	receiver astmodel.InternalTypeName,
) (*dst.FuncDecl, error)

AsFunc renders this function as an AST for serialization to a Go source file

func (*PropertyAssignmentFunction) Direction

Direction returns this functions direction of conversion

func (*PropertyAssignmentFunction) Equals

Equals checks to see if the supplied function is the same as this one

func (*PropertyAssignmentFunction) Name

Name returns the name of this function

func (*PropertyAssignmentFunction) ParameterType

func (fn *PropertyAssignmentFunction) ParameterType() astmodel.TypeName

func (*PropertyAssignmentFunction) References

References returns the set of types referenced by this function

func (*PropertyAssignmentFunction) RequiredPackageReferences

func (fn *PropertyAssignmentFunction) RequiredPackageReferences() *astmodel.PackageReferenceSet

RequiredPackageReferences returns the set of package references required by this function

type PropertyAssignmentFunctionBuilder

type PropertyAssignmentFunctionBuilder struct {
	// contains filtered or unexported fields
}

PropertyAssignmentFunctionBuilder is a factory used to construct a PropertyAssignmentFunction.

func NewPropertyAssignmentFunctionBuilder

func NewPropertyAssignmentFunctionBuilder(
	receiver astmodel.TypeDefinition,
	otherDefinition astmodel.TypeDefinition,
	direction conversions.Direction,
) *PropertyAssignmentFunctionBuilder

NewPropertyAssignmentFunctionBuilder creates a new factory for construction of a PropertyAssignmentFunction. receiver is the type definition that will be the receiver for this function otherDefinition is the type definition to convert TO or FROM direction specifies whether we are converting TO or FROM the other definition

func (*PropertyAssignmentFunctionBuilder) AddAssignmentSelector

func (builder *PropertyAssignmentFunctionBuilder) AddAssignmentSelector(selector PropertyAssignmentSelector)

AddAssignmentSelector adds a new assignment selector to the list of assignment selectors. Assignment selectors are executed in the order they are added.

func (*PropertyAssignmentFunctionBuilder) AddSuffixMatchingAssignmentSelector

func (builder *PropertyAssignmentFunctionBuilder) AddSuffixMatchingAssignmentSelector(
	sourceSuffix string,
	destinationSuffix string,
)

AddSuffixMatchingAssignmentSelector adds a new assignment selector that will match a property with the specified sourceSuffix to a property with the specified destinationSuffix.

func (*PropertyAssignmentFunctionBuilder) Build

func (*PropertyAssignmentFunctionBuilder) UseAugmentationInterface

func (builder *PropertyAssignmentFunctionBuilder) UseAugmentationInterface(augmentation astmodel.TypeName)

UseAugmentationInterface returns the property assignment function with a conversion augmentation interface set

type PropertyAssignmentSelector

type PropertyAssignmentSelector func(
	sourceProperties conversions.ReadableConversionEndpointSet,
	destinationProperties conversions.WritableConversionEndpointSet,
	assign func(reader *conversions.ReadableConversionEndpoint, writer *conversions.WritableConversionEndpoint) error,
	conversionContext *conversions.PropertyConversionContext,
) error

PropertyAssignmentSelector is a function that selects pairs of endpoints to create property assignments sourceProperties is the set of readable property endpoints. destinationProperties is the set of writable property endpoints. assign is a callback function used to assign a value from the source to the destination returns an error if there was a problem selecting a property, nil otherwise

type PureFunction

type PureFunction struct {
	// contains filtered or unexported fields
}

StandaloneFunction is a simple helper that implements the Function interface. It is intended for use for pure functions

func NewPureFunction

func NewPureFunction(
	name string,
	idFactory astmodel.IdentifierFactory,
	asFunc PureFunctionHandler,
) *PureFunction

NewPureFunction creates a new pure function

func (*PureFunction) AddPackageReference

func (fn *PureFunction) AddPackageReference(refs ...astmodel.PackageReference)

AddPackageReference adds one or more required package references

func (*PureFunction) AddReferencedTypes

func (fn *PureFunction) AddReferencedTypes(types ...astmodel.TypeName)

AddReferencedTypes adds one or more types that are required Their packages are automatically included as well.

func (*PureFunction) AsFunc

func (fn *PureFunction) AsFunc(
	codeGenerationContext *astmodel.CodeGenerationContext,
	_ astmodel.InternalTypeName,
) (*dst.FuncDecl, error)

AsFunc renders the current instance as a Go abstract syntax tree

func (*PureFunction) Equals

Equals checks if this function is equal to the passed in function

func (*PureFunction) IdFactory

func (fn *PureFunction) IdFactory() astmodel.IdentifierFactory

func (*PureFunction) Name

func (fn *PureFunction) Name() string

Name returns the unique name of this function

func (*PureFunction) References

func (fn *PureFunction) References() astmodel.TypeNameSet

References returns the set of types to which this function refers. SHOULD include any types which this function references but its receiver doesn't. SHOULD NOT include the receiver of this function.

func (*PureFunction) RequiredPackageReferences

func (fn *PureFunction) RequiredPackageReferences() *astmodel.PackageReferenceSet

RequiredPackageReferences returns the set of required packages for this function

type PureFunctionHandler

type PureFunctionHandler func(f *PureFunction, codeGenerationContext *astmodel.CodeGenerationContext, methodName string) *dst.FuncDecl

type ReceiverType

type ReceiverType string

type ResourceConversionFunction

type ResourceConversionFunction struct {
	// contains filtered or unexported fields
}

ResourceConversionFunction implements conversions to/from our hub type Existing PropertyAssignment functions are used to implement stepwise conversion

Direct conversion from the hub type:

func (<receiver> <receiverType>) Convert<From|To>(hub conversion.Hub) error {
	source, ok := hub.(*<hub.Type>)
	if !ok {
		return fmt.Errorf("expected <hub.Type> but received %T instead", hub)
	}
	return <receiver>.AssignProperties<From|To><Type>(source)
}

Indirect conversion, multiple steps via an intermediate instance

func (r <receiver>) Convert<From|To>(hub conversion.Hub) error {
	var source <vNext>
	err := source.Convert<From|To>(hub)
	if err != nil {
		return errors.Wrap(err, "converting from hub to source")
	}

	err = <receiver>.AssignProperties<From|To><Type>(&source)
	if err != nil {
		return errors.Wrap(err, "converting from source to <type>")
	}

	return nil
}

func NewResourceConversionFunction

func NewResourceConversionFunction(
	hub astmodel.InternalTypeName,
	propertyFunction *PropertyAssignmentFunction,
	idFactory astmodel.IdentifierFactory,
) *ResourceConversionFunction

NewResourceConversionFunction creates a conversion function that populates our hub type from the current instance hub is the TypeName of our hub type propertyFunction is the function we use to copy properties across

func (*ResourceConversionFunction) AsFunc

func (fn *ResourceConversionFunction) AsFunc(
	codeGenerationContext *astmodel.CodeGenerationContext,
	receiver astmodel.InternalTypeName,
) (*dst.FuncDecl, error)

func (*ResourceConversionFunction) Direction

Direction returns this functions direction of conversion

func (*ResourceConversionFunction) Equals

func (*ResourceConversionFunction) Hub

Hub returns the hub type we convert with

func (*ResourceConversionFunction) Name

func (*ResourceConversionFunction) References

func (*ResourceConversionFunction) RequiredPackageReferences

func (fn *ResourceConversionFunction) RequiredPackageReferences() *astmodel.PackageReferenceSet

type ResourceFunction

type ResourceFunction struct {
	// contains filtered or unexported fields
}

ResourceFunction is a simple helper that implements the Function interface. It is intended for use for functions that only need information about the resource they are operating on

func NewDefaultAzureNameFunction

func NewDefaultAzureNameFunction(resource *astmodel.ResourceType, idFactory astmodel.IdentifierFactory) *ResourceFunction

func NewResourceFunction

func NewResourceFunction(
	name string,
	resource *astmodel.ResourceType,
	idFactory astmodel.IdentifierFactory,
	asFunc ResourceFunctionHandler,
	requiredPackages *astmodel.PackageReferenceSet,
) *ResourceFunction

NewResourceFunction creates a new resource function

func NewValidateOptionalConfigMapReferenceFunction

func NewValidateOptionalConfigMapReferenceFunction(resource *astmodel.ResourceType, idFactory astmodel.IdentifierFactory) *ResourceFunction

func NewValidateOwnerReferenceFunction

func NewValidateOwnerReferenceFunction(resource *astmodel.ResourceType, idFactory astmodel.IdentifierFactory) *ResourceFunction

func NewValidateResourceReferencesFunction

func NewValidateResourceReferencesFunction(resource *astmodel.ResourceType, idFactory astmodel.IdentifierFactory) *ResourceFunction

func NewValidateWriteOncePropertiesFunction

func NewValidateWriteOncePropertiesFunction(resource *astmodel.ResourceType, idFactory astmodel.IdentifierFactory) *ResourceFunction

func (*ResourceFunction) AsFunc

func (fn *ResourceFunction) AsFunc(
	codeGenerationContext *astmodel.CodeGenerationContext,
	receiver astmodel.InternalTypeName,
) (*dst.FuncDecl, error)

AsFunc renders the current instance as a Go abstract syntax tree

func (*ResourceFunction) Equals

Equals determines if this Function is equal to another one

func (*ResourceFunction) IdFactory

func (*ResourceFunction) Name

func (fn *ResourceFunction) Name() string

Name returns the unique name of this function (You can't have two functions with the same name on the same object or resource)

func (*ResourceFunction) References

func (fn *ResourceFunction) References() astmodel.TypeNameSet

References returns the set of types to which this function refers. SHOULD include any types which this function references but its receiver doesn't. SHOULD NOT include the receiver of this function.

func (*ResourceFunction) RequiredPackageReferences

func (fn *ResourceFunction) RequiredPackageReferences() *astmodel.PackageReferenceSet

RequiredPackageReferences returns the set of required packages for this function

func (*ResourceFunction) Resource

func (fn *ResourceFunction) Resource() *astmodel.ResourceType

Resource returns the resource this function applies to

type ResourceFunctionHandler

type ResourceFunctionHandler func(
	f *ResourceFunction,
	codeGenerationContext *astmodel.CodeGenerationContext,
	receiver astmodel.TypeName,
	methodName string,
) (*dst.FuncDecl, error)

type ResourceStatusSetterFunction

type ResourceStatusSetterFunction struct {
	// contains filtered or unexported fields
}

ResourceStatusSetterFunction is a function that sets the status on a resource

func NewResourceStatusSetterFunction

func NewResourceStatusSetterFunction(
	resource *astmodel.ResourceType,
	idFactory astmodel.IdentifierFactory,
) *ResourceStatusSetterFunction

NewResourceStatusSetterFunction creates a new ResourceStatusSetterFunction resource is the resource type that will host the function idFactory is an IdentifierFactory for creating local variable names

func (ResourceStatusSetterFunction) AsFunc

func (fn ResourceStatusSetterFunction) AsFunc(
	codeGenerationContext *astmodel.CodeGenerationContext,
	receiver astmodel.InternalTypeName,
) (*dst.FuncDecl, error)

AsFunc generates the required function declaration

func (ResourceStatusSetterFunction) Equals

Equals returns true if the passed function is equal

func (ResourceStatusSetterFunction) Name

Name returns the unique name of this function

func (ResourceStatusSetterFunction) References

References returns the set of other types required by this function

func (ResourceStatusSetterFunction) RequiredPackageReferences

func (fn ResourceStatusSetterFunction) RequiredPackageReferences() *astmodel.PackageReferenceSet

RequiredPackageReferences returns the set of package references required by this function

type StoragePropertyConversion

type StoragePropertyConversion func(
	source dst.Expr,
	destination dst.Expr,
	knownLocals *astmodel.KnownLocalsSet,
	generationContext *astmodel.CodeGenerationContext) ([]dst.Stmt, error)

StoragePropertyConversion represents a function that generates the correct AST to convert a single property value Different functions will be used, depending on the types of the properties to be converted. source is an expression that returns the source we are converting from (a Resource or other Object) destination is an expression that returns the destination we are converting to (again, a Resource or other Object) The function returns a sequence of statements to carry out the stated conversion/copy

type ValidationKind

type ValidationKind string

ValidationKind determines when a particular validation should be run

type ValidatorBuilder

type ValidatorBuilder struct {
	// contains filtered or unexported fields
}

ValidatorBuilder helps in building an interface implementation for admissions.Validator.

func NewValidatorBuilder

func NewValidatorBuilder(
	resourceName astmodel.InternalTypeName,
	resource *astmodel.ResourceType,
	idFactory astmodel.IdentifierFactory,
) *ValidatorBuilder

NewValidatorBuilder creates a new ValidatorBuilder for the given object type.

func (*ValidatorBuilder) AddValidation

func (v *ValidatorBuilder) AddValidation(kind ValidationKind, f *ResourceFunction)

AddValidation adds a validation function to the set of validation functions to be applied to the given object.

func (*ValidatorBuilder) ToInterfaceImplementation

func (v *ValidatorBuilder) ToInterfaceImplementation() *astmodel.InterfaceImplementation

ToInterfaceImplementation creates an InterfaceImplementation that implements the admissions.Validator interface. This implementation includes calls to all validations registered with this ValidatorBuilder via the AddValidation function, as well as helper functions that allow additional handcrafted validations to be injected by implementing the genruntime.Validator interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL