common

package
v1.8.1 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2025 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Overview

Package common contains common utilities for the everest-operator.

Index

Constants

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

Variables

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.

Functions

func BackupStoragePrefix

func BackupStoragePrefix(db *everestv1alpha1.DatabaseCluster) string

BackupStoragePrefix returns the prefix for the backup storage.

func BackupStoragesThatReferenceObject added in v1.8.0

func BackupStoragesThatReferenceObject(
	ctx context.Context,
	c client.Client,
	keyPath, namespace, keyValue string,
) (*everestv1alpha1.BackupStorageList, error)

BackupStoragesThatReferenceObject returns a list of BackupStorages that reference the given name by the provided keyPath and namespace.

func ConfigureStorage added in v1.6.0

func ConfigureStorage(
	ctx context.Context,
	c client.Client,
	db *everestv1alpha1.DatabaseCluster,
	currentSize resource.Quantity,
	setStorageSizeFunc func(resource.Quantity),
) error

ConfigureStorage handles storage configuration and volume expansion checks for the given database cluster.

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,
	setControllerRef bool,
) 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 DatabaseClusterBackupsThatReferenceObject added in v1.8.0

func DatabaseClusterBackupsThatReferenceObject(
	ctx context.Context,
	c client.Client,
	keyPath, namespace, keyValue string,
) (*everestv1alpha1.DatabaseClusterBackupList, error)

DatabaseClusterBackupsThatReferenceObject returns a list of DatabaseClusterBackups that reference the given name by the provided keyPath and namespace.

func DatabaseClusterRestoresThatReferenceObject added in v1.8.0

func DatabaseClusterRestoresThatReferenceObject(
	ctx context.Context,
	c client.Client,
	keyPath, namespace, keyValue string,
) (*everestv1alpha1.DatabaseClusterRestoreList, error)

DatabaseClusterRestoresThatReferenceObject returns a list of DatabaseClusterRestores that reference the given name by the provided keyPath and namespace.

func DatabaseClustersThatReferenceObject added in v1.7.0

func DatabaseClustersThatReferenceObject(
	ctx context.Context,
	c client.Client,
	keyPath, namespace, keyValue string,
) (*everestv1alpha1.DatabaseClusterList, error)

DatabaseClustersThatReferenceObject returns a list of DatabaseClusters that reference the given name by the provided keyPath and namespace.

func EnqueueObjectsInNamespace

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 EnsureInUseFinalizer added in v1.8.0

func EnsureInUseFinalizer(ctx context.Context, c client.Client, used bool, obj client.Object) error

EnsureInUseFinalizer ensures that the InUseResourceFinalizer is present or absent.

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 GetClusterType

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

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

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 GetDataImportJobName added in v1.8.0

func GetDataImportJobName(db *everestv1alpha1.DatabaseCluster) string

GetDataImportJobName returns the name of the DataImport job for the given database cluster.

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

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 GetPMMResources added in v1.8.0

func GetPMMResources(monitoringSpec everestv1alpha1.Monitoring, dbEnginSize everestv1alpha1.EngineSize) corev1.ResourceRequirements

GetPMMResources returns the resource requirements for PMM based on the monitoring configuration and database engine size.

func GetPodSchedulingPolicy added in v1.7.0

func GetPodSchedulingPolicy(ctx context.Context, c client.Client, pspName string) (*everestv1alpha1.PodSchedulingPolicy, error)

GetPodSchedulingPolicy returns the PodSchedulingPolicy object by name.

func GetRecommendedCRVersion

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

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

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 MonitoringConfigsThatReferenceObject added in v1.8.0

func MonitoringConfigsThatReferenceObject(
	ctx context.Context,
	c client.Client,
	keyPath, namespace, keyValue string,
) (*everestv1alpha1.MonitoringConfigList, error)

MonitoringConfigsThatReferenceObject returns a list of MonitoringConfig that reference the given name by the provided keyPath 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

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,
	setControllerRef bool,
) 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.

func VerifyPVCResizeFailure added in v1.6.0

func VerifyPVCResizeFailure(ctx context.Context, c client.Client, name, namespace string) (bool, string, error)

VerifyPVCResizeFailure checks if the PVC resize failed. If it failed, it returns true and the error message.

Types

This section is empty.

Jump to

Keyboard shortcuts

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