conversion

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2024 License: Apache-2.0 Imports: 10 Imported by: 9

Documentation

Index

Constants

View Source
const (
	// AllVersions denotes that a Conversion is applicable for all versions
	// of an API with which the Conversion is registered. It can be used for
	// both the conversion source or target API versions.
	AllVersions = "*"
)

Variables

This section is empty.

Functions

func Convert added in v1.4.0

func Convert(params map[string]any, paths []string, mode ListConversionMode) (map[string]any, error)

Convert performs conversion between singleton lists and embedded objects while passing the CRD parameters to the Terraform layer and while reading state from the Terraform layer at runtime. The paths where the conversion will be performed are specified using paths and the conversion mode (whether an embedded object will be converted into a singleton list or a singleton list will be converted into an embedded object) is determined by the mode parameter.

func DefaultPathPrefixes added in v1.4.0

func DefaultPathPrefixes() []string

DefaultPathPrefixes returns the list of the default path prefixes for excluding paths in the identity conversion. The returned value is ["spec.forProvider", "spec.initProvider", "status.atProvider"].

func ExpandParameters added in v1.4.0

func ExpandParameters(prefixes []string, excludePaths ...string) []string

ExpandParameters sorts and expands the given list of field path suffixes with the given prefixes.

Types

type Conversion

type Conversion interface {
	// Applicable should return true if this Conversion is applicable while
	// converting the API of the `src` object to the API of the `dst` object.
	Applicable(src, dst runtime.Object) bool
}

Conversion is the interface for the CRD API version converters. Conversion implementations registered for a source, target pair are called in chain so Conversion implementations can be modular, e.g., a Conversion implementation registered for a specific source and target versions does not have to contain all the needed API conversions between these two versions. All PavedConversions are run in their registration order before the ManagedConversions. Conversions are run in three stages:

  1. PrioritizedManagedConversions are run.
  2. The source and destination objects are paved and the PavedConversions are run in chain without unpaving the unstructured representation between conversions.
  3. The destination paved object is converted back to a managed resource and ManagedConversions are run in the order they are registered.

func NewCustomConverter

func NewCustomConverter(sourceVersion, targetVersion string, converter func(src, target resource.Managed) error) Conversion

NewCustomConverter returns a new Conversion from the specified `sourceVersion` of an API to the specified `targetVersion` and invokes the specified converter function to perform the conversion on the managed resources.

func NewFieldRenameConversion

func NewFieldRenameConversion(sourceVersion, sourceField, targetVersion, targetField string) Conversion

NewFieldRenameConversion returns a new Conversion that implements a field renaming conversion from the specified `sourceVersion` to the specified `targetVersion` of an API. The field's name in the `sourceVersion` is given with the `sourceField` parameter and its name in the `targetVersion` is given with `targetField` parameter.

func NewIdentityConversionExpandPaths added in v1.4.0

func NewIdentityConversionExpandPaths(sourceVersion, targetVersion string, pathPrefixes []string, excludePaths ...string) Conversion

NewIdentityConversionExpandPaths returns a new Conversion from the specified sourceVersion of an API to the specified targetVersion, which copies the identical paths from the source to the target. excludePaths can be used to ignore certain field paths while copying. Exclude paths must be specified in standard crossplane-runtime fieldpath library syntax, i.e., with proper indices for traversing map and slice types (e.g., a.b[*].c). The field paths in excludePaths are sorted in lexical order and are prefixed with each of the path prefixes specified with pathPrefixes. So if an exclude path "x" is specified with the prefix slice ["a", "b"], then paths a.x and b.x will both be skipped while copying fields from a source to a target.

func NewSingletonListConversion added in v1.4.0

func NewSingletonListConversion(sourceVersion, targetVersion string, pathPrefixes []string, crdPaths []string, mode ListConversionMode) Conversion

NewSingletonListConversion returns a new Conversion from the specified sourceVersion of an API to the specified targetVersion and uses the CRD field paths given in crdPaths to convert between the singleton lists and embedded objects in the given conversion mode.

type ListConversionMode added in v1.4.0

type ListConversionMode int

ListConversionMode denotes the mode of the list-object API conversion, e.g., conversion of embedded objects into singleton lists.

const (
	// ToEmbeddedObject represents a runtime conversion from a singleton list
	// to an embedded object, i.e., the runtime conversions needed while
	// reading from the Terraform state and updating the CRD
	// (for status, late-initialization, etc.)
	ToEmbeddedObject ListConversionMode = iota
	// ToSingletonList represents a runtime conversion from an embedded object
	// to a singleton list, i.e., the runtime conversions needed while passing
	// the configuration data to the underlying Terraform layer.
	ToSingletonList
)

func (ListConversionMode) String added in v1.4.0

func (m ListConversionMode) String() string

String returns a string representation of the conversion mode.

type ManagedConversion

type ManagedConversion interface {
	Conversion
	// ConvertManaged converts from the `src` managed resource to the `dst`
	// managed resource and returns `true` if the conversion has been done,
	// `false` otherwise, together with any errors encountered.
	ConvertManaged(src, target resource.Managed) (bool, error)
}

ManagedConversion defines a Conversion from a specific source resource.Managed type to a target one. Generic Conversion implementations may prefer to implement the PavedConversion interface. Implementations of ManagedConversion can do type assertions to specific source and target types, and so, they are expected to be strongly typed.

type PavedConversion

type PavedConversion interface {
	Conversion
	// ConvertPaved converts from the `src` paved object to the `dst`
	// paved object and returns `true` if the conversion has been done,
	// `false` otherwise, together with any errors encountered.
	ConvertPaved(src, target *fieldpath.Paved) (bool, error)
}

PavedConversion is an optimized Conversion between two fieldpath.Paved objects. PavedConversion implementations for a specific source and target version pair are chained together and the source and the destination objects are paved once at the beginning of the chained PavedConversion.ConvertPaved calls. The target fieldpath.Paved object is then converted into the original resource.Terraformed object at the end of the chained calls. This prevents the intermediate conversions between fieldpath.Paved and the resource.Terraformed representations of the same object, and the fieldpath.Paved representation is convenient for writing generic Conversion implementations not bound to a specific type.

type PrioritizedManagedConversion added in v1.4.0

type PrioritizedManagedConversion interface {
	ManagedConversion
	Prioritized()
}

PrioritizedManagedConversion is a ManagedConversion that take precedence over all the other converters. PrioritizedManagedConversions are run, in their registration order, before the PavedConversions.

Jump to

Keyboard shortcuts

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