migration

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2023 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyInto

func CopyInto(source any, target any, targetGVK schema.GroupVersionKind, skipFieldPaths ...string) (any, error)

CopyInto copies values of fields from the migration `source` object into the migration `target` object and fills in the target object's TypeMeta using the supplied `targetGVK`. While copying fields from migration source to migration target, the fields at the paths specified with `skipFieldPaths` array are skipped. This is a utility that can be used in the migration resource converter implementations. If a certain field with the same name in both the `source` and the `target` objects has different types in `source` and `target`, then it must be included in the `skipFieldPaths` and it must manually be handled in the conversion function.

func FromRawExtension

func FromRawExtension(r runtime.RawExtension) (unstructured.Unstructured, error)

FromRawExtension attempts to convert a runtime.RawExtension into an unstructured.Unstructured.

func InitializeDynamicClient

func InitializeDynamicClient(kubeconfigPath string) (dynamic.Interface, error)

InitializeDynamicClient returns a dynamic client

func ToSanitizedUnstructured

func ToSanitizedUnstructured(mg any) unstructured.Unstructured

ToSanitizedUnstructured converts the specified managed resource to an unstructured.Unstructured. Before the converted object is returned, it's sanitized by removing certain fields (like status, metadata.creationTimestamp).

Types

type ApplyStep

type ApplyStep struct {
	// Files denotes the paths of the manifest files to be applied.
	// The paths can either be relative or absolute.
	Files []string `json:"files,omitempty"`
}

ApplyStep represents an apply step in which an array of manifests is applied from the filesystem.

type Category

type Category string

Category specifies if a resource is a Claim, Composite or a Managed resource

const (
	// CategoryClaim category for composite claim resources
	CategoryClaim Category = "Claim"
	// CategoryComposite category for composite resources
	CategoryComposite Category = "Composite"
	// CategoryComposition category for compositions
	CategoryComposition Category = "Composition"
	// CategoryManaged category for managed resources
	CategoryManaged Category = "Managed"
)

Resource categories

type ComposedTemplateConversionFn

type ComposedTemplateConversionFn func(cmp xpv1.ComposedTemplate, convertedBase ...*xpv1.ComposedTemplate) error

ComposedTemplateConversionFn is a function that converts from the specified v1.ComposedTemplate's migration source resources to one or more migration target resources.

type Converter

type Converter interface {
	// Resources takes a managed resource and returns zero or more managed
	// resources to be created.
	Resources(mg resource.Managed) ([]resource.Managed, error)

	// ComposedTemplates takes a ComposedTemplate entry and returns zero or more
	// ComposedTemplate with the new shape, including the necessary changes in
	// its patches. Conversion of the v1.ComposedTemplate.Bases is handled
	// via Converter.Resources and Converter.ComposedTemplates must only
	// convert the other fields (`Patches`, `ConnectionDetails`, etc.)
	ComposedTemplates(cmp v1.ComposedTemplate, convertedBase ...*v1.ComposedTemplate) error
}

Converter converts a managed resource or a Composition's ComposedTemplate from the migration source provider's schema to the migration target provider's schema.

type DeleteOptions

type DeleteOptions struct {
	// FinalizerPolicy denotes the policy to be used regarding
	// the managed reconciler's finalizer
	FinalizerPolicy *FinalizerPolicy `json:"finalizerPolicy,omitempty"`
}

DeleteOptions represent options to be used during deletion of a managed resource.

type DeleteStep

type DeleteStep struct {
	// Options represents the options to be used while deleting the resources
	// specified in Resources.
	Options *DeleteOptions `json:"options,omitempty"`
	// Resources is the array of resources to be deleted in this step
	Resources []Resource `json:"resources,omitempty"`
}

DeleteStep represents a deletion step with options

type FileSystemSource

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

FileSystemSource is a source implementation to read resources from filesystem

func NewFileSystemSource

func NewFileSystemSource(dir string, opts ...FileSystemSourceOption) (*FileSystemSource, error)

NewFileSystemSource returns a FileSystemSource

func (*FileSystemSource) HasNext

func (fs *FileSystemSource) HasNext() (bool, error)

HasNext checks the next item

func (*FileSystemSource) Next

Next returns the next item of slice

type FileSystemSourceOption

type FileSystemSourceOption func(*FileSystemSource)

FileSystemSourceOption allows you to configure FileSystemSource

func FsWithFileSystem

func FsWithFileSystem(f afero.Fs) FileSystemSourceOption

FsWithFileSystem configures the filesystem to use. Used mostly for testing.

type FileSystemTarget

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

FileSystemTarget is a target implementation to write/patch/delete resources to file system

func NewFileSystemTarget

func NewFileSystemTarget(opts ...FileSystemTargetOption) *FileSystemTarget

NewFileSystemTarget returns a FileSystemTarget

func (*FileSystemTarget) Delete

Delete deletes a file from filesystem

func (*FileSystemTarget) Put

Put writes input to filesystem

type FileSystemTargetOption

type FileSystemTargetOption func(*FileSystemTarget)

FileSystemTargetOption allows you to configure FileSystemTarget

func FtWithFileSystem

func FtWithFileSystem(f afero.Fs) FileSystemTargetOption

FtWithFileSystem configures the filesystem to use. Used mostly for testing.

type FinalizerPolicy

type FinalizerPolicy string

FinalizerPolicy denotes the policy regarding the managed reconciler's finalizer while deleting a managed resource.

const (
	// FinalizerPolicyRemove is the FinalizerPolicy for removing
	// the managed reconciler's finalizer from a managed resource.
	FinalizerPolicyRemove FinalizerPolicy = "Remove" // Default
)

type GroupVersionKind

type GroupVersionKind struct {
	// Group is the API group for the resource
	Group string `json:"group"`
	// Version is the API version for the resource
	Version string `json:"version"`
	// Kind is the kind name for the resource
	Kind string `json:"kind"`
}

GroupVersionKind represents the GVK for an object's kind. schema.GroupVersionKind does not contain json the serialization tags for its fields, but we would like to serialize these as part of the migration plan.

func FromGroupVersionKind

func FromGroupVersionKind(gvk schema.GroupVersionKind) GroupVersionKind

FromGroupVersionKind converts a schema.GroupVersionKind into a migration.GroupVersionKind.

type KubernetesSource

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

KubernetesSource is a source implementation to read resources from Kubernetes cluster.

func NewKubernetesSource

func NewKubernetesSource(r *Registry, dynamicClient dynamic.Interface) (*KubernetesSource, error)

NewKubernetesSource returns a KubernetesSource DynamicClient is used here to query resources. Elements of gvks (slice of GroupVersionKind) are passed to the Dynamic Client in a loop to get list of resources. An example element of gvks slice: Group: "ec2.aws.upbound.io", Version: "v1beta1", Kind: "VPC",

func (*KubernetesSource) HasNext

func (ks *KubernetesSource) HasNext() (bool, error)

HasNext checks the next item

func (*KubernetesSource) Next

Next returns the next item of slice

type Metadata

type Metadata struct {
	// Path uniquely identifies the path for this object on its Source
	Path string
	// colon separated list of parent `Path`s for fan-ins and fan-outs
	// Example: resources/a.yaml:resources/b.yaml
	Parents string
	// Category specifies if the associated resource is a Claim, Composite or a
	// Managed resource
	Category Category
}

Metadata holds metadata for an object read from a Source

type Plan

type Plan struct {
	Version string `json:"version"`
	Spec    Spec   `json:"spec,omitempty"`
}

Plan represents a migration plan for migrating managed resources, and associated composites and claims from a migration source provider to a migration target provider.

type PlanGenerator

type PlanGenerator struct {

	// Plan is the migration.Plan whose steps are expected
	// to complete a migration when they're executed in order.
	Plan Plan
	// contains filtered or unexported fields
}

PlanGenerator generates a migration.Plan reading the manifests available from `source`, converting managed resources and compositions using the available `migration.Converter`s registered in the `registry` and writing the output manifests to the specified `target`.

func NewPlanGenerator

func NewPlanGenerator(registry *Registry, source Source, target Target) PlanGenerator

NewPlanGenerator constructs a new PlanGenerator using the specified Source and Target and the default converter Registry.

func (*PlanGenerator) GeneratePlan

func (pg *PlanGenerator) GeneratePlan() error

GeneratePlan generates a migration plan for the manifests available from the configured Source and writing them to the configured Target using the configured converter Registry. The generated Plan is available in the PlanGenerator.Plan variable if the generation is successful (i.e., no errors are reported).

type Registry

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

Registry is a registry of `migration.Converter`s keyed with the associated `schema.GroupVersionKind`s and an associated runtime.Scheme with which the corresponding types are registered.

func NewRegistry

func NewRegistry(scheme *runtime.Scheme) *Registry

NewRegistry returns a new Registry initialized with the specified runtime.Scheme.

func (*Registry) AddClaimType

func (r *Registry) AddClaimType(gvk schema.GroupVersionKind)

AddClaimType registers a new composite resource claim type with the given GVK

func (*Registry) AddCompositeType

func (r *Registry) AddCompositeType(gvk schema.GroupVersionKind)

AddCompositeType registers a new composite resource type with the given GVK

func (*Registry) AddCompositionTypes

func (r *Registry) AddCompositionTypes() error

AddCompositionTypes registers the Composition types with the registry's scheme. Only the v1 API of Compositions is currently supported.

func (*Registry) AddToScheme

func (r *Registry) AddToScheme(sb func(scheme *runtime.Scheme) error) error

AddToScheme registers types with this Registry's runtime.Scheme

func (*Registry) GetAllRegisteredGVKs

func (r *Registry) GetAllRegisteredGVKs() []schema.GroupVersionKind

GetAllRegisteredGVKs returns a list of registered GVKs including v1.CompositionGroupVersionKind

func (*Registry) GetCompositionGVKs

func (r *Registry) GetCompositionGVKs() []schema.GroupVersionKind

func (*Registry) GetManagedResourceGVKs

func (r *Registry) GetManagedResourceGVKs() []schema.GroupVersionKind

GetManagedResourceGVKs returns a list of all registered managed resource GVKs

func (*Registry) RegisterConversionFunctions

func (r *Registry) RegisterConversionFunctions(gvk schema.GroupVersionKind, rFn ResourceConversionFn, cmpFn ComposedTemplateConversionFn)

RegisterConversionFunctions registers the supplied ResourceConversionFn and ComposedTemplateConversionFn for the specified GVK. The specified GVK must belong to a Crossplane managed resource type and the type must already have been registered with the client-go's default scheme.

func (*Registry) RegisterConverter

func (r *Registry) RegisterConverter(gvk schema.GroupVersionKind, conv Converter)

RegisterConverter registers the specified migration.Converter for the specified GVK with the default Registry.

type Resource

type Resource struct {
	// GroupVersionKind holds the GVK for the resource's type
	// schema.GroupVersionKind is not embedded for consistent serialized names
	GroupVersionKind `json:",inline"`
	// Name is the name of the resource
	Name string `json:"name"`
}

type ResourceConversionFn

type ResourceConversionFn func(mg resource.Managed) ([]resource.Managed, error)

ResourceConversionFn is a function that converts the specified migration source managed resource to one or more migration target managed resources.

type Source

type Source interface {
	// HasNext returns `true` if the Source implementation has a next manifest
	// available to return with a call to Next. Any errors encountered while
	// determining whether a next manifest exists will also be reported.
	HasNext() (bool, error)
	// Next returns the next resource manifest available or
	// any errors encountered while reading the next resource manifest.
	Next() (UnstructuredWithMetadata, error)
}

Source is a source for reading resource manifests

type Spec

type Spec struct {
	// Steps are the migration plan's steps that are expected
	// to complete a migration when executed in order.
	Steps []Step `json:"steps,omitempty"`
}

Spec represents the specification of a migration plan

type Step

type Step struct {
	// Name is the name of this Step
	Name string `json:"name"`
	// Type is the type of this Step.
	// Can be one of Apply, Delete, etc.
	Type StepType `json:"type"`
	// Apply contains the information needed to run an StepTypeApply step.
	// Must be set when the Step.Type is StepTypeApply.
	Apply *ApplyStep `json:"apply,omitempty"`
	// Delete contains the information needed to run an StepTypeDelete step.
	// Must be set when the Step.Type is StepTypeDelete.
	Delete *DeleteStep `json:"delete,omitempty"`
}

Step represents a step in the generated migration plan

type StepType

type StepType string

StepType is the type used to name a migration step

const (
	// StepTypeApply denotes an apply step
	StepTypeApply StepType = "Apply"
	// StepTypeDelete denotes a delete step
	StepTypeDelete StepType = "Delete"
)

type Target

type Target interface {
	// Put writes a resource manifest to this Target
	Put(o UnstructuredWithMetadata) error
	// Delete deletes a resource manifest from this Target
	Delete(o UnstructuredWithMetadata) error
}

Target is a target where resource manifests can be manipulated (e.g., added, deleted, patched, etc.)

type UnstructuredWithMetadata

type UnstructuredWithMetadata struct {
	Object   unstructured.Unstructured
	Metadata Metadata
}

UnstructuredWithMetadata represents an unstructured.Unstructured together with the associated Metadata.

Directories

Path Synopsis
mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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