k8sutil

package
v0.0.0-...-44f2bf6 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2024 License: Apache-2.0 Imports: 57 Imported by: 13

Documentation

Index

Constants

View Source
const (
	ServerContainerConditionContainersNotReady = "ContainersNotReady"
	ServerContainerConditionPrefix             = "containers with unready status: "
)
View Source
const (
	// LabelKeyArangoDeployment is the key of the label used to store the ArangoDeployment name in
	LabelKeyArangoDeployment = "arango_deployment"
	// LabelKeyArangoLocalStorage is the key of the label used to store the ArangoLocalStorage name in
	LabelKeyArangoLocalStorage = "arango_local_storage"
	// LabelKeyApp is the key of the label used to store the application name in (fixed to AppName)
	LabelKeyApp = "app"
	// LabelKeyRole is the key of the label used to store the role of the resource in
	LabelKeyRole = "role"
	// LabelKeyArangoExporter is the key of the label used to indicate that an exporter is present
	LabelKeyArangoExporter = "arango_exporter"
	// LabelKeyArangoMember is the key of the label used to store the ArangoDeployment member ID in
	LabelKeyArangoMember = "deployment.arangodb.com/member"
	// LabelKeyArangoZone is the key of the label used to store the ArangoDeployment zone ID in
	LabelKeyArangoZone = "deployment.arangodb.com/zone"
	// LabelKeyArangoScheduled is the key of the label used to define that member is already scheduled
	LabelKeyArangoScheduled = "deployment.arangodb.com/scheduled"
	// LabelKeyArangoTopology is the key of the label used to store the ArangoDeployment topology ID in
	LabelKeyArangoTopology = "deployment.arangodb.com/topology"
	// LabelKeyArangoLeader is the key of the label used to store the current leader of a group instances. AF only.
	LabelKeyArangoLeader = "deployment.arangodb.com/leader"
	// LabelKeyArangoActive is the key of the label used to mark members as active.
	LabelKeyArangoActive = "deployment.arangodb.com/active"
	// LabelValueArangoActive is the value of the label used to mark members as active.
	LabelValueArangoActive = "true"
	// LabelKeyArangoMLStatefulSet is the key of the label used to define k8s StatefulSet for ML Extension
	LabelKeyArangoMLStatefulSet = "ml.arangodb.com/statefulset"
	// LabelKeyAnalyticsGAEStatefulSet is the key of the label used to define k8s StatefulSet for Analytics GAE
	LabelKeyAnalyticsGAEStatefulSet = "analytics.arangodb.com/statefulset"
	// AppName is the value for the "app" label
	AppName = "arangodb"
	// AppArangoML is the value for the "app" label
	AppArangoML = "arangoml"
	// AppAnalytics is the value for the "app" label
	AppAnalytics = "analytics"
)
View Source
const (
	LifecycleVolumeMountDir = "/lifecycle/tools"
)

Variables

View Source
var ExtractStorageResourceRequirement = kresources.ExtractStorageResourceRequirement

ExtractStorageResourceRequirement filters resource requirements for Pods. Keep reference for backward compatibility

Functions

func AddOwnerRefToObject

func AddOwnerRefToObject(obj meta.Object, ownerRef *meta.OwnerReference)

AddOwnerRefToObject adds given owner reference to given object

func AppendLifecycleEnv

func AppendLifecycleEnv(in []core.EnvVar) []core.EnvVar

func AppendTLSKeyfileSecretPostfix

func AppendTLSKeyfileSecretPostfix(name string) string

AppendTLSKeyfileSecretPostfix returns the name of the Secret extended with TLS keyfile postfix.

func AppsV1DeploymentGVK

func AppsV1DeploymentGVK() schema.GroupVersionKind

func ArangodInitContainer

func ArangodInitContainer(name, id, engine, executable, operatorImage string, requireUUID bool, securityContext *core.SecurityContext) core.Container

ArangodInitContainer creates a container configured to initialize a UUID file.

func ArangodVersionCheckInitContainer

func ArangodVersionCheckInitContainer(name, executable, operatorImage string, version driver.Version, securityContext *core.SecurityContext) core.Container

ArangodVersionCheckInitContainer creates a container configured to check version.

func ArangodVolumeMount

func ArangodVolumeMount() core.VolumeMount

ArangodVolumeMount creates a volume mount structure for arangod.

func ArangodWaiterInitContainer

func ArangodWaiterInitContainer(name, deploymentName, executable, operatorImage string, isSecured bool, securityContext *core.SecurityContext) core.Container

ArangodWaiterInitContainer creates a container configured to wait for specific ArangoDeployment to be ready

func AreContainersReady

func AreContainersReady(pod *core.Pod, coreContainers utils.StringList) bool

AreContainersReady checks whether Pod is considered as ready. Returns true if the PodReady condition on the given pod is set to true, or all provided containers' names are running and are not in the list of failed containers.

func BatchV1CronJobGVK

func BatchV1CronJobGVK() schema.GroupVersionKind

func BatchV1JobGVK

func BatchV1JobGVK() schema.GroupVersionKind

func BinaryPath

func BinaryPath() string

func ClientAuthCACertificateVolumeMount

func ClientAuthCACertificateVolumeMount() core.VolumeMount

ClientAuthCACertificateVolumeMount creates a volume mount structure for a client-auth CA certificate (ca.crt).

func ClusterJWTVolumeMount

func ClusterJWTVolumeMount() core.VolumeMount

ClusterJWTVolumeMount creates a volume mount structure for a cluster JWT secret (token).

func ContainerStopTime

func ContainerStopTime(container core.ContainerStatus) time.Time

ContainerStopTime returns time of the Container stop. If container is running, time.Zero is returned

func ContainersRecentStopTime

func ContainersRecentStopTime(containers []core.ContainerStatus) time.Time

ContainersRecentStopTime returns most recent termination time of pods

func ConvertImageID2Image

func ConvertImageID2Image(imageID string) string

ConvertImageID2Image converts a ImageID from a ContainerStatus to an Image that can be used in a Container specification.

func CoreV1PodGVK

func CoreV1PodGVK() schema.GroupVersionKind

func CreateAffinity

func CreateAffinity(deploymentName, role string, required bool, affinityWithRole string) *core.Affinity

CreateAffinity creates pod anti-affinity for the given role. role contains the name of the role to configure any-affinity with. affinityWithRole contains the role to configure affinity with.

func CreateAgentLeaderServiceName

func CreateAgentLeaderServiceName(deploymentName string) string

CreateAgentLeaderServiceName returns the name of the service used to access a leader agent.

func CreateBasicAuthSecret

func CreateBasicAuthSecret(ctx context.Context, secrets generic.ModClient[*core.Secret], secretName, username, password string,
	ownerRef *meta.OwnerReference) error

CreateBasicAuthSecret creates a secret with given name in given namespace with a given username and password as value.

func CreateCASecret

func CreateCASecret(ctx context.Context, secrets generic.ModClient[*core.Secret], secretName string, certificate, key string,
	ownerRef *meta.OwnerReference) error

CreateCASecret creates a secret used to store a PEM encoded CA certificate & private key.

func CreateConfigMap

func CreateConfigMap(ctx context.Context, configMaps generic.ModClient[*core.ConfigMap], cm *core.ConfigMap, ownerRef *meta.OwnerReference) error

func CreateDatabaseClientService

func CreateDatabaseClientService(ctx context.Context, svcs generic.ModClient[*core.Service], deployment meta.Object,
	ports []core.ServicePort, selectors map[string]string, owner meta.OwnerReference) (string, bool, error)

CreateDatabaseClientService prepares and creates a service in k8s, used by database clients within the k8s cluster. If the service already exists, nil is returned. If another error occurs, that error is returned. The returned bool is true if the service is created, or false when the service already existed.

func CreateDatabaseClientServiceDNSName

func CreateDatabaseClientServiceDNSName(deployment meta.Object) string

CreateDatabaseClientServiceDNSName returns the DNS of the database client service.

func CreateDatabaseClientServiceDNSNameWithDomain

func CreateDatabaseClientServiceDNSNameWithDomain(deployment meta.Object, domain *string) string

CreateDatabaseClientServiceDNSNameWithDomain returns the DNS of the database client service.

func CreateDatabaseClientServiceName

func CreateDatabaseClientServiceName(deploymentName string) string

CreateDatabaseClientServiceName returns the name of the service used by database clients for the given deployment name.

func CreateDatabaseExternalAccessServiceName

func CreateDatabaseExternalAccessServiceName(deploymentName string) string

CreateDatabaseExternalAccessServiceName returns the name of the service used to access the database from output the kubernetes cluster.

func CreateEncryptionKeySecret

func CreateEncryptionKeySecret(secrets generic.ModClient[*core.Secret], secretName string, key []byte) error

CreateEncryptionKeySecret creates a secret used to store a RocksDB encryption key.

func CreateEnvFieldPath

func CreateEnvFieldPath(name, fieldPath string) core.EnvVar

func CreateEnvSecretKeySelector

func CreateEnvSecretKeySelector(name, SecretKeyName, secretKey string) core.EnvVar

func CreateExporterClientServiceName

func CreateExporterClientServiceName(deploymentName string) string

CreateExporterClientServiceName returns the name of the service used by arangodb-exporter clients for the given deployment name.

func CreateExporterService

func CreateExporterService(ctx context.Context, cachedStatus inspector.Inspector,
	deployment meta.Object, ports []core.ServicePort, selectors map[string]string, owner meta.OwnerReference) (string, bool, error)

CreateExporterService

func CreateExternalAccessService

func CreateExternalAccessService(ctx context.Context, svcs generic.ModClient[*core.Service], svcName string, serviceType core.ServiceType,
	ports []core.ServicePort, selectors map[string]string, loadBalancerIP string,
	loadBalancerSourceRanges []string, owner meta.OwnerReference) (string, bool, error)

CreateExternalAccessService prepares and creates a service in k8s, used to access the database/sync from outside k8s cluster. If the service already exists, nil is returned. If another error occurs, that error is returned. The returned bool is true if the service is created, or false when the service already existed.

func CreateHeadlessService

func CreateHeadlessService(ctx context.Context, svcs generic.ModClient[*core.Service], deployment meta.Object,
	ports []core.ServicePort, selectors map[string]string,
	owner meta.OwnerReference) (string, bool, error)

CreateHeadlessService prepares and creates a headless service in k8s, used to provide a stable DNS name for all pods. If the service already exists, nil is returned. If another error occurs, that error is returned. The returned bool is true if the service is created, or false when the service already existed.

func CreateHeadlessServiceName

func CreateHeadlessServiceName(deploymentName string) string

CreateHeadlessServiceName returns the name of the headless service for the given deployment name.

func CreateJWTFromSecret

func CreateJWTFromSecret(ctx context.Context, cachedSecrets generic.ReadClient[*core.Secret], secrets generic.ModClient[*core.Secret], tokenSecretName, secretSecretName string, claims map[string]interface{}, ownerRef *meta.OwnerReference) error

CreateJWTFromSecret creates a JWT using the secret stored in secretSecretName and stores the result in a new secret called tokenSecretName

func CreatePersistentVolumeClaim

func CreatePersistentVolumeClaim(ctx context.Context, pvcs generic.ModClient[*core.PersistentVolumeClaim], pvcName, deploymentName,
	storageClassName, role string, enforceAntiAffinity bool, resources core.ResourceRequirements,
	vct *core.PersistentVolumeClaim, finalizers []string, owner meta.OwnerReference) error

CreatePersistentVolumeClaim creates a persistent volume claim with given name and configuration. If the pvc already exists, nil is returned. If another error occurs, that error is returned.

func CreatePod

func CreatePod(ctx context.Context, c generic.ModClient[*core.Pod], pod *core.Pod, ns string,
	owner meta.OwnerReference) (string, types.UID, error)

CreatePod adds an owner to the given pod and calls the k8s api-server to created it. If the pod already exists, nil is returned. If another error occurs, that error is returned.

func CreatePodDNSName

func CreatePodDNSName(deployment meta.Object, role, id string) string

CreatePodDNSName returns the DNS of a pod with a given role & id in a given deployment.

func CreatePodDNSNameWithDomain

func CreatePodDNSNameWithDomain(deployment meta.Object, domain *string, role, id string) string

CreatePodDNSName returns the DNS of a pod with a given role & id in a given deployment.

func CreatePodName

func CreatePodName(deploymentName, role, id, suffix string) string

CreatePodName returns the name of the pod for a member with a given id in a deployment with a given name.

func CreatePodSecurityContext

func CreatePodSecurityContext(spec *api.ServerGroupSpecSecurityContext) *core.PodSecurityContext

CreatePodSecurityContext creates pod's security context.

func CreateSecurityContext

func CreateSecurityContext(spec *api.ServerGroupSpecSecurityContext) *core.SecurityContext

CreateSecurityContext returns security context. If secured container's feature is enabled then default values will set on nil fields.

func CreateServiceDNSName

func CreateServiceDNSName(svc *core.Service) string

CreateServiceDNSName returns the DNS of a service.

func CreateServiceDNSNameWithDomain

func CreateServiceDNSNameWithDomain(svc *core.Service, domain *string) string

CreateServiceDNSNameWithDomain returns the DNS of a service extended with domain.

func CreateServiceURL

func CreateServiceURL(svc core.Service, scheme string, portPredicate func(core.ServicePort) bool, nodeFetcher func() ([]*core.Node, error)) (string, error)

CreateServiceURL creates a URL used to reach the given service.

func CreateSyncMasterClientServiceDNSName

func CreateSyncMasterClientServiceDNSName(deployment meta.Object) string

CreateSyncMasterClientServiceDNSName returns the DNS of the syncmaster client service.

func CreateSyncMasterClientServiceDNSNameWithDomain

func CreateSyncMasterClientServiceDNSNameWithDomain(deployment meta.Object, domain *string) string

CreateSyncMasterClientServiceDNSNameWithDomain returns the DNS of the syncmaster client service.

func CreateSyncMasterClientServiceName

func CreateSyncMasterClientServiceName(deploymentName string) string

CreateSyncMasterClientServiceName returns the name of the service used by syncmaster clients for the given deployment name.

func CreateTLSKeyfileSecret

func CreateTLSKeyfileSecret(ctx context.Context, secrets generic.ModClient[*core.Secret], secretName string, keyfile string,
	ownerRef *meta.OwnerReference) (*core.Secret, error)

CreateTLSKeyfileSecret creates a secret used to store a PEM encoded keyfile in the format ArangoDB accepts it for its `--ssl.keyfile` option.

func CreateTLSKeyfileSecretName

func CreateTLSKeyfileSecretName(deploymentName, role, id string) string

CreateTLSKeyfileSecretName returns the name of the Secret that holds the TLS keyfile for a member with a given id in a deployment with a given name.

func CreateTokenSecret

func CreateTokenSecret(ctx context.Context, secrets generic.ModClient[*core.Secret], secretName, token string,
	ownerRef *meta.OwnerReference) error

CreateTokenSecret creates a secret with given name in given namespace with a given token as value.

func CreateVolumeEmptyDir

func CreateVolumeEmptyDir(name string) core.Volume

func CreateVolumeWithConfigMap

func CreateVolumeWithConfigMap(name, configMapName string) core.Volume

func CreateVolumeWithPersitantVolumeClaim

func CreateVolumeWithPersitantVolumeClaim(name, claimName string) core.Volume

func CreateVolumeWithSecret

func CreateVolumeWithSecret(name, secretName string) core.Volume

func DatabaseClientDetails

func DatabaseClientDetails(deploymentName string, role string, withLeader bool) ([]core.ServicePort, map[string]string)

func DeploymentListOpt

func DeploymentListOpt(deploymentName string) meta.ListOptions

DeploymentListOpt creates a ListOptions matching all labels for the given deployment name.

func EnsureFinalizerAbsent

func EnsureFinalizerAbsent(ctx context.Context, pods generic.ModClient[*core.Pod], pod *core.Pod, finalizers ...string) error

func EnsureFinalizerPresent

func EnsureFinalizerPresent(ctx context.Context, pods generic.ModClient[*core.Pod], pod *core.Pod, finalizers ...string) error

func EnsureFinalizers

func EnsureFinalizers(in meta.Object, exists []string, missing []string) bool

func EnvExists

func EnvExists(a []core.EnvVar, name string) bool

func ExporterJWTVolumeMount

func ExporterJWTVolumeMount() core.VolumeMount

func ExporterServiceDetails

func ExporterServiceDetails(deploymentName string) ([]core.ServicePort, map[string]string)

func ExternalAccessDetails

func ExternalAccessDetails(port, nodePort int, deploymentName, role string, withLeader bool) ([]core.ServicePort, map[string]string)

func GetAnyVolumeByName

func GetAnyVolumeByName(volumes []core.Volume, name string) (core.Volume, bool)

GetAnyVolumeByName returns the volume in the given volumes with the given name. Returns false if not found.

func GetAnyVolumeMountByName

func GetAnyVolumeMountByName(volumes []core.VolumeMount, name string) (core.VolumeMount, bool)

GetAnyVolumeMountByName returns the volumemount in the given volumemountss with the given name. Returns false if not found.

func GetArangoDBImageFromContainers

func GetArangoDBImageFromContainers(containers []core.Container, names ...string) (string, bool)

GetArangoDBImageFromContainers returns the ArangoDB specific image from a container specs

func GetArangoDBImageIDFromContainerStatuses

func GetArangoDBImageIDFromContainerStatuses(containers []core.ContainerStatus, names ...string) (string, bool)

GetArangoDBImageIDFromContainerStatuses returns the ArangoDB specific image from a container statuses

func GetArangoDBImageIDFromPod

func GetArangoDBImageIDFromPod(pod *core.Pod, names ...string) (string, error)

GetArangoDBImageIDFromPod returns the ArangoDB specific image from a pod

func GetBasicAuthSecret

func GetBasicAuthSecret(secrets generic.ReadClient[*core.Secret], secretName string) (string, string, error)

GetBasicAuthSecret loads a secret with given name in the given namespace and extracts the `username` & `password` field. If the secret does not exists or one of the fields is missing, an error is returned. Returns: username, password, error

func GetCACertficateSecret

func GetCACertficateSecret(ctx context.Context, secrets generic.ReadClient[*core.Secret], secretName string) (string, error)

GetCACertficateSecret loads a secret with given name in the given namespace and extracts the `ca.crt` field. If the secret does not exists the field is missing, an error is returned. Returns: certificate, error

func GetCAFromSecret

func GetCAFromSecret(s *core.Secret, ownerRef *meta.OwnerReference) (string, string, bool, error)

func GetCASecret

func GetCASecret(ctx context.Context, secrets generic.ReadClient[*core.Secret], secretName string,
	ownerRef *meta.OwnerReference) (string, string, bool, error)

GetCASecret loads a secret with given name in the given namespace and extracts the `ca.crt` & `ca.key` field. If the secret does not exists or one of the fields is missing, an error is returned. Returns: certificate, private-key, isOwnedByDeployment, error

func GetFinalizers

func GetFinalizers(spec api.ServerGroupSpec, group api.ServerGroup) []string

func GetImageDetails

GetImageDetails Returns latest defined Image details

func GetKeyCertFromSecret

func GetKeyCertFromSecret(secret *core.Secret, certName, keyName string) (crypto.Certificates, interface{}, error)

func GetLifecycleEnv

func GetLifecycleEnv() []core.EnvVar

func GetPodByName

func GetPodByName(pods []core.Pod, podName string) (core.Pod, bool)

GetPodByName returns pod if it exists among the pods' list Returns false if not found.

func GetPodOwner

func GetPodOwner(kubecli kubernetes.Interface, pod *core.Pod, ns string) (*apps.ReplicaSet, error)

GetPodOwner returns the ReplicaSet that owns the given Pod. If the Pod has no owner of the owner is not a ReplicaSet, nil is returned.

func GetPodSpecChecksum

func GetPodSpecChecksum(podSpec core.PodSpec) (string, error)

GetPodSpecChecksum return checksum of requested pod spec based on deployment and group spec

func GetReplicaSetOwner

func GetReplicaSetOwner(kubecli kubernetes.Interface, rSet *apps.ReplicaSet, ns string) (*apps.Deployment, error)

GetReplicaSetOwner returns the Deployment that owns the given ReplicaSet. If the ReplicaSet has no owner of the owner is not a Deployment, nil is returned.

func GetSecretAuthCredentials

func GetSecretAuthCredentials(secret *core.Secret) (string, string, error)

GetSecretAuthCredentials returns username and password from the secret

func GetTLSKeyfileFromSecret

func GetTLSKeyfileFromSecret(s *core.Secret) (string, error)

func GetTLSKeyfileSecret

func GetTLSKeyfileSecret(secrets generic.ReadClient[*core.Secret], secretName string) (string, error)

GetTLSKeyfileSecret loads a secret used to store a PEM encoded keyfile in the format ArangoDB accepts it for its `--ssl.keyfile` option. Returns: keyfile (pem encoded), error

func GetTokenFromSecret

func GetTokenFromSecret(s *core.Secret) (string, error)

GetTokenFromSecret loads the token secret from a Secret with given name.

func GetTokenSecret

func GetTokenSecret(ctx context.Context, secrets generic.ReadClient[*core.Secret], secretName string) (string, error)

GetTokenSecret loads the token secret from a Secret with given name.

func HeadlessServiceDetails

func HeadlessServiceDetails(deploymentName string) ([]core.ServicePort, map[string]string)

func InitLifecycleContainer

func InitLifecycleContainer(image, binaryPath string, resources *core.ResourceRequirements, securityContext *core.SecurityContext) (core.Container, error)

InitLifecycleContainer creates an init-container to copy the lifecycle binary to a shared volume.

func IsAnyContainerAlive

func IsAnyContainerAlive(containers []core.ContainerStatus) bool

IsAnyContainerAlive returns true if any of the containers is running

func IsContainerAlive

func IsContainerAlive(container core.ContainerStatus) bool

IsContainerAlive returns true if container is running

func IsContainerRunning

func IsContainerRunning(pod *core.Pod, name string) bool

IsContainerRunning returns true if the container of the pod is still running

func IsContainerStarted

func IsContainerStarted(pod *core.Pod, container string) bool

func IsJSON

func IsJSON(s []byte) bool

func IsPersistentVolumeClaimFileSystemResizePending

func IsPersistentVolumeClaimFileSystemResizePending(pvc *core.PersistentVolumeClaim) bool

IsPersistentVolumeClaimFileSystemResizePending returns true if the pvc has FileSystemResizePending set to true

func IsPersistentVolumeClaimMarkedForDeletion

func IsPersistentVolumeClaimMarkedForDeletion(pvc *core.PersistentVolumeClaim) bool

IsPersistentVolumeClaimMarkedForDeletion returns true if the pvc has been marked for deletion.

func IsPersistentVolumeClaimResizing

func IsPersistentVolumeClaimResizing(pvc *core.PersistentVolumeClaim) bool

IsPersistentVolumeClaimResizing returns true if the pvc has Resizing set to true

func IsPodAlive

func IsPodAlive(pod *core.Pod) bool

IsPodAlive returns true if any of the containers within pod is running

func IsPodFailed

func IsPodFailed(pod *core.Pod, coreContainers utils.StringList) bool

IsPodFailed returns true when one of the core containers is terminated wih a non-zero exit code, or the whole pod has been failed.

func IsPodMarkedForDeletion

func IsPodMarkedForDeletion(pod *core.Pod) bool

IsPodMarkedForDeletion returns true if the pod has been marked for deletion.

func IsPodNotScheduledFor

func IsPodNotScheduledFor(pod *core.Pod, timeout time.Duration) bool

IsPodNotScheduledFor returns true if the pod has not been scheduled for longer than the given duration.

func IsPodReady

func IsPodReady(pod *core.Pod) bool

IsPodReady returns true if the PodReady condition on the given pod is set to true.

func IsPodScheduled

func IsPodScheduled(pod *core.Pod) bool

IsPodScheduled returns true if the pod has been scheduled.

func IsPodServerContainerRunning

func IsPodServerContainerRunning(pod *core.Pod) bool

IsPodServerContainerRunning returns true if the arangodb container of the pod is still running

func IsPodSucceeded

func IsPodSucceeded(pod *core.Pod, coreContainers utils.StringList) bool

IsPodSucceeded returns true when all core containers are terminated wih a zero exit code, or the whole pod has been succeeded.

func IsPodTerminating

func IsPodTerminating(pod *core.Pod) bool

IsPodTerminating returns true if the pod has been marked for deletion.

func IsServiceRotationRequired

func IsServiceRotationRequired(spec api.DeploymentSpec, svc *core.Service) bool

func LabelsForActiveMember

func LabelsForActiveMember(deploymentName, role, id string) map[string]string

LabelsForActiveMember returns a map of labels, given to active members for given deployment name and member id

func LabelsForDeployment

func LabelsForDeployment(deploymentName, role string) map[string]string

LabelsForDeployment returns a map of labels, given to all resources for given deployment name

func LabelsForExporterService

func LabelsForExporterService(deploymentName string) map[string]string

LabelsForExporterService returns a map of labels, used to select the all arangodb-exporter containers

func LabelsForExporterServiceSelector

func LabelsForExporterServiceSelector(deploymentName string) map[string]string

LabelsForExporterServiceSelector returns a map of labels, used to select the all arangodb-exporter containers

func LabelsForLeaderMember

func LabelsForLeaderMember(deploymentName, role, id string) map[string]string

LabelsForLeaderMember returns a map of labels for given deployment name and member id and role and leadership.

func LabelsForLocalStorage

func LabelsForLocalStorage(localStorageName, role string) map[string]string

LabelsForLocalStorage returns a map of labels, given to all resources for given local storage name

func LabelsForMember

func LabelsForMember(deploymentName, role, id string) map[string]string

LabelsForMember returns a map of labels, given to all resources for given deployment name and member id

func LifecycleBinary

func LifecycleBinary() string

func LifecycleVolume

func LifecycleVolume() core.Volume

LifecycleVolume creates a volume mount structure for shared lifecycle emptyDir.

func LifecycleVolumeMount

func LifecycleVolumeMount() core.VolumeMount

LifecycleVolumeMount creates a volume mount structure for shared lifecycle emptyDir.

func LocalStorageListOpt

func LocalStorageListOpt(localStorageName, role string) meta.ListOptions

LocalStorageListOpt creates a ListOptions matching all labels for the given local storage name.

func MasterJWTVolumeMount

func MasterJWTVolumeMount() core.VolumeMount

MasterJWTVolumeMount creates a volume mount structure for a master JWT secret (token).

func NewContainer

func NewContainer(containerCreator interfaces.ContainerCreator) (core.Container, error)

NewContainer creates a container for specified creator

func NewLifecycle

func NewLifecycle(t string) (*core.Lifecycle, error)

NewLifecycle creates a lifecycle structure with preStop handler.

func NewLifecycleFinalizers

func NewLifecycleFinalizers() (*core.Lifecycle, error)

NewLifecycleFinalizers creates a lifecycle structure with preStop handler which wait for finalizers to be removed.

func NewLifecycleFinalizersWithBinary

func NewLifecycleFinalizersWithBinary(exePath string) (*core.Lifecycle, error)

NewLifecycleFinalizersWithBinary creates a lifecycle structure with preStop handler which wait for finalizers to be removed using specific binary path.

func NewLifecyclePort

func NewLifecyclePort() (*core.Lifecycle, error)

NewLifecyclePort creates a lifecycle structure with preStop handler which wait for port to be closed.

func NewLifecycleWithBinary

func NewLifecycleWithBinary(exePath string, t string) (*core.Lifecycle, error)

NewLifecycleWithBinary creates a lifecycle structure with preStop handler using specific binary path.

func NewPod

func NewPod(deploymentName, role, id, podName string, podCreator interfaces.PodCreator) core.PodTemplateSpec

NewPod creates a basic Pod for given settings.

func NewTime

func NewTime(t meta.Time) *meta.Time

func PatchStorageClassIsDefault

func PatchStorageClassIsDefault(cli storagev1.StorageV1Interface, name string, isDefault bool) error

PatchStorageClassIsDefault changes the default flag of the given storage class.

func PodStopTime

func PodStopTime(pod *core.Pod) time.Time

PodStopTime returns time when pod has been stopped

func RemoveFinalizers

func RemoveFinalizers[T meta.Object](ctx context.Context, getter generic.GetInterface[T], p generic.PatchInterface[T], name string, finalizers []string, ignoreNotFound bool) (int, error)

RemoveFinalizers is a helper used to remove finalizers from an object. The functions tries to get the object using the provided get function, then remove the given finalizers and update the update using the given update function. In case of an update conflict, the functions tries again.

func RemoveOwnerRefToObjectIfNeeded

func RemoveOwnerRefToObjectIfNeeded(obj meta.Object, ownerRef *meta.OwnerReference) bool

RemoveOwnerRefToObjectIfNeeded removes given owner reference to given object if it exists

func RemoveSelectedFinalizers

func RemoveSelectedFinalizers[T meta.Object](ctx context.Context, getter generic.GetInterface[T], patcher generic.PatchInterface[T], p T,
	finalizers []string, ignoreNotFound bool) (int, error)

RemoveSelectedFinalizers removes the given finalizers from the given pod.

func RenderTLSKeyfileSecret

func RenderTLSKeyfileSecret(secretName string, keyfile string, ownerRef *meta.OwnerReference) *core.Secret

RenderTLSKeyfileSecret renders a secret used to store a PEM encoded keyfile in the format ArangoDB accepts it for its `--ssl.keyfile` option.

func RocksdbEncryptionReadOnlyVolumeMount

func RocksdbEncryptionReadOnlyVolumeMount() core.VolumeMount

RocksdbEncryptionReadOnlyVolumeMount creates a volume mount structure for a RocksDB encryption key.

func RocksdbEncryptionVolumeMount

func RocksdbEncryptionVolumeMount() core.VolumeMount

RocksdbEncryptionVolumeMount creates a volume mount structure for a RocksDB encryption key.

func SetBinaryPath

func SetBinaryPath(path string)

func SetFinalizers

func SetFinalizers(ctx context.Context, pods generic.ModClient[*core.Pod], pod *core.Pod, finalizers ...string) error

func StorageClassIsDefault

func StorageClassIsDefault(sc *storage.StorageClass) bool

StorageClassIsDefault returns true if the given storage class is marked default, false otherwise.

func TlsKeyfileVolumeMount

func TlsKeyfileVolumeMount() core.VolumeMount

TlsKeyfileVolumeMount creates a volume mount structure for a TLS keyfile.

func UpdateJWTFromSecret

func UpdateJWTFromSecret(ctx context.Context, cachedSecrets generic.ReadClient[*core.Secret], secrets generic.ModClient[*core.Secret], tokenSecretName, secretSecretName string, claims map[string]interface{}) error

UpdateJWTFromSecret updates a JWT using the secret stored in secretSecretName and stores the result in a new secret called tokenSecretName

func UpdateOwnerRefToObjectIfNeeded

func UpdateOwnerRefToObjectIfNeeded(obj meta.Object, ownerRef *meta.OwnerReference) bool

UpdateOwnerRefToObjectIfNeeded add given owner reference to given object if it does not exist yet

func UpdateTokenSecret

func UpdateTokenSecret(ctx context.Context, secrets generic.ModClient[*core.Secret], secret *core.Secret, token string) error

UpdateTokenSecret updates a secret with given name in given namespace with a given token as value.

func ValidateCACertificateSecret

func ValidateCACertificateSecret(ctx context.Context, secrets generic.ReadClient[*core.Secret], secretName string) error

ValidateCACertificateSecret checks that a secret with given name in given namespace exists and it contains a 'ca.crt' data field.

func ValidateEncryptionKeyFromSecret

func ValidateEncryptionKeyFromSecret(s *core.Secret) error

func ValidateEncryptionKeySecret

func ValidateEncryptionKeySecret(secrets generic.InspectorInterface[*core.Secret], secretName string) error

ValidateEncryptionKeySecret checks that a secret with given name in given namespace exists and it contains a 'key' data field of exactly 32 bytes.

func ValidateTokenFromSecret

func ValidateTokenFromSecret(s *core.Secret) error

func ValidateTokenSecret

func ValidateTokenSecret(ctx context.Context, secrets generic.ReadClient[*core.Secret], secretName string) error

ValidateTokenSecret checks that a secret with given name in given namespace exists and it contains a 'token' data field.

func VolumeMountExists

func VolumeMountExists(vm []core.VolumeMount, name string) bool

func WaitForInformers

func WaitForInformers(stop <-chan struct{}, timeout time.Duration, informers ...Informer)

Types

type APIObject

type APIObject interface {
	runtime.Object

	K8SObject

	OwnerOf(in meta.Object) bool
}

APIObject helps to abstract an object from our custom API.

type DeepCopy

type DeepCopy[T interface{}] interface {
	DeepCopy() DeepCopy[T]
}

type Event

type Event struct {
	InvolvedObject runtime.Object
	Type           string
	Reason         string
	Message        string
}

Event is used to create events using an EventRecorder.

func NewAccessPackageCreatedEvent

func NewAccessPackageCreatedEvent(apiObject APIObject, apSecretName string) *Event

NewAccessPackageCreatedEvent creates an event indicating that a secret containing an access package has been created.

func NewAccessPackageDeletedEvent

func NewAccessPackageDeletedEvent(apiObject APIObject, apSecretName string) *Event

NewAccessPackageDeletedEvent creates an event indicating that a secret containing an access package has been deleted.

func NewCannotChangeStorageClassEvent

func NewCannotChangeStorageClassEvent(apiObject APIObject, memberID, role, subReason string) *Event

NewCannotChangeStorageClassEvent creates an event indicating that an item would need to use a different StorageClass, but this is not possible for the given reason.

func NewCannotSetArchitectureEvent

func NewCannotSetArchitectureEvent(apiObject runtime.Object, arch, memberId string) *Event

NewCannotSetArchitectureEvent creates an even of type CannotSetArchitectureEvent.

func NewCannotShrinkVolumeEvent

func NewCannotShrinkVolumeEvent(apiObject APIObject, pvcname string) *Event

NewCannotShrinkVolumeEvent creates an event indicating that the user tried to shrink a PVC

func NewDowntimeNotAllowedEvent

func NewDowntimeNotAllowedEvent(apiObject APIObject, operation string) *Event

NewDowntimeNotAllowedEvent creates an event indicating that an operation cannot be executed because downtime is currently not allowed.

func NewErrorEvent

func NewErrorEvent(reason string, err error, apiObject APIObject) *Event

NewErrorEvent creates an even of type error.

func NewImmutableFieldEvent

func NewImmutableFieldEvent(fieldName string, apiObject APIObject) *Event

NewImmutableFieldEvent creates an event indicating that an attempt was made to change a field that is immutable.

func NewMemberAddEvent

func NewMemberAddEvent(memberName, role string, apiObject APIObject) *Event

NewMemberAddEvent creates an event indicating that a member was added.

func NewMemberRemoveEvent

func NewMemberRemoveEvent(memberName, role string, apiObject APIObject) *Event

NewMemberRemoveEvent creates an event indicating that an existing member was removed.

func NewOperatorEngineOpsAlertEvent

func NewOperatorEngineOpsAlertEvent(reason string, apiObject APIObject) *Event

NewOperatorEngineOpsAlertEvent creates an even of type OperatorEngineOpsAlert.

func NewPVCResizedEvent

func NewPVCResizedEvent(apiObject APIObject, pvcname string) *Event

NewPVCResizedEvent creates an event indicating that a PVC has been resized

func NewPlanAbortedEvent

func NewPlanAbortedEvent(apiObject APIObject, itemType, memberID, role string) *Event

NewPlanAbortedEvent creates an event indicating that an item on a reconciliation plan wants to abort the entire plan.

func NewPlanAppendEvent

func NewPlanAppendEvent(apiObject APIObject, itemType, memberID, role, reason string) *Event

NewPlanAppendEvent creates an event indicating that an item on a reconciliation plan has been added

func NewPlanTimeoutEvent

func NewPlanTimeoutEvent(apiObject APIObject, itemType, memberID, role string) *Event

NewPlanTimeoutEvent creates an event indicating that an item on a reconciliation plan did not finish before its deadline.

func NewPodCreatedEvent

func NewPodCreatedEvent(podName, role string, apiObject APIObject) *Event

NewPodCreatedEvent creates an event indicating that a pod has been created

func NewPodGoneEvent

func NewPodGoneEvent(podName, role string, apiObject APIObject) *Event

NewPodGoneEvent creates an event indicating that a pod is missing

func NewPodsSchedulingFailureEvent

func NewPodsSchedulingFailureEvent(unscheduledPodNames []string, apiObject APIObject) *Event

NewPodsSchedulingFailureEvent creates an event indicating that one of more cannot be scheduled.

func NewPodsSchedulingResolvedEvent

func NewPodsSchedulingResolvedEvent(apiObject APIObject) *Event

NewPodsSchedulingResolvedEvent creates an event indicating that an earlier problem with pod scheduling has been resolved.

func NewSecretsChangedEvent

func NewSecretsChangedEvent(changedSecretNames []string, apiObject APIObject) *Event

NewSecretsChangedEvent creates an event indicating that one of more secrets have changed.

func NewSecretsRestoredEvent

func NewSecretsRestoredEvent(apiObject APIObject) *Event

NewSecretsRestoredEvent creates an event indicating that all secrets have been restored to their original values.

func NewUpgradeNotAllowedEvent

func NewUpgradeNotAllowedEvent(apiObject APIObject,
	fromVersion, toVersion driver.Version,
	fromLicense, toLicense upgraderules.License) *Event

NewUpgradeNotAllowedEvent creates an event indicating that an upgrade (or downgrade) is not allowed.

type Informer

type Informer interface {
	WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool
}

type K8SObject

type K8SObject interface {
	meta.Object
	// AsOwner creates an OwnerReference for the given deployment
	AsOwner() meta.OwnerReference
}

type License

type License string

func (License) IsV2Set

func (l License) IsV2Set() bool

func (License) V2Hash

func (l License) V2Hash() string

type LicenseSecret

type LicenseSecret struct {
	V1 string
	V2 License
}

func GetLicenseFromSecret

func GetLicenseFromSecret(secret secret.Inspector, name string) (LicenseSecret, error)

type OptionPair

type OptionPair struct {
	Key   string
	Value string
}

OptionPair key value pair builder

func ExtractStringToOptionPair

func ExtractStringToOptionPair(arg string) OptionPair

ExtractStringToOptionPair extracts command line argument into the OptionPair.

func (OptionPair) CompareTo

func (o OptionPair) CompareTo(other OptionPair) int

CompareTo returns -1 if o < other, 0 if o == other, 1 otherwise

func (OptionPair) String

func (o OptionPair) String() string

type OptionPairs

type OptionPairs []OptionPair

OptionPairs list of pair builder

func CreateOptionPairs

func CreateOptionPairs(lens ...int) OptionPairs

func NewOptionPair

func NewOptionPair(pairs ...OptionPair) OptionPairs

func (*OptionPairs) Add

func (o *OptionPairs) Add(key string, value interface{})

func (*OptionPairs) Addf

func (o *OptionPairs) Addf(key, format string, i ...interface{})

func (*OptionPairs) Append

func (o *OptionPairs) Append(pairs ...OptionPair)

func (OptionPairs) AsArgs

func (o OptionPairs) AsArgs() []string

func (OptionPairs) AsArgsWithCommand

func (o OptionPairs) AsArgsWithCommand(command string) []string

func (OptionPairs) AsSplittedArgs

func (o OptionPairs) AsSplittedArgs() []string

func (OptionPairs) Copy

func (o OptionPairs) Copy() OptionPairs

func (*OptionPairs) Merge

func (o *OptionPairs) Merge(pairs ...OptionPairs)

func (OptionPairs) Sort

func (o OptionPairs) Sort() OptionPairs

func (OptionPairs) Unique

func (o OptionPairs) Unique() OptionPairs

type Reconcile

type Reconcile interface {
	Reconcile(ctx context.Context) error
	Required()
	IsRequired() bool
	WithError(err error) error

	ParallelAll(items int, executor func(id int) error) error
	Parallel(items, max int, executor func(id int) error) error
}

func NewReconcile

func NewReconcile(refresh refresh.Inspector) Reconcile

type RemoveFinalizersClient

type RemoveFinalizersClient[T meta.Object] interface {
	generic.GetInterface[T]
	generic.PatchInterface[T]
}

type ResourceWatcher

type ResourceWatcher struct {
	// contains filtered or unexported fields
}

ResourceWatcher is a helper to watch for events in a specific type of resource. The handler functions are protected from panics.

func NewResourceWatcher

func NewResourceWatcher(getter cache.Getter, resource, namespace string,
	objType runtime.Object, h cache.ResourceEventHandlerFuncs) *ResourceWatcher

NewResourceWatcher creates a helper that watches for changes in a resource of a specific type. If wraps the given handler functions, such that panics are caught and logged.

func (*ResourceWatcher) Run

func (rw *ResourceWatcher) Run(stopCh <-chan struct{})

Run continues to watch for events on the selected type of resource until the given channel is closed.

Jump to

Keyboard shortcuts

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