translate

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2024 License: Apache-2.0 Imports: 26 Imported by: 7

Documentation

Index

Constants

View Source
const (
	SkipBackSyncInMultiNamespaceMode = "vcluster.loft.sh/skip-backsync"
)

Variables

View Source
var (
	NamespaceLabel  = "vcluster.loft.sh/namespace"
	MarkerLabel     = "vcluster.loft.sh/managed-by"
	LabelPrefix     = "vcluster.loft.sh/label"
	ControllerLabel = "vcluster.loft.sh/controlled-by"

	// VClusterName is the vcluster name, usually set at start time
	VClusterName = "suffix"

	ManagedAnnotationsAnnotation = "vcluster.loft.sh/managed-annotations"
	ManagedLabelsAnnotation      = "vcluster.loft.sh/managed-labels"
)
View Source
var (
	NamespaceAnnotation = "vcluster.loft.sh/object-namespace"
	NameAnnotation      = "vcluster.loft.sh/object-name"
	UIDAnnotation       = "vcluster.loft.sh/object-uid"
)

Functions

func ApplyMetadata added in v0.9.0

func ApplyMetadata(fromAnnotations map[string]string, toAnnotations map[string]string, fromLabels map[string]string, toLabels map[string]string, excludeAnnotations ...string) (labels map[string]string, annotations map[string]string)

func ConvertKindToResource added in v0.14.0

func ConvertKindToResource(config *rest.Config, groupVersionKind schema.GroupVersionKind) (schema.GroupVersionResource, error)

func ConvertLabelKeyWithPrefix added in v0.5.0

func ConvertLabelKeyWithPrefix(prefix, key string) string

func EnsureCRDFromPhysicalCluster added in v0.14.0

func EnsureCRDFromPhysicalCluster(ctx context.Context, pConfig *rest.Config, vConfig *rest.Config, groupVersionKind schema.GroupVersionKind) (bool, bool, error)

func GetOwnerReference added in v0.4.4

func GetOwnerReference(object client.Object) []metav1.OwnerReference

func KindExists added in v0.14.0

func KindExists(config *rest.Config, groupVersionKind schema.GroupVersionKind) (metav1.APIResource, error)

KindExists returns the api resource for a given CRD. If the kind does not exist, it returns an error.

func LabelSelectorWithPrefix added in v0.16.0

func LabelSelectorWithPrefix(labelPrefix string, labelSelector *metav1.LabelSelector) *metav1.LabelSelector

func MergeLabelSelectors added in v0.5.0

func MergeLabelSelectors(elems ...*metav1.LabelSelector) *metav1.LabelSelector

func PhysicalNamespace added in v0.16.4

func PhysicalNamespace(currentNamespace, vNamespace, prefix, suffix string) string

func ResetObjectMetadata

func ResetObjectMetadata(obj metav1.Object)

ResetObjectMetadata resets the objects metadata except name, namespace and annotations

func SafeConcatName

func SafeConcatName(name ...string) string

func SingleNamespacePhysicalName added in v0.16.4

func SingleNamespacePhysicalName(name, namespace, suffix string) string

func Split

func Split(s, sep string) (string, string)

func UniqueSlice

func UniqueSlice(stringSlice []string) []string

Types

type ApplyMapsOptions added in v0.9.0

type ApplyMapsOptions struct {
	ManagedKeys []string
	ExcludeKeys []string
}

type PhysicalNameFunc added in v0.20.0

type PhysicalNameFunc func(vName, vNamespace string) string

PhysicalNameFunc is a definition to translate a name

type PhysicalNameTranslator added in v0.4.0

type PhysicalNameTranslator func(vName string, vObj client.Object) string

PhysicalNameTranslator transforms a virtual cluster name to a physical name

type PhysicalNamespacedNameTranslator added in v0.14.0

type PhysicalNamespacedNameTranslator func(vNN types.NamespacedName, vObj client.Object) string

PhysicalNamespacedNameTranslator transforms a virtual cluster name to a physical name

type Translator added in v0.4.4

type Translator interface {
	// SingleNamespaceTarget signals if we sync all objects into a single namespace
	SingleNamespaceTarget() bool

	// IsManaged checks if the object is managed by vcluster
	IsManaged(obj runtime.Object, physicalName PhysicalNameFunc) bool

	// IsManagedCluster checks if the cluster scoped object is managed by vcluster
	IsManagedCluster(obj runtime.Object) bool

	// IsTargetedNamespace checks if the provided namespace is a sync target for vcluster
	IsTargetedNamespace(ns string) bool

	// PhysicalNameClusterScoped returns the physical name for a cluster scoped
	// virtual cluster object
	PhysicalNameClusterScoped(vName string) string

	// PhysicalName returns the physical name for a virtual cluster object
	PhysicalName(vName, vNamespace string) string

	// PhysicalNameShort returns the short physical name for a virtual cluster object
	PhysicalNameShort(vName, vNamespace string) string

	// PhysicalNamespace returns the physical namespace for a virtual cluster object
	PhysicalNamespace(vNamespace string) string

	// TranslateLabelsCluster translates the labels of a cluster scoped object
	TranslateLabelsCluster(vObj client.Object, pObj client.Object, syncedLabels []string) map[string]string

	// TranslateLabelSelectorCluster translates a label selector of a cluster scoped object
	TranslateLabelSelectorCluster(labelSelector *metav1.LabelSelector) *metav1.LabelSelector

	// ApplyMetadata translates the metadata including labels and annotations initially from virtual to physical
	ApplyMetadata(vObj client.Object, syncedLabels []string, excludedAnnotations ...string) client.Object

	// ApplyMetadataUpdate updates the physical objects metadata and signals if there were any changes
	ApplyMetadataUpdate(vObj client.Object, pObj client.Object, syncedLabels []string, excludedAnnotations ...string) (bool, map[string]string, map[string]string)

	// ApplyAnnotations applies the annotations from source to target
	ApplyAnnotations(src client.Object, to client.Object, excluded []string) map[string]string

	// ApplyLabels applies the labels from source to target
	ApplyLabels(src client.Object, to client.Object, syncedLabels []string) map[string]string

	// TranslateLabels translates labels
	TranslateLabels(fromLabels map[string]string, vNamespace string, syncedLabels []string) map[string]string

	// TranslateLabelSelector translates a label selector
	TranslateLabelSelector(labelSelector *metav1.LabelSelector) *metav1.LabelSelector

	// SetupMetadataWithName is similar to ApplyMetadata with a custom name translator and doesn't apply annotations and labels
	SetupMetadataWithName(vObj client.Object, translator PhysicalNameTranslator) (client.Object, error)

	// LegacyGetTargetNamespace returns in the case of a single namespace the target namespace, but fails
	// if vcluster is syncing to multiple namespaces.
	LegacyGetTargetNamespace() (string, error)

	ConvertLabelKey(string) string
}
var Default Translator = &singleNamespace{}

func NewMultiNamespaceTranslator added in v0.14.0

func NewMultiNamespaceTranslator(currentNamespace string) Translator

func NewSingleNamespaceTranslator added in v0.14.0

func NewSingleNamespaceTranslator(targetNamespace string) Translator

Jump to

Keyboard shortcuts

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