translate

package
v0.16.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2023 License: Apache-2.0 Imports: 25 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"
	// Suffix is the vcluster name, usually set at start time
	Suffix = "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 GetLoadBalancerSVCName added in v0.14.2

func GetLoadBalancerSVCName(serviceName string) string

GetLoadBalancerSVCName retrieves the service name if service name is set to type LoadBalancer. A separate service is created in this case so as to expose only the apiserver and not the kubelet port

func GetOwnerReference added in v0.4.4

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

func KindExistsAndIsClusterScoped added in v0.15.0

func KindExistsAndIsClusterScoped(config *rest.Config, groupVersionKind schema.GroupVersionKind) (bool, bool, error)

KindExistsAndIsClusterScoped checks if given CRDs exist in the given group. Returns foundKinds, notFoundKinds, error

func MergeLabelSelectors added in v0.5.0

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

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 Split

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

func TranslateLabelSelectorWithPrefix added in v0.5.0

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

func UniqueSlice

func UniqueSlice(stringSlice []string) []string

Types

type ApplyMapsOptions added in v0.9.0

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

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

PhysicalNameTranslator 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) 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

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