kube

package
v1.13.0-dev.2 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Overview

Package kube provides useful functions to manipulate with kube objects.

Index

Constants

View Source
const (
	DefaultSystemNamespace         = "kcm-system"
	DefaultStateManagementProvider = "ksm-projectsveltos"

	DefaultStateManagementProviderSelectorKey   = "ksm.k0rdent.mirantis.com/adapter"
	DefaultStateManagementProviderSelectorValue = "kcm-controller-manager"
)
View Source
const EnableProvidersReloadEnvName = "ENABLE_PROVIDERS_RELOAD"

EnableProvidersReloadEnvName is the name of the env variable enabling provider deployment annotation patch injection.

View Source
const ProxySecretEnvName = "PROXY_SECRET"

ProxySecretEnvName is the name of the env variable holding the Secret name with the proxy data.

Variables

View Source
var DefaultBackoff = wait.Backoff{
	Duration: 250 * time.Millisecond,
	Factor:   2.0,
	Jitter:   0.1,
	Steps:    5,
	Cap:      5 * time.Second,
}

DefaultBackoff is the bounded exponential backoff applied to MapFunc retries. It caps the synchronous retry budget so a misbehaving dependency cannot indefinitely block the informer dispatch goroutine.

Functions

func AddOwnerReference

func AddOwnerReference(dependent, owner client.Object) (changed bool)

func CheckAllSecretsExistInNamespace

func CheckAllSecretsExistInNamespace(ctx context.Context, cl client.Client, namespace string, names ...string) (exist bool, missingSecrets []string, err error)

CheckAllSecretsExistInNamespace returns positive if all of the Secrets with the given names exist in the given namespace. Empty names are ignored.

func CopySecret

func CopySecret(
	ctx context.Context,
	sourceClient client.Client,
	targetClient client.Client,
	key client.ObjectKey,
	toNamespace string,
	nameOverride string,
	owner client.Object,
	extraLabels map[string]string,
) error

CopySecret copies a Secret with the given key to the given namespace.

func CurrentNamespace

func CurrentNamespace() string

func DefaultClientFactory

func DefaultClientFactory(kubeconfig []byte, scheme *runtime.Scheme) (client.Client, error)

DefaultClientFactory constructs a sigs.k8s.io/controller-runtime/pkg/client.Client from the given kubeconfig bytes and scheme.

func DefaultClientFactoryWithRestConfig

func DefaultClientFactoryWithRestConfig() (func([]byte, *runtime.Scheme) (client.Client, error), *rest.Config)

DefaultClientFactoryWithRestConfig returns a lazy factory function that builds a sigs.k8s.io/controller-runtime/pkg/client.Client from kubeconfig bytes and a scheme.

The associated k8s.io/client-go/rest.Config is initialized only when the factory is first invoked.

WARN: The returned callback is NOT concurrency safe.

func DeleteAllExceptAndWait

func DeleteAllExceptAndWait[T client.Object](
	ctx context.Context,
	c client.Client,
	obj T,
	list client.ObjectList,
	timeout time.Duration,
	exclude DeletionExcludeFn[T],
	extraOpts ...client.DeleteAllOfOption,
) error

DeleteAllExceptAndWait deletes collection of the given object across all of the namespaces available, and wait for the given timeout to ensure all of the objects have actually been deleted.

func DeletePVCsAndOwnersAndWait added in v1.6.0

func DeletePVCsAndOwnersAndWait(
	ctx context.Context,
	c client.Client,
	timeout time.Duration,
	exclude DeletionExcludeFn[*corev1.PersistentVolumeClaim],
) error

DeletePVCsAndOwnersAndWait deletes PVCs (respecting exclude), removing pod owners when necessary so PVCs can be released. This also removes finalizers from objects (pods/owners) after deleting them. It waits up to timeout for matching PersistentVolumes (not PVCs) to disappear.

func EnqueueRequestsFromMapFunc added in v1.11.0

func EnqueueRequestsFromMapFunc(fn MapFunc[client.Object]) handler.EventHandler

EnqueueRequestsFromMapFunc is a drop-in replacement for sigs.k8s.io/controller-runtime/pkg/handler.EnqueueRequestsFromMapFunc that retries transient errors raised by fn using DefaultBackoff. When the backoff is exhausted, the error is logged at the dispatch context's logger and the event is dropped, matching the prior best-effort semantics.

func EnsureDeleteAllOf

func EnsureDeleteAllOf(ctx context.Context, cl client.Client, gvk schema.GroupVersionKind, opts *client.ListOptions) (requeue bool, err error)

func EnsureNamespace

func EnsureNamespace(ctx context.Context, cl client.Client, namespace string) error

func GetChildClient

func GetChildClient(ctx context.Context, mgmtCl client.Client, kubeconfigSecretRef client.ObjectKey, kubeconfigSecretKey string, scheme *runtime.Scheme, clientFactory func([]byte, *runtime.Scheme) (client.Client, error)) (client.Client, error)

GetChildClient fetches a child cluster's client.

func GetKubeconfigSecretKey

func GetKubeconfigSecretKey(clusterKey client.ObjectKey) client.ObjectKey

GetKubeconfigSecretKey forms an sigs.k8s.io/controller-runtime/pkg/client.ObjectKey for a Secret containing kubeconfig bytes.

func GetRegionalClient

func GetRegionalClient(
	ctx context.Context,
	mgmtClient client.Client,
	systemNamespace string,
	region *kcmv1.Region,
	getSchemeFunc func() (*runtime.Scheme, error),
) (client.Client, *rest.Config, error)

GetRegionalClient returns the sigs.k8s.io/controller-runtime/pkg/client.Client for the given github.com/k0rdent/kcm/api/v1beta1.Region object.

func GetRegionalClientByRegionName

func GetRegionalClientByRegionName(ctx context.Context, mgmtClient client.Client, systemNamespace, region string, getSchemeFunc func() (*runtime.Scheme, error)) (client.Client, error)

GetRegionalClientByRegionName returns the sigs.k8s.io/controller-runtime/pkg/client.Client for the given region name. If region is empty, returns the client of the management cluster.

func GetRegionalKubeconfigSecretRef

func GetRegionalKubeconfigSecretRef(region *kcmv1.Region) (*fluxmeta.SecretKeyReference, error)

GetRegionalKubeconfigSecretRef retrieves the kubeconfig secret reference from the given github.com/k0rdent/kcm/api/v1beta1.Region in github.com/fluxcd/pkg/apis/meta.SecretKeyReference format.

func RESTMapperCacheSweeper added in v1.12.0

func RESTMapperCacheSweeper() manager.Runnable

RESTMapperCacheSweeper returns the runnable that expires idle entries of the shared RESTMapper cache.

func SetPredeclaredSecretsCondition

func SetPredeclaredSecretsCondition(ctx context.Context, cl client.Client, base ObjectConditionGetter, namespace string, names ...string) (changed bool, err error)

SetPredeclaredSecretsCondition checks if all Secret objects with the given names in the given namespace exist. If one of the Secret objects does not exist, creates a new warning Event and returns error. In either case, sets the github.com/K0rdent/kcm/api/v1beta1.PredeclaredSecretsExistCondition condition with corresponding status.

Does nothing if all of the given names are empty.

func TypedEnqueueRequestsFromMapFunc added in v1.11.0

func TypedEnqueueRequestsFromMapFunc[O client.Object](fn MapFunc[O]) handler.TypedEventHandler[O, ctrl.Request]

TypedEnqueueRequestsFromMapFunc is the typed variant of EnqueueRequestsFromMapFunc for use with typed sources (see sigs.k8s.io/controller-runtime/pkg/source.TypedKind).

Types

type DeletionExcludeFn

type DeletionExcludeFn[T client.Object] func(T) bool

DeletionExcludeFn returns true for objects that must be preserved.

type MapFunc added in v1.11.0

type MapFunc[O client.Object] func(context.Context, O) ([]ctrl.Request, error)

MapFunc maps a watch source object to a set of reconcile requests. Unlike the stock sigs.k8s.io/controller-runtime/pkg/handler.MapFunc it may report an error to signal that the mapping itself failed (e.g. a transient API error while listing dependent objects). The wrapping handler retries the call with a bounded exponential backoff instead of silently dropping the event.

Returning (nil, nil) is the canonical way to express "no work to enqueue, not an error" (for example: the source object did not match an indexer or failed a type assertion).

type ObjectConditionGetter

type ObjectConditionGetter interface {
	client.Object
	GetConditions() *[]metav1.Condition
}

ObjectConditionGetter is a common interface over sigs.k8s.io/controller-runtime/pkg/client.Object that can get a reference to a slice of k8s.io/apimachinery/pkg/apis/meta/v1.Condition to manipulate the object directly.

Jump to

Keyboard shortcuts

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