conversion

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: Apache-2.0 Imports: 5 Imported by: 10

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

This section is empty.

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 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.

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.

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.

Jump to

Keyboard shortcuts

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