ownerutil

package
v0.30.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2024 License: Apache-2.0 Imports: 15 Imported by: 24

Documentation

Index

Constants

View Source
const (
	OwnerKey          = "olm.owner"
	OwnerNamespaceKey = "olm.owner.namespace"
	OwnerKind         = "olm.owner.kind"
)

Variables

View Source
var (
	NotController          = false
	DontBlockOwnerDeletion = false
)

Functions

func AddNonBlockingOwner

func AddNonBlockingOwner(object metav1.Object, owner Owner)

AddNonBlockingOwner adds a nonblocking owner to the ownerref list.

func AddOwner

func AddOwner(object metav1.Object, owner Owner, blockOwnerDeletion, isController bool)

AddOwner adds an owner to the ownerref list.

func AddOwnerLabels

func AddOwnerLabels(object metav1.Object, owner Owner) error

AddOwnerLabels adds ownerref-like labels to an object by inferring the owner kind

func AddOwnerLabelsForKind

func AddOwnerLabelsForKind(object metav1.Object, owner Owner, kind string)

AddOwnerLabels adds ownerref-like labels to an object, with no inference

func Adoptable

func Adoptable(target Owner, owners []metav1.OwnerReference) bool

Adoptable checks whether a resource with the given set of OwnerReferences is "adoptable" by the target OwnerReference. This function returns true if there exists an element in owners referencing the same kind target does, otherwise it returns false.

func AdoptableLabels

func AdoptableLabels(labels map[string]string, checkName bool, targets ...Owner) bool

AdoptableLabels determines if an OLM managed resource is adoptable by any of the given targets based on its owner labels. The checkName perimeter enables an additional check for name equality with the `olm.owner` label. Generally used for cross-namespace ownership and for Cluster -> Namespace scope.

func CSVOwnerSelector

func CSVOwnerSelector(owner *operatorsv1alpha1.ClusterServiceVersion) labels.Selector

CSVOwnerSelector returns a label selector to find generated objects owned by owner

func EnsureOwner

func EnsureOwner(object metav1.Object, owner Owner) bool

EnsureOwner adds a new owner if needed and returns whether the object already had the owner.

func GetOwnerByKind

func GetOwnerByKind(object metav1.Object, ownerKind string) *metav1.OwnerReference

func GetOwnerByKindLabel

func GetOwnerByKindLabel(object metav1.Object, ownerKind string) (name, namespace string, ok bool)

func GetOwnersByKind

func GetOwnersByKind(object metav1.Object, ownerKind string) []metav1.OwnerReference

GetOwnersByKind returns all OwnerReferences of the given kind listed by the given object

func HasOwnerConflict

func HasOwnerConflict(target Owner, owners []metav1.OwnerReference) bool

HasOwnerConflict checks if the given list of OwnerReferences points to owners other than the target. This function returns true if the list of OwnerReferences is empty or contains elements of the same kind as the target but does not include the target OwnerReference itself. This function returns false if the list contains the target, or has no elements of the same kind as the target.

Note: This is imporant when determining if a Role, RoleBinding, ClusterRole, or ClusterRoleBinding can be used to satisfy permissions of a CSV. If the target CSV is not a member of the RBAC resource's OwnerReferences, then we know the resource can be garbage collected by OLM independently of the target CSV

func InferGroupVersionKind

func InferGroupVersionKind(obj runtime.Object) error

InferGroupVersionKind adds TypeMeta to an owner so that it can be written to an ownerref. TypeMeta is generally only known at serialization time, so we often won't know what GVK an owner has. For the types we know about, we can add the GVK of the apis that we're using the interact with the object.

func IsOwnedBy

func IsOwnedBy(object metav1.Object, owner Owner) bool

func IsOwnedByKind

func IsOwnedByKind(object metav1.Object, ownerKind string) bool

func IsOwnedByKindLabel

func IsOwnedByKindLabel(object metav1.Object, ownerKind string) bool

IsOwnedByKindLabel returns whether or not a label exists on the object pointing to an owner of a particular kind

func IsOwnedByLabel

func IsOwnedByLabel(object metav1.Object, owner Owner) bool

func NonBlockingOwner

func NonBlockingOwner(owner Owner) metav1.OwnerReference

NonBlockingOwner returns an ownerrefence to be added to an ownerref list

func NonBlockingOwnerApplyConfiguration added in v0.28.0

func NonBlockingOwnerApplyConfiguration(owner Owner) *metav1ac.OwnerReferenceApplyConfiguration

NonBlockingOwnerApplyConfiguration returns an ownerrefence to be added to an ownerref list used in an SSA Configuration

func OwnerLabel

func OwnerLabel(owner Owner, kind string) map[string]string

OwnerLabel returns a label added to generated objects for later querying

Types

type Owner

type Owner interface {
	metav1.Object
	runtime.Object
}

Owner is used to build an OwnerReference, and we need type and object metadata

Jump to

Keyboard shortcuts

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