Documentation
¶
Overview ¶
Package kube provides useful functions to manipulate with kube objects.
Index ¶
- Constants
- Variables
- func AddOwnerReference(dependent, owner client.Object) (changed bool)
- func CheckAllSecretsExistInNamespace(ctx context.Context, cl client.Client, namespace string, names ...string) (exist bool, missingSecrets []string, err error)
- func CopySecret(ctx context.Context, sourceClient client.Client, targetClient client.Client, ...) error
- func CurrentNamespace() string
- func DefaultClientFactory(kubeconfig []byte, scheme *runtime.Scheme) (client.Client, error)
- func DefaultClientFactoryWithRestConfig() (func([]byte, *runtime.Scheme) (client.Client, error), *rest.Config)
- func DeleteAllExceptAndWait[T client.Object](ctx context.Context, c client.Client, obj T, list client.ObjectList, ...) error
- func DeletePVCsAndOwnersAndWait(ctx context.Context, c client.Client, timeout time.Duration, ...) error
- func EnqueueRequestsFromMapFunc(fn MapFunc[client.Object]) handler.EventHandler
- func EnsureDeleteAllOf(ctx context.Context, cl client.Client, gvk schema.GroupVersionKind, ...) (requeue bool, err error)
- func EnsureNamespace(ctx context.Context, cl client.Client, namespace string) error
- func GetChildClient(ctx context.Context, mgmtCl client.Client, ...) (client.Client, error)
- func GetKubeconfigSecretKey(clusterKey client.ObjectKey) client.ObjectKey
- func GetRegionalClient(ctx context.Context, mgmtClient client.Client, systemNamespace string, ...) (client.Client, *rest.Config, error)
- func GetRegionalClientByRegionName(ctx context.Context, mgmtClient client.Client, systemNamespace, region string, ...) (client.Client, error)
- func GetRegionalKubeconfigSecretRef(region *kcmv1.Region) (*fluxmeta.SecretKeyReference, error)
- func RESTMapperCacheSweeper() manager.Runnable
- func SetPredeclaredSecretsCondition(ctx context.Context, cl client.Client, base ObjectConditionGetter, ...) (changed bool, err error)
- func TypedEnqueueRequestsFromMapFunc[O client.Object](fn MapFunc[O]) handler.TypedEventHandler[O, ctrl.Request]
- type DeletionExcludeFn
- type MapFunc
- type ObjectConditionGetter
Constants ¶
const ( DefaultSystemNamespace = "kcm-system" DefaultStateManagementProvider = "ksm-projectsveltos" DefaultStateManagementProviderSelectorKey = "ksm.k0rdent.mirantis.com/adapter" DefaultStateManagementProviderSelectorValue = "kcm-controller-manager" )
const EnableProvidersReloadEnvName = "ENABLE_PROVIDERS_RELOAD"
EnableProvidersReloadEnvName is the name of the env variable enabling provider deployment annotation patch injection.
const ProxySecretEnvName = "PROXY_SECRET"
ProxySecretEnvName is the name of the env variable holding the Secret name with the proxy data.
Variables ¶
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 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 ¶
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 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 ¶
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
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 ¶
DeletionExcludeFn returns true for objects that must be preserved.
type MapFunc ¶ added in v1.11.0
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 ¶
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.