common

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2024 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Overview

Package common contains common utilities for the everest-operator.

Index

Constants

View Source
const (
	// Everest ...
	Everest = "everest"
	// DefaultPMMClientImage is the default image for PMM client.
	DefaultPMMClientImage = "percona/pmm-client:2"

	// DBClusterRestoreDBClusterNameField is the field in the DatabaseClusterRestore CR.
	DBClusterRestoreDBClusterNameField = ".spec.dbClusterName"
	// DBClusterBackupDBClusterNameField is the field in the DatabaseClusterBackup CR.
	DBClusterBackupDBClusterNameField = ".spec.dbClusterName"

	// TopologyKeyHostname is the topology key for hostname.
	TopologyKeyHostname = "kubernetes.io/hostname"

	// PXCDeploymentName is the name of the Percona XtraDB Cluster operator deployment.
	PXCDeploymentName = "percona-xtradb-cluster-operator"
	// PSMDBDeploymentName is the name of the Percona Server for MongoDB operator deployment.
	PSMDBDeploymentName = "percona-server-mongodb-operator"
	// PGDeploymentName is the name of the Percona PostgreSQL operator deployment.
	PGDeploymentName = "percona-postgresql-operator"

	// PXCAPIGroup is the API group for Percona XtraDB Cluster.
	PXCAPIGroup = "pxc.percona.com"
	// PSMDBAPIGroup is the API group for Percona Server for MongoDB.
	PSMDBAPIGroup = "psmdb.percona.com"
	// PGAPIGroup is the API group for Percona PostgreSQL.
	PGAPIGroup = "pgv2.percona.com"

	// PerconaXtraDBClusterKind is the kind for Percona XtraDB Cluster.
	PerconaXtraDBClusterKind = "PerconaXtraDBCluster"
	// PerconaServerMongoDBKind is the kind for Percona Server for MongoDB.
	PerconaServerMongoDBKind = "PerconaServerMongoDB"
	// PerconaPGClusterKind is the kind for Percona PostgreSQL.
	PerconaPGClusterKind = "PerconaPGCluster"
	// PerconaXtraDBClusterRestoreKind is the kind for Percona XtraDB Cluster restore.
	PerconaXtraDBClusterRestoreKind = "PerconaXtraDBClusterRestore"

	// ClusterTypeEKS represents the EKS cluster type.
	ClusterTypeEKS ClusterType = "eks"
	// ClusterTypeMinikube represents the Minikube cluster type.
	ClusterTypeMinikube ClusterType = "minikube"

	// LabelBackupStorageName is the label for backup storage name.
	LabelBackupStorageName = "percona.com/backup-storage-name"
	// LabelKubernetesManagedBy is a common label that indicates the resource is managed by a specific operator.
	LabelKubernetesManagedBy = "app.kubernetes.io/managed-by"

	// EverestSecretsPrefix is the prefix for secrets created by Everest.
	EverestSecretsPrefix = "everest-secrets-"

	// DBBackupCleanupFinalizer is the finalizer for cleaning up DatabaseClusterBackup.
	// Deprecated: We keep this for backward compatibility.
	DBBackupCleanupFinalizer = "everest.percona.com/dbb-cleanup"

	// UpstreamClusterCleanupFinalizer is the finalizer for cleaning up the upstream cluster.
	UpstreamClusterCleanupFinalizer = "everest.percona.com/upstream-cluster-cleanup"

	// ForegroundDeletionFinalizer is the finalizer that ensures foreground deletion for the resource.
	ForegroundDeletionFinalizer = "foregroundDeletion"
)

Variables

View Source
var (
	// PXCGVK is the GroupVersionKind for Percona XtraDB Cluster.
	PXCGVK = schema.GroupVersionKind{Group: PXCAPIGroup, Version: "v1", Kind: PerconaXtraDBClusterKind}
	// PXCRGVK is the GroupVersionKind for Percona PostgreSQL.
	PXCRGVK = schema.GroupVersionKind{Group: PXCAPIGroup, Version: "v1", Kind: PerconaXtraDBClusterRestoreKind}
	// PSMDBGVK is the GroupVersionKind for Percona Server for MongoDB.
	PSMDBGVK = schema.GroupVersionKind{Group: PSMDBAPIGroup, Version: "v1", Kind: PerconaServerMongoDBKind}
	// PGGVK is the GroupVersionKind for Percona PostgreSQL.
	PGGVK = schema.GroupVersionKind{Group: PGAPIGroup, Version: "v2", Kind: PerconaPGClusterKind}
)
View Source
var (
	// ErrPitrTypeIsNotSupported is an error for unsupported PITR type.
	ErrPitrTypeIsNotSupported = errors.New("unknown PITR type")
	// ErrPitrTypeLatest is an error for 'latest' being an unsupported PITR type.
	ErrPitrTypeLatest = errors.New("'latest' type is not supported by Everest yet")
	// ErrPitrEmptyDate is an error for missing PITR date.
	ErrPitrEmptyDate = errors.New("no date provided for PITR of type 'date'")

	// ErrPSMDBOneStorageRestriction is an error for using more than one storage for psmdb clusters.
	ErrPSMDBOneStorageRestriction = errors.New("using more than one storage is not allowed for psmdb clusters")
)
View Source
var DefaultNamespaceFilter predicate.Predicate = &predicates.Nop{}

DefaultNamespaceFilter is the default namespace filter.

View Source
var ExposeAnnotationsMap = map[ClusterType]map[string]string{
	ClusterTypeEKS: {
		"service.beta.kubernetes.io/aws-load-balancer-type": "nlb",
	},
}

ExposeAnnotationsMap is a map of annotations needed for exposing the database cluster.

Functions

func BackupStoragePrefix

func BackupStoragePrefix(db *everestv1alpha1.DatabaseCluster) string

BackupStoragePrefix returns the prefix for the backup storage.

func CreateOrUpdate

func CreateOrUpdate(
	ctx context.Context,
	c client.Client,
	obj client.Object,
	patchSecretData bool,
) error

CreateOrUpdate creates or updates a resource. With patchSecretData the new secret Data is applied on top of the original secret's Data.

func CreateOrUpdateSecretData

func CreateOrUpdateSecretData(
	ctx context.Context,
	c client.Client,
	database *everestv1alpha1.DatabaseCluster,
	secretName string,
	data map[string][]byte,
) error

CreateOrUpdateSecretData creates or updates the data of a secret. When updating, it only changes the values of the keys specified in the data map. All other keys are left untouched, so it's not possible to delete a key.

func DefaultAffinitySettings added in v1.2.0

func DefaultAffinitySettings() *corev1.Affinity

DefaultAffinitySettings returns the default corev1.Affinity object used in Everest.

func EnqueueObjectsInNamespace added in v1.3.0

func EnqueueObjectsInNamespace(c client.Client, list client.ObjectList) handler.EventHandler

EnqueueObjectsInNamespace returns an event handler that should be attached with Namespace watchers. It enqueues all objects specified by the type of list in the triggered namespace.

func GetBackupStorage

func GetBackupStorage(
	ctx context.Context,
	c client.Client,
	name, namespace string,
) (*everestv1alpha1.BackupStorage, error)

GetBackupStorage returns a BackupStorage object with the specified name and namespace.

func GetDBMonitoringConfig

func GetDBMonitoringConfig(
	ctx context.Context,
	c client.Client,
	database *everestv1alpha1.DatabaseCluster,
) (*everestv1alpha1.MonitoringConfig, error)

GetDBMonitoringConfig returns the MonitoringConfig object for the given DatabaseCluster object.

func GetDatabaseEngine

func GetDatabaseEngine(ctx context.Context, c client.Client, name, namespace string) (*everestv1alpha1.DatabaseEngine, error)

GetDatabaseEngine gets the DatabaseEngine object with the specified name and namespace.

func GetOperatorImage added in v1.2.0

func GetOperatorImage(
	ctx context.Context,
	c client.Client,
	name types.NamespacedName,
) (string, error)

GetOperatorImage returns the image of the operator running in the cluster for the specified deployment name and namespace.

func GetOperatorVersion

func GetOperatorVersion(
	ctx context.Context,
	c client.Client,
	name types.NamespacedName,
) (*version.Version, error)

GetOperatorVersion returns the version of the operator running in the cluster for the specified deployment name and namespace.

TODO: Read the operator version from the DatabaseEngine status rather than fetching the Deployment, since DatabaseEngines are cached in the controller's client.

func GetRecommendedCRVersion added in v1.0.0

func GetRecommendedCRVersion(
	ctx context.Context,
	c client.Client,
	operatorName string,
	db *everestv1alpha1.DatabaseCluster,
) (*string, error)

GetRecommendedCRVersion returns the recommended CR version for the operator.

func GetRepoNameByBackupStorage added in v1.1.0

func GetRepoNameByBackupStorage(
	backupStorage *everestv1alpha1.BackupStorage,
	repos []crunchyv1beta1.PGBackRestRepo,
) string

GetRepoNameByBackupStorage returns the name of the repo that corresponds to the given backup storage.

func GetSecretFromMonitoringConfig

func GetSecretFromMonitoringConfig(
	ctx context.Context,
	c client.Client,
	monitoring *everestv1alpha1.MonitoringConfig,
) (string, error)

GetSecretFromMonitoringConfig gets the secret data from the MonitoringConfig.

func HandleDBBackupsCleanup

func HandleDBBackupsCleanup(
	ctx context.Context,
	c client.Client,
	database *everestv1alpha1.DatabaseCluster,
) (bool, error)

HandleDBBackupsCleanup handles the cleanup of the dbbackup objects. Returns true if cleanup is complete.

func HandleUpstreamClusterCleanup added in v1.1.0

func HandleUpstreamClusterCleanup(
	ctx context.Context,
	c client.Client,
	database *everestv1alpha1.DatabaseCluster,
	upstream client.Object,
) (bool, error)

HandleUpstreamClusterCleanup handles the cleanup of the psdmb objects. Returns true if cleanup is complete.

func IsDatabaseClusterRestoreRunning

func IsDatabaseClusterRestoreRunning(
	ctx context.Context,
	c client.Client,
	dbName, dbNs string,
) (bool, error)

IsDatabaseClusterRestoreRunning returns true if a restore is running for the specified database, otherwise false.

func IsOwnedBy

func IsOwnedBy(child, parent metav1.Object) bool

IsOwnedBy checks if the child object is owned by the parent object. Returns true if child has an owner reference to the parents.

func ListDatabaseClusterBackups

func ListDatabaseClusterBackups(
	ctx context.Context,
	c client.Client,
	dbName, dbNs string,
) (*everestv1alpha1.DatabaseClusterBackupList, error)

ListDatabaseClusterBackups returns a list of DatabaseClusterBackup objects for the DatabaseCluster with the specified name and namespace.

func ListDatabaseClusterRestores

func ListDatabaseClusterRestores(
	ctx context.Context,
	c client.Client,
	dbName, dbNs string,
) (*everestv1alpha1.DatabaseClusterRestoreList, error)

ListDatabaseClusterRestores lists the DatabaseClusterRestores for the database specified by the name and namespace.

func PITRBucketName

func PITRBucketName(db *everestv1alpha1.DatabaseCluster, bucket string) string

PITRBucketName returns the name of the bucket for the point-in-time recovery backups.

func PITRStorageName

func PITRStorageName(storageName string) string

PITRStorageName returns the name of the storage for the point-in-time recovery backups.

func ReconcileDBRestoreFromDataSource

func ReconcileDBRestoreFromDataSource(
	ctx context.Context,
	c client.Client,
	database *everestv1alpha1.DatabaseCluster,
) error

ReconcileDBRestoreFromDataSource reconciles the DatabaseClusterRestore object based on the DataSource field of the DatabaseCluster.

func StatusAsPlainTextOrEmptyString added in v1.2.0

func StatusAsPlainTextOrEmptyString(status interface{}) string

StatusAsPlainTextOrEmptyString returns the status as a plain text string or an empty string.

func UpdateSecretData

func UpdateSecretData(
	ctx context.Context,
	c client.Client,
	database *everestv1alpha1.DatabaseCluster,
	secretName string,
	data map[string][]byte,
) error

UpdateSecretData updates the data of a secret. It only changes the values of the keys specified in the data map. All other keys are left untouched, so it's not possible to delete a key.

func ValidatePitrRestoreSpec

func ValidatePitrRestoreSpec(dataSource everestv1alpha1.DataSource) error

ValidatePitrRestoreSpec validates the PITR restore spec.

Types

type ClusterType

type ClusterType string

ClusterType represents the type of the cluster.

func GetClusterType

func GetClusterType(ctx context.Context, c client.Client) (ClusterType, error)

GetClusterType returns the type of the cluster on which this operator is running.

Jump to

Keyboard shortcuts

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