controller

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2025 License: Apache-2.0 Imports: 13 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ANNOTATION = &annotationMetadata{}
	LABEL      = &labelMetadata{}
)

Functions

func EnsureAnnotation

func EnsureAnnotation(ctx context.Context, c client.Client, obj client.Object, annKey, annValue string, patch bool, mode ...ModifyMetadataEntryMode) error

EnsureAnnotation ensures that the given annotation has the desired state on the object. If the annotation already exists with the expected value or doesn't exist when deletion is desired, this is a no-op. If the annotation already exists with a different value, a MetadataEntryAlreadyExistsError is returned, unless mode OVERWRITE is set. To remove an annotation, set mode to DELETE. The given annValue does not matter in this case. If patch is set to true, the object will be patched in the cluster immediately, otherwise only the in-memory object is modified. client may be nil when patch is false.

func EnsureLabel

func EnsureLabel(ctx context.Context, c client.Client, obj client.Object, labelKey, labelValue string, patch bool, mode ...ModifyMetadataEntryMode) error

EnsureLabel ensures that the given label has the desired state on the object. If the label already exists with the expected value or doesn't exist when deletion is desired, this is a no-op. If the label already exists with a different value, a MetadataEntryAlreadyExistsError is returned, unless mode OVERWRITE is set. To remove an label, set mode to DELETE. The given labelValue does not matter in this case. If patch is set to true, the object will be patched in the cluster immediately, otherwise only the in-memory object is modified. client may be nil when patch is false.

func GetAnnotation

func GetAnnotation(obj client.Object, key string) (string, bool)

GetAnnotation returns the value of the given annotation key on the object and whether it exists.

func GetLabel

func GetLabel(obj client.Object, key string) (string, bool)

GetLabel returns the value of the given label key on the object and whether it exists.

func GotAnnotationPredicate

func GotAnnotationPredicate(key, val string) predicate.Predicate

GotAnnotationPredicate reacts if the specified annotation was added to the resource. If val is empty, the value of the annotation doesn't matter, just that it was added. Otherwise, true is only returned if the annotation was added (or changed) with the specified value.

func GotLabelPredicate

func GotLabelPredicate(key, val string) predicate.Predicate

GotLabelPredicate reacts if the specified label was added to the resource. If val is empty, the value of the label doesn't matter, just that it was added. Otherwise, true is only returned if the label was added (or changed) with the specified value.

func HasAnnotation

func HasAnnotation(obj client.Object, key string) bool

HasAnnotation returns true if the given annotation key exists on the object.

func HasAnnotationPredicate

func HasAnnotationPredicate(key, val string) predicate.Predicate

HasAnnotationPredicate reacts if the resource has the specified annotation. If val is empty, the value of the annotation doesn't matter, only its existence. Otherwise, true is only returned if the annotation has the specified value. Note that GotAnnotationPredicate can be used to check if a resource just got a specific annotation.

func HasAnnotationWithValue

func HasAnnotationWithValue(obj client.Object, key, value string) bool

HasAnnotationWithValue returns true if the given annotation key exists on the object and has the given value.

func HasLabel

func HasLabel(obj client.Object, key string) bool

HasLabel returns true if the given label key exists on the object.

func HasLabelPredicate

func HasLabelPredicate(key, val string) predicate.Predicate

HasLabelPredicate reacts if the resource has the specified label. If val is empty, the value of the label doesn't matter, only its existence. Otherwise, true is only returned if the label has the specified value. Note that GotLabelPredicate can be used to check if a resource just got a specific label.

func HasLabelWithValue

func HasLabelWithValue(obj client.Object, key, value string) bool

HasLabelWithValue returns true if the given label key exists on the object and has the given value.

func HasOwnerReference

func HasOwnerReference(owned, owner client.Object, scheme *runtime.Scheme) (int, error)

HasOwnerReference returns the index of the owner reference if the 'owned' object has a owner reference pointing to the 'owner' object. If not, -1 is returned. Note that name and uid are only compared if set in the owner object. This means that the function will return a positive index for an owner object with empty name and uid if the owned object contains a owner reference which fits just apiversion and kind. The scheme argument may be nil if the owners GVK is populated.

func IsMetadataEntryAlreadyExistsError

func IsMetadataEntryAlreadyExistsError(err error) bool

func LoadKubeconfig

func LoadKubeconfig(configPath string) (*rest.Config, error)

LoadKubeconfig loads a cluster configuration from the given path. If the path points to a single file, this file is expected to contain a kubeconfig which is then loaded. If the path points to a directory which contains a file named "kubeconfig", that file is used. If the path points to a directory which does not contain a "kubeconfig" file, there must be "host", "token", and "ca.crt" files present, which are used to configure cluster access based on an OIDC trust relationship. If the path is empty, the in-cluster config is returned.

func LostAnnotationPredicate

func LostAnnotationPredicate(key, val string) predicate.Predicate

LostAnnotationPredicate reacts if the specified annotation was removed from the resource. If val is empty, this predicate returns true if the annotation was removed completely, independent of which value it had. Otherwise, true is returned if the annotation had the specified value before and now lost it, either by being removed or by being set to a different value.

func LostLabelPredicate

func LostLabelPredicate(key, val string) predicate.Predicate

LostLabelPredicate reacts if the specified label was removed from the resource. If val is empty, this predicate returns true if the label was removed completely, independent of which value it had. Otherwise, true is returned if the label had the specified value before and now lost it, either by being removed or by being set to a different value.

Types

type DeletionTimestampChangedPredicate

type DeletionTimestampChangedPredicate struct {
	predicate.Funcs
}

DeletionTimestampChangedPredicate reacts to changes of the deletion timestamp.

func (DeletionTimestampChangedPredicate) Update

type MetadataEntryAlreadyExistsError

type MetadataEntryAlreadyExistsError struct {
	MType        metadataEntryType
	Key          string
	DesiredValue string
	ActualValue  string
}

func NewMetadataEntryAlreadyExistsError

func NewMetadataEntryAlreadyExistsError(mType metadataEntryType, key, desired, actual string) *MetadataEntryAlreadyExistsError

func (*MetadataEntryAlreadyExistsError) Error

type ModifyMetadataEntryMode

type ModifyMetadataEntryMode string
const (
	OVERWRITE ModifyMetadataEntryMode = "overwrite"
	DELETE    ModifyMetadataEntryMode = "delete"
)

type StatusChangedPredicate

type StatusChangedPredicate struct {
	predicate.Funcs
}

StatusChangedPredicate returns true if the object's status changed. Getting the status is done via reflection and only works if the corresponding field is named 'Status'. If getting the status fails, this predicate always returns true.

func (StatusChangedPredicate) Update

Jump to

Keyboard shortcuts

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