metadata

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NodeIDLabel = LabelKROPrefix + "node-id"

	// Collection labels for tracking collection membership and position.
	// These enable querying collection resources and understanding their position.
	CollectionIndexLabel = LabelKROPrefix + "collection-index"
	CollectionSizeLabel  = LabelKROPrefix + "collection-size"

	OwnedLabel      = LabelKROPrefix + "owned"
	KROVersionLabel = LabelKROPrefix + "kro-version"

	ManagedByLabelKey = "app.kubernetes.io/managed-by"
	ManagedByKROValue = "kro"

	InstanceIDLabel        = LabelKROPrefix + "instance-id"
	InstanceLabel          = LabelKROPrefix + "instance-name"
	InstanceNamespaceLabel = LabelKROPrefix + "instance-namespace"
	InstanceGroupLabel     = LabelKROPrefix + "instance-group"
	InstanceVersionLabel   = LabelKROPrefix + "instance-version"
	InstanceKindLabel      = LabelKROPrefix + "instance-kind"

	ResourceGraphDefinitionIDLabel        = LabelKROPrefix + "resource-graph-definition-id"
	ResourceGraphDefinitionNameLabel      = LabelKROPrefix + "resource-graph-definition-name"
	ResourceGraphDefinitionNamespaceLabel = LabelKROPrefix + "resource-graph-definition-namespace"
	ResourceGraphDefinitionVersionLabel   = LabelKROPrefix + "resource-graph-definition-version"
	// GraphRevisionHashLabel stores a label-safe representation of the GraphRevision spec hash.
	GraphRevisionHashLabel = LabelKROPrefix + "graph-revision-hash"
)
View Source
const (
	KROInstancesGroupSuffix = v1beta1.KRODomainName
)
View Source
const (
	// LabelKROPrefix is the label key prefix used to identify KRO owned resources.
	LabelKROPrefix = v1beta1.KRODomainName + "/"
)

Variables

View Source
var (
	ErrDuplicatedLabels = errors.New("duplicate labels")
)

Functions

func CompareRGDOwnership

func CompareRGDOwnership(existing, desired metav1.ObjectMeta) (kroOwned, nameMatch, idMatch bool)

CompareRGDOwnership compares RGD ownership labels between two resources. Returns three booleans:

  • kroOwned: whether the existing resource is owned by KRO
  • nameMatch: whether both resources have the same RGD name
  • idMatch: whether both resources have the same RGD ID

This allows callers to distinguish between different ownership scenarios:

  • kroOwned=true, nameMatch=true, idMatch=true: same RGD, normal update
  • kroOwned=true, nameMatch=true, idMatch=false: same RGD name, different ID (adoption)
  • kroOwned=true, nameMatch=false: different RGD (conflict)
  • kroOwned=false: not owned by KRO (conflict)

func ExtractGVKFromUnstructured

func ExtractGVKFromUnstructured(unstructured map[string]interface{}) (schema.GroupVersionKind, error)

ExtractGVKFromUnstructured extracts the GroupVersionKind from an unstructured object. It performs early validation to fail fast and avoid unnecessary API calls: - apiVersion: parsed with schema.ParseGroupVersion for proper validation - kind: validated as DNS-1035 label after lowercasing

func HasGraphRevisionFinalizer added in v0.2.0

func HasGraphRevisionFinalizer(obj metav1.Object) bool

HasGraphRevisionFinalizer checks if the object has the kro finalizer.

func HasInstanceFinalizer

func HasInstanceFinalizer(obj client.Object) bool

HasInstanceFinalizer checks if an unstructured object has an instance-specific finalizer.

func HasResourceGraphDefinitionFinalizer

func HasResourceGraphDefinitionFinalizer(obj metav1.Object) bool

HasResourceGraphDefinitionFinalizer checks if the object has the kro finalizer.

func IsKROOwned

func IsKROOwned(meta metav1.Object) bool

IsKROOwned returns true if the resource is owned by KRO.

func NewInstanceAndResourceGraphDefinitionSelector

func NewInstanceAndResourceGraphDefinitionSelector(instance metav1.Object, resourceGraphDefinition metav1.Object) metav1.LabelSelector

NewInstanceAndResourceGraphDefinitionSelector returns a selector combining instance and RGD labels. Only matches resources that carry both — typically instances themselves, not child resources (which do not carry RGD labels).

func NewInstanceSelector

func NewInstanceSelector(instance metav1.Object) metav1.LabelSelector

func NewNodeAndInstanceAndResourceGraphDefinitionSelector

func NewNodeAndInstanceAndResourceGraphDefinitionSelector(node metav1.Object, instance metav1.Object, resourceGraphDefinition metav1.Object) metav1.LabelSelector

NewNodeAndInstanceAndResourceGraphDefinitionSelector returns a selector combining node, instance, and RGD labels. Only matches resources that carry all three — child resources do not carry RGD labels, so this selector will not match them. Use NewInstanceSelector for child resource lookups.

func NewResourceGraphDefinitionSelector

func NewResourceGraphDefinitionSelector(resourceGraphDefinition metav1.Object) metav1.LabelSelector

NewResourceGraphDefinitionSelector returns a selector matching resources that carry RGD labels (CRDs and instances). Child resources managed by an instance do NOT carry RGD labels; use NewInstanceSelector to find child resources.

func RemoveGraphRevisionFinalizer added in v0.2.0

func RemoveGraphRevisionFinalizer(obj metav1.Object)

RemoveGraphRevisionFinalizer removes the kro finalizer from the object.

func RemoveInstanceFinalizer

func RemoveInstanceFinalizer(obj client.Object)

RemoveInstanceFinalizer removes an instance-specific finalizer from an unstructured object.

func RemoveResourceGraphDefinitionFinalizer

func RemoveResourceGraphDefinitionFinalizer(obj metav1.Object)

RemoveResourceGraphDefinitionFinalizer removes the kro finalizer from the object.

func SetGraphRevisionFinalizer added in v0.2.0

func SetGraphRevisionFinalizer(obj metav1.Object)

SetGraphRevisionFinalizer adds the kro finalizer to the object if it's not already present.

func SetInstanceFinalizer

func SetInstanceFinalizer(obj client.Object)

SetInstanceFinalizer adds an instance-specific finalizer to an unstructured object.

func SetResourceGraphDefinitionFinalizer

func SetResourceGraphDefinitionFinalizer(obj metav1.Object)

SetResourceGraphDefinitionFinalizer adds the kro finalizer to the object if it's not already present.

Types

type GenericLabeler

type GenericLabeler map[string]string

GenericLabeler is a map of labels that can be applied to a resource. It implements the Labeler interface.

func NewCollectionItemLabeler

func NewCollectionItemLabeler(nodeID string, index, size int) GenericLabeler

NewCollectionItemLabeler returns a new labeler that sets collection-specific labels on a resource that is part of a collection (forEach expansion). - node-id: the resource ID from the RGD (e.g "workerPods") - collection-index: the position in the collection (e.g "0", "1", "2") - collection-size: the total number of items in the collection (e.g "3")

func NewGraphRevisionHashLabeler added in v0.2.0

func NewGraphRevisionHashLabeler(specHash string) GenericLabeler

NewGraphRevisionHashLabeler returns a new labeler that sets a label-safe representation of the GraphRevision spec hash on a resource.

func NewInstanceLabeler

func NewInstanceLabeler(instance *unstructured.Unstructured, namespaced bool) GenericLabeler

NewInstanceLabeler returns a new labeler that sets the InstanceLabel and InstanceIDLabel labels on a resource. The InstanceLabel is the namespace and name of the instance that was reconciled to create the resource. It also includes the instance's GVK to allow child resource handlers to filter events by parent instance type.

func NewKROMetaLabeler

func NewKROMetaLabeler() GenericLabeler

NewKROMetaLabeler returns a new labeler that sets the OwnedLabel, and KROVersion labels on a resource.

func NewNodeLabeler added in v0.2.0

func NewNodeLabeler() GenericLabeler

NewNodeLabeler returns a new labeler for child resources Only includes app.kubernetes.io/managed-by label, as other labels come from the parent labeler.

func NewResourceGraphDefinitionLabeler

func NewResourceGraphDefinitionLabeler(rgMeta metav1.Object) GenericLabeler

NewResourceGraphDefinitionLabeler returns a new labeler that sets the ResourceGraphDefinitionLabel and ResourceGraphDefinitionIDLabel labels on a resource.

func (GenericLabeler) ApplyLabels

func (gl GenericLabeler) ApplyLabels(meta metav1.Object)

ApplyLabels applies the labels to the resource.

func (GenericLabeler) Copy

func (gl GenericLabeler) Copy() map[string]string

Copy returns a copy of the labels.

func (GenericLabeler) Labels

func (gl GenericLabeler) Labels() map[string]string

Labels returns the labels.

func (GenericLabeler) Merge

func (gl GenericLabeler) Merge(other Labeler) (Labeler, error)

Merge merges the labels from the other labeler into the current labeler. If there are any duplicate keys, an error is returned.

type Labeler

type Labeler interface {
	Labels() map[string]string
	ApplyLabels(metav1.Object)
	Merge(Labeler) (Labeler, error)
}

Labeler is an interface that defines a set of labels that can be applied to a resource.

Jump to

Keyboard shortcuts

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