k8s

package
v1.1.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const WatchNamespaceEnvVar = "WATCH_NAMESPACE"

Variables

View Source
var ErrLeaseAlreadyHeld = errors.New("lease held by another holder")

Functions

func AcquireLease added in v1.1.0

func AcquireLease(ctx context.Context, cl client.Client, leaseName, holder, namespace string, checkStale IsHolderStaleFunc) error

AcquireLease attempts to acquire a named lease for the given holder. If isHolderStale is non-nil and the lease is held by a different holder, the callback is invoked to determine whether the current holder is stale. A stale holder is evicted atomically and the lease is granted to the new holder.

func AddAnnotation added in v0.6.0

func AddAnnotation(obj client.Object, key, value string)

func AddLabel

func AddLabel(obj client.Object, key, value string)

func AnnotateObject added in v0.11.0

func AnnotateObject(ctx context.Context, c client.Client, obj client.Object, annotations map[naming.AnnotationKey]string) error

AnnotateObject adds the specified annotations to the object

func ConfigMap

func ConfigMap(cr *apiv1.PerconaServerMySQL, name, filename, data string, component string) *corev1.ConfigMap

func ConfigMapHash added in v1.0.0

func ConfigMapHash(cm *corev1.ConfigMap) (string, error)

func CustomConfigHash added in v0.12.0

func CustomConfigHash(ctx context.Context, cl client.Client, cr *apiv1.PerconaServerMySQL, configurable Configurable, component string) (string, error)

func DeannotateObject added in v0.11.0

func DeannotateObject(ctx context.Context, c client.Client, obj client.Object, annotation naming.AnnotationKey) error

DeannotateObject removes the specified annotation from the object

func DefaultAPINamespace

func DefaultAPINamespace() (string, error)

DefaultAPINamespace returns namespace for direct api access from a pod https://v1-21.docs.kubernetes.io/docs/tasks/run-application/access-api-from-pod/#directly-accessing-the-rest-api

func DeleteSecrets added in v0.9.0

func DeleteSecrets(ctx context.Context, cl client.Client, cr *apiv1.PerconaServerMySQL, secretNames []string) error

func EnsureComponent added in v0.12.0

func EnsureComponent(
	ctx context.Context,
	cl client.Client,
	c Component,
) error

func EnsureObjectWithHash

func EnsureObjectWithHash(
	ctx context.Context,
	cl client.Client,
	owner metav1.Object,
	obj client.Object,
	s *runtime.Scheme,
) error

func EnsureService added in v0.4.0

func EnsureService(
	ctx context.Context,
	cl client.Client,
	cr *apiv1.PerconaServerMySQL,
	svc *corev1.Service,
	s *runtime.Scheme,
	saveOldMeta bool,
) error

func EqualConfigMaps added in v1.0.0

func EqualConfigMaps(cfgs ...*corev1.ConfigMap) bool

func EqualMetadata added in v0.12.0

func EqualMetadata(m ...metav1.ObjectMeta) bool

func ExecProbe added in v0.2.0

func ExecProbe(probe corev1.Probe, cmd []string) *corev1.Probe

func GetCRWithDefaults added in v0.4.0

func GetCRWithDefaults(
	ctx context.Context,
	cl client.Client,
	nn types.NamespacedName,
	serverVersion *platform.ServerVersion,
) (*apiv1.PerconaServerMySQL, error)

func GetImageIDFromPod added in v0.11.0

func GetImageIDFromPod(pod *corev1.Pod, containerName string) (string, error)

func GetLease added in v1.1.0

func GetLease(ctx context.Context, client client.Client, leaseName, namespace string) (*coordinationv1.Lease, error)

func GetOperatorNamespace added in v0.7.0

func GetOperatorNamespace() (string, error)

GetOperatorNamespace returns the namespace of the operator pod

func GetTLSHash added in v0.12.0

func GetTLSHash(ctx context.Context, cl client.Client, cr *apiv1.PerconaServerMySQL) (string, error)

func GetWatchNamespace

func GetWatchNamespace() (string, error)

GetWatchNamespace returns the namespace the operator should be watching for changes

func InitContainer added in v0.3.0

func InitContainer(cr *apiv1.PerconaServerMySQL, component string, image string, initSpec *apiv1.InitContainerSpec,
	pullPolicy corev1.PullPolicy,
	secCtx *corev1.SecurityContext,
	resources corev1.ResourceRequirements,
	extraVolumeMounts []corev1.VolumeMount,
) corev1.Container

func InitImage

InitImage returns the image to be used in init container. It returns component specific init image if it's defined, else it returns top level init image. If there is no init image defined in the CR, it returns the current running operator image.

func IsPodReady

func IsPodReady(pod corev1.Pod) bool

func IsPodWithNameReady added in v0.3.0

func IsPodWithNameReady(ctx context.Context, cl client.Client, nn types.NamespacedName) (bool, error)

func ObjectExists

func ObjectExists(ctx context.Context, cl client.Reader, nn types.NamespacedName, o client.Object) (bool, error)

func ObjectHash

func ObjectHash(obj runtime.Object) (string, error)

func OperatorImage added in v0.2.0

func OperatorImage(ctx context.Context, cl client.Reader) (string, error)

func PVCsByLabels added in v0.4.0

func PVCsByLabels(ctx context.Context, cl client.Reader, l map[string]string, namespace string) ([]corev1.PersistentVolumeClaim, error)

func PodsByLabels

func PodsByLabels(ctx context.Context, cl client.Reader, l map[string]string, namespace string) ([]corev1.Pod, error)

func ReleaseLease added in v1.1.0

func ReleaseLease(ctx context.Context, cl client.Client, leaseName, holder, namespace string) error

ReleaseLease deletes the lease only if it is still held by the given holder. UID and ResourceVersion preconditions prevent accidentally deleting a lease that was re-created by a concurrent acquirer between the Get and Delete.

func RemoveLabel

func RemoveLabel(obj client.Object, key string)

func RolloutRestart

func RolloutRestart(ctx context.Context, cl client.Client, obj runtime.Object, key naming.AnnotationKey, value string) error

RolloutRestart restarts pods owned by object by updating the pod template with passed annotation key-value.

func SecretKeySelector

func SecretKeySelector(name, key string) *corev1.SecretKeySelector

SecretKeySelector is a k8s helper to create SecretKeySelector object

func ServicesByLabels

func ServicesByLabels(ctx context.Context, cl client.Reader, l map[string]string, namespace string) ([]corev1.Service, error)

func UserPassword

func UserPassword(ctx context.Context, cl client.Reader, cr *apiv1.PerconaServerMySQL, username apiv1.SystemUser) (string, error)

Types

type Component added in v0.12.0

type Component interface {
	Name() string
	PerconaServerMySQL() *apiv1.PerconaServerMySQL
	Labels() map[string]string
	MatchLabels() map[string]string
	PodSpec() *apiv1.PodSpec

	Object(ctx context.Context, cl client.Client) (client.Object, error)
}

type ComponentWithInit added in v0.3.0

type ComponentWithInit interface {
	GetInitSpec(cr *apiv1.PerconaServerMySQL) apiv1.InitContainerSpec
}

type Configurable added in v0.12.0

type Configurable interface {
	GetConfigMapName() string
	GetConfigMapKey() string
	GetConfiguration() string
	GetResources() corev1.ResourceRequirements
	ExecuteConfigurationTemplate(configuration string, memory *resource.Quantity) (string, error)
}

type IsHolderStaleFunc added in v1.1.0

type IsHolderStaleFunc func(ctx context.Context, currentHolder string) (bool, error)

IsHolderStaleFunc determines whether the current lease holder is stale and can be evicted. Called with the current holder's identity.

Jump to

Keyboard shortcuts

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