utils

package
v1.23.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 70 Imported by: 0

Documentation

Overview

Package utils contains helper functions/methods for e2e

Index

Constants

View Source
const (
	// RetryTimeout retry timeout (in seconds) when a client api call or kubectl cli request get failed
	RetryTimeout = 60
	// RetryAttempts maximum number of attempts when it fails in `retry`. Mainly used in `RunUncheckedRetry`
	RetryAttempts = 5
	// PollingTime polling interval (in seconds) between retries
	PollingTime = 5
)
View Source
const (
	// PGLocalSocketDir is the directory containing the PostgreSQL local socket
	PGLocalSocketDir = "/controller/run"
	// AppUser for app user
	AppUser = "app"
	// PostgresUser for postgres user
	PostgresUser = "postgres"
	// AppDBName database name app
	AppDBName = "app"
	// PostgresDBName database name postgres
	PostgresDBName = "postgres"
)
View Source
const TestTimeoutsEnvVar = "TEST_TIMEOUTS"

TestTimeoutsEnvVar is the environment variable where specific timeouts can be set for the E2E test suite

Variables

View Source
var AKS = TestEnvVendor("aks")

AKS azure cloud cluster

DefaultTestTimeouts contains the default timeout in seconds for various events

View Source
var EKS = TestEnvVendor("eks")

EKS amazon elastic cloud cluster

View Source
var ErrEnvVarNotFound = errors.New("could not find environment variable")

ErrEnvVarNotFound is thrown when a SHELL-FORMAT var in a file does not have a matching env variable

View Source
var GKE = TestEnvVendor("gke")

GKE google cloud cluster

View Source
var LOCAL = TestEnvVendor("local")

LOCAL kind or k3d cluster running locally

View Source
var OCP = TestEnvVendor("ocp")

OCP openshift cloud cluster

Functions

func AllClusterPodsHaveAnnotations

func AllClusterPodsHaveAnnotations(
	env *TestingEnvironment,
	namespace, clusterName string,
	annotations map[string]string,
) (bool, error)

AllClusterPodsHaveAnnotations verifies if the annotations defined in a map are included in all the pods of a cluster

func AllClusterPodsHaveLabels

func AllClusterPodsHaveLabels(
	env *TestingEnvironment,
	namespace, clusterName string,
	labels map[string]string,
) (bool, error)

AllClusterPodsHaveLabels verifies if the labels defined in a map are included in all the pods of a cluster

func AreSameLsn added in v1.18.0

func AreSameLsn(lsnList []string) bool

AreSameLsn returns true if all the LSN values inside a given list are the same

func AssertQueryRecord

func AssertQueryRecord(logEntries []map[string]interface{}, errorTestQuery string, message string, logger string) bool

AssertQueryRecord verifies if any of the message record field of each JSON row contains the expectedResult string, then applies the assertions related to the log format

func BumpPostgresImageMajorVersion added in v1.16.0

func BumpPostgresImageMajorVersion(postgresImage string) (string, error)

BumpPostgresImageMajorVersion returns a postgresImage incrementing the major version of the argument (if available)

func CheckOptionsForBarmanCommand added in v1.21.4

func CheckOptionsForBarmanCommand(
	logEntries []map[string]interface{},
	message, backupName, podName string,
	optionsExpected []string,
) (bool, error)

CheckOptionsForBarmanCommand checks if the expected options are used from the barman command execution log

func CheckRecordForQuery

func CheckRecordForQuery(entry map[string]interface{}, errorTestQuery, user, database, message string) bool

CheckRecordForQuery applies some assertions related to the format of the JSON log fields keys and values

func CheckWebhookReady

func CheckWebhookReady(env *TestingEnvironment, namespace string) error

CheckWebhookReady ensures that the operator has finished the webhook setup.

func CleanFilesOnMinio added in v1.21.5

func CleanFilesOnMinio(minioEnv *MinioEnv, path string) (string, error)

CleanFilesOnMinio clean files on minio for a given path

func ClusterHasAnnotations

func ClusterHasAnnotations(
	cluster *apiv1.Cluster,
	annotations map[string]string,
) bool

ClusterHasAnnotations verifies that the annotations of a cluster contain a specified annotations map

func ClusterHasLabels

func ClusterHasLabels(
	cluster *apiv1.Cluster,
	labels map[string]string,
) bool

ClusterHasLabels verifies that the labels of a cluster contain a specified labels map

func ComposeAzBlobListAzuriteCmd

func ComposeAzBlobListAzuriteCmd(clusterName, path string) string

ComposeAzBlobListAzuriteCmd builds the Azure storage blob list command for Azurite

func ComposeAzBlobListCmd

func ComposeAzBlobListCmd(
	configuration AzureConfiguration,
	clusterName,
	path string,
) string

ComposeAzBlobListCmd builds the Azure storage blob list command

func CountFilesOnAzureBlobStorage

func CountFilesOnAzureBlobStorage(
	configuration AzureConfiguration,
	clusterName,
	path string,
) (int, error)

CountFilesOnAzureBlobStorage counts files on Azure Blob storage

func CountFilesOnAzuriteBlobStorage

func CountFilesOnAzuriteBlobStorage(
	namespace,
	clusterName,
	path string,
) (int, error)

CountFilesOnAzuriteBlobStorage counts files on Azure Blob storage. using Azurite

func CountFilesOnMinio

func CountFilesOnMinio(minioEnv *MinioEnv, path string) (value int, err error)

CountFilesOnMinio uses the minioClient in the given `namespace` to count the amount of files matching the given `path`

func CountReplicas

func CountReplicas(env *TestingEnvironment, pod *corev1.Pod) (int, error)

CountReplicas counts the number of replicas attached to an instance

func CreateBackup added in v1.21.1

func CreateBackup(
	targetBackup apiv1.Backup,
	env *TestingEnvironment,
) (*apiv1.Backup, error)

CreateBackup creates a Backup resource for a given cluster name

func CreateCertificateSecretsOnAzurite added in v1.15.3

func CreateCertificateSecretsOnAzurite(
	namespace,
	clusterName,
	azuriteCaSecName,
	azuriteTLSSecName string,
	env *TestingEnvironment,
) error

CreateCertificateSecretsOnAzurite will create secrets for Azurite deployment

func CreateClientCertificatesViaKubectlPlugin

func CreateClientCertificatesViaKubectlPlugin(
	cluster apiv1.Cluster,
	certName string,
	userName string,
	env *TestingEnvironment,
) error

CreateClientCertificatesViaKubectlPlugin creates a certificate for a given user on a given cluster

func CreateClusterFromBackupUsingPITR

func CreateClusterFromBackupUsingPITR(
	namespace,
	clusterName,
	backupFilePath,
	targetTime string,
	env *TestingEnvironment,
) (*apiv1.Cluster, error)

CreateClusterFromBackupUsingPITR creates a cluster from backup, using the PITR

func CreateClusterFromExternalClusterBackupWithPITROnAzure

func CreateClusterFromExternalClusterBackupWithPITROnAzure(
	namespace,
	externalClusterName,
	sourceClusterName,
	targetTime,
	storageCredentialsSecretName,
	azStorageAccount,
	azBlobContainer string,
	env *TestingEnvironment,
) (*apiv1.Cluster, error)

CreateClusterFromExternalClusterBackupWithPITROnAzure creates a cluster on Azure, starting from an external cluster backup with PITR

func CreateClusterFromExternalClusterBackupWithPITROnAzurite

func CreateClusterFromExternalClusterBackupWithPITROnAzurite(
	namespace,
	externalClusterName,
	sourceClusterName,
	targetTime string,
	env *TestingEnvironment,
) (*apiv1.Cluster, error)

CreateClusterFromExternalClusterBackupWithPITROnAzurite creates a cluster with Azurite, starting from an external cluster backup with PITR

func CreateClusterFromExternalClusterBackupWithPITROnMinio

func CreateClusterFromExternalClusterBackupWithPITROnMinio(
	namespace,
	externalClusterName,
	sourceClusterName,
	targetTime string,
	env *TestingEnvironment,
) (*apiv1.Cluster, error)

CreateClusterFromExternalClusterBackupWithPITROnMinio creates a cluster on Minio, starting from an external cluster backup with PITR

func CreateDSN added in v1.18.1

func CreateDSN(host, user, dbname, password string, sslmode SSLMode, port int) string

CreateDSN return DSN name

func CreateObject

func CreateObject(env *TestingEnvironment, object client.Object, opts ...client.CreateOption) (client.Object, error)

CreateObject create object in the Kubernetes cluster

func CreateOnDemandBackup added in v1.21.0

func CreateOnDemandBackup(
	namespace,
	clusterName,
	backupName string,
	target apiv1.BackupTarget,
	method apiv1.BackupMethod,
	env *TestingEnvironment,
) (*apiv1.Backup, error)

CreateOnDemandBackup creates a Backup resource for a given cluster name Deprecated: Use CreateBackup. TODO: eradicate

func CreateOnDemandBackupViaKubectlPlugin added in v1.21.0

func CreateOnDemandBackupViaKubectlPlugin(
	namespace,
	clusterName,
	backupName string,
	target apiv1.BackupTarget,
	method apiv1.BackupMethod,
) error

CreateOnDemandBackupViaKubectlPlugin uses the kubectl plugin to create a backup

func CreateOperatorConfigurationMap added in v1.20.6

func CreateOperatorConfigurationMap(pgOperatorNamespace, configName string, isOnline bool, env *TestingEnvironment)

CreateOperatorConfigurationMap creates the operator namespace and enables/disable the online upgrade for the instance manager

func CreateSecretCA

func CreateSecretCA(
	namespace string,
	clusterName string,
	caSecName string,
	includeCAPrivateKey bool,
	env *TestingEnvironment) (
	*apiv1.Cluster, *certs.KeyPair, error,
)

CreateSecretCA generates a CA for the cluster and return the cluster and the key pair

func CreateServiceFQDN added in v1.18.1

func CreateServiceFQDN(namespace, serviceName string) string

CreateServiceFQDN create service name with full dns

func CreateStorageCredentialsOnAzurite added in v1.15.3

func CreateStorageCredentialsOnAzurite(namespace string, env *TestingEnvironment) error

CreateStorageCredentialsOnAzurite will create credentials for Azurite

func CreateSubscription added in v1.21.3

func CreateSubscription(env *TestingEnvironment, channel string) error

CreateSubscription creates a subscription object inside openshift with a fixed name

func CurlClient

func CurlClient(namespace string) corev1.Pod

CurlClient returns the Pod definition for a curl client

func CurlGetMetrics

func CurlGetMetrics(namespace, curlPodName, podIP string, port int) (string, error)

CurlGetMetrics returns true if test connection is successful else false

func DefaultWebapp

func DefaultWebapp(namespace string, name string, rootCASecretName string, tlsSecretName string) corev1.Pod

DefaultWebapp returns a struct representing a

func DeleteCSV added in v1.21.3

func DeleteCSV(env *TestingEnvironment) error

DeleteCSV will delete all operator's CSVs

func DeleteObject

func DeleteObject(env *TestingEnvironment, object client.Object, opts ...client.DeleteOption) error

DeleteObject delete object in the Kubernetes cluster

func DeleteOperatorCRDs added in v1.21.3

func DeleteOperatorCRDs(env *TestingEnvironment) error

DeleteOperatorCRDs deletes the CRDs associated with the operator

func DeleteSubscription added in v1.21.3

func DeleteSubscription(env *TestingEnvironment) error

DeleteSubscription deletes the operator's subscription object

func DeploymentIsReady

func DeploymentIsReady(deployment appsv1.Deployment) bool

DeploymentIsReady checks if a Deployment is ready

func DeploymentWaitForReady

func DeploymentWaitForReady(env *TestingEnvironment, deployment *appsv1.Deployment, timeoutSeconds uint) error

DeploymentWaitForReady waits for a Deployment to be ready

func Envsubst added in v1.15.4

func Envsubst(vars map[string]string, data []byte) ([]byte, error)

Envsubst substitutes any SHELL-FORMAT variables embedded in a file by the value of the corresponding environment variable, provided in `vars`

SHELL-FORMAT is, `${foo}` BUT NOT `$foo`, for simplicity of implementation

NOTE: If a variable embedded in the file is not provided in the `vars` argument, this function will error out. This is different from the behavior of the `envsubst` shell command: in testing we should avoid silent failures

func ExecuteBackup

func ExecuteBackup(
	namespace,
	backupFile string,
	onlyTargetStandbys bool,
	timeoutSeconds int,
	env *TestingEnvironment,
) *apiv1.Backup

ExecuteBackup performs a backup and checks the backup status

func FencingOff

func FencingOff(
	env *TestingEnvironment,
	serverName,
	namespace,
	clusterName string,
	fencingMethod FencingMethod,
) error

FencingOff marks an instance in a cluster as not fenced

func FencingOn

func FencingOn(
	env *TestingEnvironment,
	serverName,
	namespace,
	clusterName string,
	fencingMethod FencingMethod,
) error

FencingOn marks an instance in a cluster as fenced

func FirstEndpointIP

func FirstEndpointIP(endpoint *corev1.Endpoints) string

FirstEndpointIP returns the IP of first Address in the Endpoint

func ForgeArchiveWalOnMinio

func ForgeArchiveWalOnMinio(namespace, clusterName, miniClientPodName, existingWALName, newWALName string) error

ForgeArchiveWalOnMinio instead of using `switchWalCmd` to generate a real WAL archive, directly forges a WAL archive file on Minio by copying and renaming an existing WAL archive file for the sake of more control of testing. To make sure the forged one won't be a real WAL archive, we let the sequence in newWALName to be big enough so that it can't be a real WAL archive name in an idle postgresql.

func GetAvailableReleases added in v1.15.1

func GetAvailableReleases(releasesPath string) ([]*semver.Version, error)

GetAvailableReleases retrieves all the available releases from the list of YAML files in the top-level `releases/` directory.

func GetCNPGsMutatingWebhookByName

func GetCNPGsMutatingWebhookByName(env *TestingEnvironment, name string) (
	*admissionregistrationv1.MutatingWebhookConfiguration, int, error,
)

GetCNPGsMutatingWebhookByName get the MutatingWebhook filtered by the name of one of the webhooks

func GetCNPGsValidatingWebhookByName

func GetCNPGsValidatingWebhookByName(env *TestingEnvironment, name string) (
	*admissionregistrationv1.ValidatingWebhookConfiguration, int, error,
)

GetCNPGsValidatingWebhookByName get ValidatingWebhook by the name of one of the webhooks

func GetCNPGsValidatingWebhookConf

func GetCNPGsValidatingWebhookConf(env *TestingEnvironment) (
	*admissionregistrationv1.ValidatingWebhookConfiguration, error,
)

GetCNPGsValidatingWebhookConf get the ValidatingWebhook linked to the operator

func GetConditionsInClusterStatus

func GetConditionsInClusterStatus(
	namespace,
	clusterName string,
	env *TestingEnvironment,
	conditionType apiv1.ClusterConditionType,
) (*metav1.Condition, error)

GetConditionsInClusterStatus get conditions values as given type from cluster object status

func GetCredentials added in v1.18.1

func GetCredentials(
	clusterName, namespace string,
	secretSuffix string,
	env *TestingEnvironment) (
	string, string, error,
)

GetCredentials retrieve username and password from secrets and return it as per user suffix

func GetCurrentTimestamp

func GetCurrentTimestamp(namespace, clusterName string, env *TestingEnvironment, podName *corev1.Pod) (string, error)

GetCurrentTimestamp getting current time stamp from postgres server

func GetExpectedHAReplicationSlotsOnPod added in v1.23.0

func GetExpectedHAReplicationSlotsOnPod(
	namespace, clusterName, podName string,
	env *TestingEnvironment,
) ([]string, error)

GetExpectedHAReplicationSlotsOnPod returns a slice of replication slot names which should be present in a given pod

func GetHostName added in v1.18.1

func GetHostName(namespace, clusterName string, env *TestingEnvironment) (string, error)

GetHostName return fully qualified domain name for read write service

func GetLeaderInfoFromLease added in v1.15.1

func GetLeaderInfoFromLease(operatorNamespace string, env *TestingEnvironment) (string, error)

GetLeaderInfoFromLease gathers leader holderIdentity from the lease

func GetManagerVersion added in v1.21.3

func GetManagerVersion(namespace, podName string) (string, error)

GetManagerVersion returns the current manager version of a given pod

func GetMostRecentReleaseTag

func GetMostRecentReleaseTag(releasesPath string) (string, error)

GetMostRecentReleaseTag retrieves the most recent release tag from the list of YAML files in the top-level `releases/` directory. Used for testing upgrades, so: if we're in a release branch, the MostRecent should be the next-to-last release

func GetObject

func GetObject(env *TestingEnvironment, objectKey client.ObjectKey, object client.Object) error

GetObject retrieves an objects for the given object key from the Kubernetes Cluster

func GetObjectList

func GetObjectList(env *TestingEnvironment, objectList client.ObjectList, opts ...client.ListOption) error

GetObjectList retrieves list of objects for a given namespace and list options

func GetOpenshiftVersion added in v1.21.3

func GetOpenshiftVersion(env *TestingEnvironment) (semver.Version, error)

GetOpenshiftVersion returns the current openshift version

func GetOperatorArchitectures added in v1.21.4

func GetOperatorArchitectures(operatorPod *corev1.Pod) ([]string, error)

GetOperatorArchitectures returns all the supported operator architectures

func GetOperatorPodName added in v1.21.3

func GetOperatorPodName(env *TestingEnvironment) (string, error)

GetOperatorPodName returns the name of the current operator pod NOTE: will return an error if the pod is being deleted

func GetOperatorVersion added in v1.21.3

func GetOperatorVersion(namespace, podName string) (string, error)

GetOperatorVersion returns the current operator version

func GetPsqlClient added in v1.16.5

func GetPsqlClient(namespace string, env *TestingEnvironment) (*corev1.Pod, error)

GetPsqlClient gets a psql client pod for service connectivity

func GetReadWriteServiceName added in v1.18.1

func GetReadWriteServiceName(clusterName string) string

GetReadWriteServiceName read write service name

func GetReplicationSlotLsnsOnPod added in v1.18.0

func GetReplicationSlotLsnsOnPod(
	namespace, clusterName string,
	pod corev1.Pod,
	env *TestingEnvironment,
) ([]string, error)

GetReplicationSlotLsnsOnPod returns a slice containing the current restart_lsn values of each replication slot present in a given pod

func GetReplicationSlotsOnPod added in v1.18.0

func GetReplicationSlotsOnPod(namespace, podName string, env *TestingEnvironment) ([]string, error)

GetReplicationSlotsOnPod returns a slice containing the names of the current replication slots present in a given pod

func GetRwServiceObject added in v1.18.1

func GetRwServiceObject(namespace, clusterName string, env *TestingEnvironment) (*corev1.Service, error)

GetRwServiceObject return read write service object

func GetStorageAllowExpansion

func GetStorageAllowExpansion(defaultStorageClass string, env *TestingEnvironment) (*bool, error)

GetStorageAllowExpansion returns the boolean value of the 'AllowVolumeExpansion' value of the storage class

func GetSubscription added in v1.21.3

func GetSubscription(env *TestingEnvironment) (*unstructured.Unstructured, error)

GetSubscription returns an unstructured subscription object

func GetSubscriptionVersion added in v1.21.3

func GetSubscriptionVersion(env *TestingEnvironment) (string, error)

GetSubscriptionVersion retrieves the current ClusterServiceVersion version of the operator

func HasLogger

func HasLogger(logEntries []map[string]interface{}, logger string) bool

HasLogger verifies if a given value exists inside a list of JSON entries

func HasOperatorBeenUpgraded added in v1.21.3

func HasOperatorBeenUpgraded(env *TestingEnvironment) bool

HasOperatorBeenUpgraded determines if the operator has been upgraded by checking if there is a deletion timestamp. If there isn't, it returns true

func HibernateOff added in v1.22.0

func HibernateOff(
	env *TestingEnvironment,
	namespace,
	clusterName string,
	method HibernationMethod,
) error

HibernateOff hibernate off a cluster

func HibernateOn added in v1.22.0

func HibernateOn(
	env *TestingEnvironment,
	namespace,
	clusterName string,
	method HibernationMethod,
) error

HibernateOn hibernate on a cluster

func ImportDatabaseMicroservice added in v1.16.0

func ImportDatabaseMicroservice(
	namespace,
	sourceClusterName,
	importedClusterName,
	imageName,
	databaseName string,
	env *TestingEnvironment,
) (*apiv1.Cluster, error)

ImportDatabaseMicroservice creates a cluster, starting from an external cluster using microservice approach NOTE: the application user on the source Cluster needs to be granted with REPLICATION permissions, which are not set by default

func ImportDatabasesMonolith added in v1.18.4

func ImportDatabasesMonolith(
	namespace,
	sourceClusterName,
	importedClusterName,
	imageName string,
	databaseNames []string,
	roles []string,
	env *TestingEnvironment,
) (*apiv1.Cluster, error)

ImportDatabasesMonolith creates a new cluster spec importing from a sourceCluster using the Monolith approach. Imports all the specified `databaseNames` and `roles` from the source cluster NOTE: enableSuperuserAccess needs to be enabled

func InstallAzCli added in v1.15.3

func InstallAzCli(namespace string, env *TestingEnvironment) error

InstallAzCli will install Az cli

func InstallAzurite added in v1.15.3

func InstallAzurite(namespace string, env *TestingEnvironment) error

InstallAzurite will set up Azurite in defined namespace and creates service

func InstallLatestCNPGOperator

func InstallLatestCNPGOperator(releaseTag string, env *TestingEnvironment)

InstallLatestCNPGOperator installs an operator version with the most recent release tag

func InstallMinio

func InstallMinio(
	env *TestingEnvironment,
	minioSetup MinioSetup,
	timeoutSeconds uint,
) error

InstallMinio installs minio in a given namespace

func IsWalStorageEnabled added in v1.17.0

func IsWalStorageEnabled(namespace, clusterName string, env *TestingEnvironment) (bool, error)

IsWalStorageEnabled returns true if 'WalStorage' is being used

func IsWellFormedLogForLogger

func IsWellFormedLogForLogger(item map[string]interface{}, loggerField string) bool

IsWellFormedLogForLogger verifies if the message record field of the given map contains the expectedResult string. If the message field matches the expectedResult, then the related record is returned. Otherwise return nil.

func ListFilesOnMinio added in v1.21.5

func ListFilesOnMinio(minioEnv *MinioEnv, path string) (string, error)

ListFilesOnMinio uses the minioClient in the given `namespace` to list the paths matching the given `path`

func MinioDefaultClient

func MinioDefaultClient(namespace string) corev1.Pod

MinioDefaultClient returns the default Pod definition for a minio client

func MinioDefaultDeployment

func MinioDefaultDeployment(namespace string, minioPVC corev1.PersistentVolumeClaim) appsv1.Deployment

MinioDefaultDeployment returns a default Deployment for minio

func MinioDefaultPVC

func MinioDefaultPVC(namespace string) (corev1.PersistentVolumeClaim, error)

MinioDefaultPVC returns a default PVC for minio

func MinioDefaultSVC

func MinioDefaultSVC(namespace string) corev1.Service

MinioDefaultSVC returns a default Service for minio

func MinioDeploy added in v1.21.5

func MinioDeploy(minioEnv *MinioEnv, env *TestingEnvironment) (*corev1.Pod, error)

MinioDeploy will create a full MinIO deployment defined inthe minioEnv variable

func MinioSSLClient

func MinioSSLClient(namespace string) corev1.Pod

MinioSSLClient returns the Pod definition for a minio client using SSL

func MinioTestConnectivityUsingBarmanCloudWalArchive

func MinioTestConnectivityUsingBarmanCloudWalArchive(
	namespace,
	clusterName,
	podName,
	id,
	key string,
	minioSvcName string,
) (bool, error)

MinioTestConnectivityUsingBarmanCloudWalArchive returns true if test connection is successful else false

func ObjectHasAnnotations added in v1.18.0

func ObjectHasAnnotations(
	object client.Object,
	annotations []string,
) bool

ObjectHasAnnotations returns true if the object has the passed annotations

func ObjectMatchesAnnotations added in v1.18.0

func ObjectMatchesAnnotations(
	object client.Object,
	annotations map[string]string,
) bool

ObjectMatchesAnnotations returns true if the object has the passed annotations key/value

func OperatorPodRenamed

func OperatorPodRenamed(operatorPod corev1.Pod, expectedOperatorPodName string) bool

OperatorPodRenamed checks if the operator pod was renamed

func OperatorPodRestarted

func OperatorPodRestarted(operatorPod corev1.Pod) bool

OperatorPodRestarted checks if the operator pod was restarted

func ParseJSONLogs

func ParseJSONLogs(namespace string, podName string, env *TestingEnvironment) ([]map[string]interface{}, error)

ParseJSONLogs returns the pod's logs of a given pod name, in the form of a list of JSON entries

func ParseObjectsFromYAML added in v1.15.4

func ParseObjectsFromYAML(data []byte, namespace string) ([]client.Object, error)

ParseObjectsFromYAML parses a series of kubernetes objects defined in a YAML payload, into the specified namespace

func PatchStatusCondition added in v1.21.3

func PatchStatusCondition(namespace, clusterName string, env *TestingEnvironment) error

PatchStatusCondition removes status conditions on a given Cluster

func PodCreateAndWaitForReady

func PodCreateAndWaitForReady(env *TestingEnvironment, pod *corev1.Pod, timeoutSeconds uint) error

PodCreateAndWaitForReady creates a given pod object and wait for it to be ready

func PodHasAnnotations

func PodHasAnnotations(pod corev1.Pod, annotations map[string]string) bool

PodHasAnnotations verifies that the annotations of a pod contain a specified annotations map

func PodHasLabels

func PodHasLabels(pod corev1.Pod, labels map[string]string) bool

PodHasLabels verifies that the labels of a pod contain a specified labels map

func PodWaitForReady

func PodWaitForReady(env *TestingEnvironment, pod *corev1.Pod, timeoutSeconds uint) error

PodWaitForReady waits for a pod to be ready

func PrintClusterResources added in v1.18.0

func PrintClusterResources(namespace, clusterName string, env *TestingEnvironment) string

PrintClusterResources prints a summary of the cluster pods, jobs, pvcs etc.

func PrintReplicationSlots added in v1.18.0

func PrintReplicationSlots(
	namespace,
	clusterName string,
	env *TestingEnvironment,
) string

PrintReplicationSlots prints replications slots with their restart_lsn

func PvcHasLabels added in v1.17.0

func PvcHasLabels(
	pvc corev1.PersistentVolumeClaim,
	labels map[string]string,
) bool

PvcHasLabels returns true if a PVC contains a given map of labels

func ReloadOperatorDeployment

func ReloadOperatorDeployment(env *TestingEnvironment, timeoutSeconds uint) error

ReloadOperatorDeployment finds and deletes the operator pod. Returns error if the new pod is not ready within a defined timeout

func Run

func Run(command string) (stdout string, stderr string, err error)

Run executes a command and prints the output when terminates with an error

func RunQueryFromPod

func RunQueryFromPod(
	connectingPod *corev1.Pod,
	host string,
	dbname string,
	user string,
	password string,
	query string,
	env *TestingEnvironment,
) (string, string, error)

RunQueryFromPod executes a query from a pod to a host

func RunRetry

func RunRetry(command string) (stdout string, stderr string, err error)

RunRetry executes a command with retry and prints the output when terminates with an error

func RunUnchecked

func RunUnchecked(command string) (stdout string, stderr string, err error)

RunUnchecked executes a command and process the information

func RunUncheckedRetry

func RunUncheckedRetry(command string) (stdout string, stderr string, err error)

RunUncheckedRetry executes a command and process the information with retry

func SetSnapshotNameAsEnv added in v1.21.0

func SetSnapshotNameAsEnv(
	snapshotList *volumesnapshot.VolumeSnapshotList,
	backup *apiv1.Backup,
	envVars EnvVarsForSnapshots,
) error

SetSnapshotNameAsEnv sets the names of a PG_DATA, a PG_WAL and a list of PG_TABLESPACE snapshots from a given snapshotList as env variables

func TestDirectoryEmpty

func TestDirectoryEmpty(namespace, podName, directoryPath string) bool

TestDirectoryEmpty tests if a directory `directoryPath` exists on pod `podName` in namespace `namespace`

func TestFileExist

func TestFileExist(namespace, podName, directoryPath, fileName string) bool

TestFileExist tests if a file specified with `fileName` exist under directory `directoryPath`, on pod `podName` in namespace `namespace`

func Timeouts added in v1.18.5

func Timeouts() (map[Timeout]int, error)

Timeouts returns the map of timeouts, where each event gets the timeout specificed in the `TEST_TIMEOUTS` environment variable, or if not specified, takes the default value

func ToggleHAReplicationSlots added in v1.23.0

func ToggleHAReplicationSlots(namespace, clusterName string, enable bool, env *TestingEnvironment) error

ToggleHAReplicationSlots sets the HA Replication Slot feature on/off depending on `enable`

func ToggleSynchronizeReplicationSlots added in v1.23.0

func ToggleSynchronizeReplicationSlots(namespace, clusterName string, enable bool, env *TestingEnvironment) error

ToggleSynchronizeReplicationSlots sets the Synchronize Replication Slot feature on/off depending on `enable`

func UpdateCNPGsMutatingWebhookConf

func UpdateCNPGsMutatingWebhookConf(env *TestingEnvironment,
	wh *admissionregistrationv1.MutatingWebhookConfiguration,
) error

UpdateCNPGsMutatingWebhookConf update MutatingWebhookConfiguration object

func UpdateCNPGsValidatingWebhookConf

func UpdateCNPGsValidatingWebhookConf(env *TestingEnvironment,
	wh *admissionregistrationv1.ValidatingWebhookConfiguration,
) error

UpdateCNPGsValidatingWebhookConf update the ValidatingWebhook object

func UpgradeSubscription added in v1.21.3

func UpgradeSubscription(env *TestingEnvironment, channel string) error

UpgradeSubscription patch an unstructured subscription object with target channel

Types

type AzureConfiguration added in v1.20.5

type AzureConfiguration struct {
	StorageAccount string
	StorageKey     string
	BlobContainer  string
}

AzureConfiguration contains the variables needed to run the azure test environment correctly

type ContainerLocator added in v1.18.5

type ContainerLocator struct {
	Namespace     string
	PodName       string
	ContainerName string
}

ContainerLocator contains the necessary data to find a container on a pod

type DatabaseName added in v1.18.5

type DatabaseName string

DatabaseName is a special type for the database argument in an Exec call

type EnvVarsForSnapshots added in v1.22.0

type EnvVarsForSnapshots struct {
	DataSnapshot             string
	WalSnapshot              string
	TablespaceSnapshotPrefix string
}

EnvVarsForSnapshots represents the environment variables to use to track snapshots and apply them in test fixture templates

type FencingMethod

type FencingMethod string

FencingMethod will be one of the supported ways to trigger an instance fencing

const (
	// UsingAnnotation it is a keyword to use while fencing on/off the instances using annotation method
	UsingAnnotation FencingMethod = "annotation"
	// UsingPlugin it is a keyword to use while fencing on/off the instances using plugin method
	UsingPlugin FencingMethod = "plugin"
)

type HibernationMethod added in v1.22.0

type HibernationMethod string

HibernationMethod will be one of the supported ways to trigger an instance fencing

const (
	// HibernateDeclaratively it is a keyword to use while fencing on/off the instances using annotation method
	HibernateDeclaratively HibernationMethod = "annotation"
	// HibernateImperatively it is a keyword to use while fencing on/off the instances using plugin method
	HibernateImperatively HibernationMethod = "plugin"
)

type MinioEnv added in v1.21.5

type MinioEnv struct {
	Client       *corev1.Pod
	CaPair       *certs.KeyPair
	CaSecretObj  corev1.Secret
	ServiceName  string
	Namespace    string
	CaSecretName string
	TLSSecret    string
	Timeout      uint
}

MinioEnv contains all the information related or required by MinIO deployment and used by the functions on every test

func (*MinioEnv) CreateCaSecret added in v1.21.5

func (m *MinioEnv) CreateCaSecret(env *TestingEnvironment, namespace string) error

CreateCaSecret creates the certificates required to authenticate against the the MinIO service

type MinioSetup

type MinioSetup struct {
	PersistentVolumeClaim corev1.PersistentVolumeClaim
	Deployment            appsv1.Deployment
	Service               corev1.Service
}

MinioSetup contains the resources needed for a working minio server deployment: a PersistentVolumeClaim, a Deployment and a Service

func MinioDefaultSetup

func MinioDefaultSetup(namespace string) (MinioSetup, error)

MinioDefaultSetup returns the definition for the default minio setup

func MinioSSLSetup

func MinioSSLSetup(namespace string) (MinioSetup, error)

MinioSSLSetup returns the definition for a minio setup using SSL

type PodLocator added in v1.18.5

type PodLocator struct {
	Namespace string
	PodName   string
}

PodLocator contains the necessary data to find a pod

type SSLMode added in v1.18.1

type SSLMode string

SSLMode while using psql connection with `sslmode`

const (
	// Prefer for `prefer` sslmode.
	Prefer SSLMode = "prefer"
	// Require for `require` sslmode.
	Require SSLMode = "require"
)

type TagSet

type TagSet struct {
	Tags map[string]string `json:"tagset"`
}

TagSet will contain the `tagset` section of the minio output command

func GetFileTagsOnMinio

func GetFileTagsOnMinio(minioEnv *MinioEnv, path string) (TagSet, error)

GetFileTagsOnMinio will use the minioClient to retrieve the tags in a specified path

type TestEnvVendor added in v1.18.5

type TestEnvVendor string

TestEnvVendor is the type of cloud vendor the e2e test is running on

func TestCloudVendor added in v1.18.5

func TestCloudVendor() (*TestEnvVendor, error)

TestCloudVendor creates the environment for testing

type TestingEnvironment

type TestingEnvironment struct {
	RestClientConfig   *rest.Config
	Client             client.Client
	Interface          kubernetes.Interface
	APIExtensionClient apiextensionsclientset.Interface
	Ctx                context.Context
	Scheme             *runtime.Scheme
	PreserveNamespaces []string
	Log                logr.Logger
	PostgresVersion    int

	AzureConfiguration AzureConfiguration
	// contains filtered or unexported fields
}

TestingEnvironment struct for operator testing

func NewTestingEnvironment

func NewTestingEnvironment() (*TestingEnvironment, error)

NewTestingEnvironment creates the environment for testing

func (TestingEnvironment) CreateNamespace

func (env TestingEnvironment) CreateNamespace(name string, opts ...client.CreateOption) error

CreateNamespace creates a namespace. Prefer CreateUniqueNamespace instead, unless you need a specific namespace name. If so, make sure there is no collision potential

func (TestingEnvironment) CreateUniqueNamespace added in v1.18.5

func (env TestingEnvironment) CreateUniqueNamespace(
	namespacePrefix string,
	opts ...client.CreateOption,
) (string, error)

CreateUniqueNamespace creates a namespace by using the passed prefix. Return the namespace name and any errors encountered.

func (TestingEnvironment) DeleteNamespace

func (env TestingEnvironment) DeleteNamespace(name string, opts ...client.DeleteOption) error

DeleteNamespace deletes a namespace if existent

func (TestingEnvironment) DeleteNamespaceAndWait

func (env TestingEnvironment) DeleteNamespaceAndWait(name string, timeoutSeconds int) error

DeleteNamespaceAndWait deletes a namespace if existent and returns when deletion is completed

func (TestingEnvironment) DeletePod

func (env TestingEnvironment) DeletePod(namespace string, name string, opts ...client.DeleteOption) error

DeletePod deletes a pod if existent

func (TestingEnvironment) DescribeKubernetesNodes added in v1.18.0

func (env TestingEnvironment) DescribeKubernetesNodes() (string, error)

DescribeKubernetesNodes prints the `describe node` for each node in the kubernetes cluster

func (TestingEnvironment) DumpNamespaceObjects added in v1.15.2

func (env TestingEnvironment) DumpNamespaceObjects(namespace string, filename string)

DumpNamespaceObjects logs the clusters, pods, pvcs etc. found in a namespace as JSON sections

func (TestingEnvironment) DumpOperator

func (env TestingEnvironment) DumpOperator(namespace string, filename string)

DumpOperator logs the JSON for the deployment in an operator namespace, its pods and endpoints

func (TestingEnvironment) DumpOperatorLogs added in v1.15.5

func (env TestingEnvironment) DumpOperatorLogs(getPrevious bool, requestedLineLength int) ([]string, error)

DumpOperatorLogs dumps the operator logs to a file, and returns the log lines as a slice.

func (TestingEnvironment) DumpPoolerResourcesInfo

func (env TestingEnvironment) DumpPoolerResourcesInfo(namespace, currentTestName string)

DumpPoolerResourcesInfo logs the JSON for the pooler resources in a namespace, its pods, Deployment, services and endpoints

func (TestingEnvironment) EnsureNamespace added in v1.20.6

func (env TestingEnvironment) EnsureNamespace(namespace string) error

EnsureNamespace checks for the presence of a namespace, and if it does not exist, creates it

func (TestingEnvironment) EventuallyExecCommand

func (env TestingEnvironment) EventuallyExecCommand(
	ctx context.Context,
	pod corev1.Pod,
	containerName string,
	timeout *time.Duration,
	command ...string,
) (string, string, error)

EventuallyExecCommand wraps the utils.ExecCommand pre-setting values constant during tests, wrapping it with an Eventually clause

func (TestingEnvironment) ExecCommand

func (env TestingEnvironment) ExecCommand(
	ctx context.Context,
	pod corev1.Pod,
	containerName string,
	timeout *time.Duration,
	command ...string,
) (string, string, error)

ExecCommand wraps the utils.ExecCommand pre-setting values constant during tests

func (TestingEnvironment) ExecCommandInContainer added in v1.18.5

func (env TestingEnvironment) ExecCommandInContainer(
	container ContainerLocator,
	timeout *time.Duration,
	command ...string,
) (string, string, error)

ExecCommandInContainer executes commands in a given instance pod, in the postgres container

func (TestingEnvironment) ExecCommandInInstancePod added in v1.18.5

func (env TestingEnvironment) ExecCommandInInstancePod(
	podLocator PodLocator,
	timeout *time.Duration,
	command ...string,
) (string, string, error)

ExecCommandInInstancePod executes commands in a given instance pod, in the postgres container

func (TestingEnvironment) ExecCommandWithPsqlClient added in v1.18.1

func (env TestingEnvironment) ExecCommandWithPsqlClient(
	namespace,
	clusterName string,
	pod *corev1.Pod,
	secretSuffix string,
	dbname string,
	query string,
) (string, string, error)

ExecCommandWithPsqlClient wraps the utils.ExecCommand pre-setting values and run query on psql client pod with rw service as host.

func (TestingEnvironment) ExecQueryInInstancePod added in v1.18.5

func (env TestingEnvironment) ExecQueryInInstancePod(
	podLocator PodLocator,
	dbname DatabaseName,
	query string,
) (string, string, error)

ExecQueryInInstancePod executes a query in an instance pod, by connecting to the pod and the postgres container, and using a local connection with the postgres user

func (TestingEnvironment) GetBackupList added in v1.15.3

func (env TestingEnvironment) GetBackupList(namespace string) (*apiv1.BackupList, error)

GetBackupList gathers the current list of backup in namespace

func (TestingEnvironment) GetCNPGsMutatingWebhookConf

func (env TestingEnvironment) GetCNPGsMutatingWebhookConf() (
	*admissionregistrationv1.MutatingWebhookConfiguration, error,
)

GetCNPGsMutatingWebhookConf get the MutatingWebhook linked to the operator

func (TestingEnvironment) GetCluster

func (env TestingEnvironment) GetCluster(namespace string, name string) (*apiv1.Cluster, error)

GetCluster gets a cluster given name and namespace

func (TestingEnvironment) GetClusterPodList

func (env TestingEnvironment) GetClusterPodList(namespace string, clusterName string) (*corev1.PodList, error)

GetClusterPodList gathers the current list of instance pods for a cluster in a namespace

func (TestingEnvironment) GetClusterPrimary

func (env TestingEnvironment) GetClusterPrimary(namespace string, clusterName string) (*corev1.Pod, error)

GetClusterPrimary gets the primary pod of a cluster Once the release of 1.20.3 and 1.19.5 places the new role label into the public images, we should use utils.ClusterInstanceRoleLabelName instead of "role"

func (TestingEnvironment) GetClusterReplicas added in v1.15.5

func (env TestingEnvironment) GetClusterReplicas(namespace string, clusterName string) (*corev1.PodList, error)

GetClusterReplicas gets a slice containing all the replica pods of a cluster Deprecated: Use utils.ClusterInstanceRoleLabelName instead of "role"

func (TestingEnvironment) GetEventList

func (env TestingEnvironment) GetEventList(namespace string) (*eventsv1.EventList, error)

GetEventList gathers the current list of events in a namespace

func (TestingEnvironment) GetJob added in v1.21.0

func (env TestingEnvironment) GetJob(namespace, jobName string) (*batchv1.Job, error)

GetJob gets a Job by namespace and name

func (TestingEnvironment) GetJobList

func (env TestingEnvironment) GetJobList(namespace string) (*batchv1.JobList, error)

GetJobList gathers the current list of jobs in a namespace

func (TestingEnvironment) GetNodeList

func (env TestingEnvironment) GetNodeList() (*corev1.NodeList, error)

GetNodeList gathers the current list of Nodes

func (TestingEnvironment) GetOperatorDeployment

func (env TestingEnvironment) GetOperatorDeployment() (appsv1.Deployment, error)

GetOperatorDeployment returns the operator Deployment if there is a single one running, error otherwise

func (TestingEnvironment) GetOperatorNamespaceName

func (env TestingEnvironment) GetOperatorNamespaceName() (string, error)

GetOperatorNamespaceName returns the namespace the operator Deployment is running in

func (TestingEnvironment) GetOperatorPod

func (env TestingEnvironment) GetOperatorPod() (corev1.Pod, error)

GetOperatorPod returns the operator pod if there is a single one running, error otherwise

func (TestingEnvironment) GetPVCList

func (env TestingEnvironment) GetPVCList(namespace string) (*corev1.PersistentVolumeClaimList, error)

GetPVCList gathers the current list of PVCs in a namespace

func (TestingEnvironment) GetPod added in v1.18.5

func (env TestingEnvironment) GetPod(namespace, podName string) (*corev1.Pod, error)

GetPod gets a pod by namespace and name

func (TestingEnvironment) GetPodList

func (env TestingEnvironment) GetPodList(namespace string) (*corev1.PodList, error)

GetPodList gathers the current list of pods in a namespace

func (TestingEnvironment) GetPodLogs

func (env TestingEnvironment) GetPodLogs(namespace string, podName string) (string, error)

GetPodLogs gathers pod logs

func (TestingEnvironment) GetPoolerList

func (env TestingEnvironment) GetPoolerList(namespace string) (*apiv1.PoolerList, error)

GetPoolerList gathers the current list of poolers in a namespace

func (TestingEnvironment) GetResourceNameFromYAML

func (env TestingEnvironment) GetResourceNameFromYAML(path string) (string, error)

GetResourceNameFromYAML returns the name of a resource in a YAML file

func (TestingEnvironment) GetResourceNamespaceFromYAML

func (env TestingEnvironment) GetResourceNamespaceFromYAML(path string) (string, error)

GetResourceNamespaceFromYAML returns the namespace of a resource in a YAML file

func (TestingEnvironment) GetResourceNamespacedNameFromYAML

func (env TestingEnvironment) GetResourceNamespacedNameFromYAML(path string) (types.NamespacedName, error)

GetResourceNamespacedNameFromYAML returns the NamespacedName representing a resource in a YAML file

func (TestingEnvironment) GetScheduledBackupList added in v1.15.3

func (env TestingEnvironment) GetScheduledBackupList(namespace string) (*apiv1.ScheduledBackupList, error)

GetScheduledBackupList gathers the current list of scheduledBackup in namespace

func (TestingEnvironment) GetServiceAccountList

func (env TestingEnvironment) GetServiceAccountList(namespace string) (*corev1.ServiceAccountList, error)

GetServiceAccountList gathers the current list of jobs in a namespace

func (TestingEnvironment) GetSnapshotList added in v1.20.3

func (env TestingEnvironment) GetSnapshotList(namespace string) (*storagesnapshotv1.VolumeSnapshotList, error)

GetSnapshotList gathers the current list of VolumeSnapshots in a namespace

func (TestingEnvironment) GetVolumeSnapshot added in v1.21.0

func (env TestingEnvironment) GetVolumeSnapshot(
	namespace,
	name string,
) (*volumesnapshot.VolumeSnapshot, error)

GetVolumeSnapshot gets a VolumeSnapshot given name and namespace

func (TestingEnvironment) IsOperatorReady

func (env TestingEnvironment) IsOperatorReady() (bool, error)

IsOperatorReady ensures that the operator will be ready.

func (TestingEnvironment) ScaleClusterSize added in v1.15.5

func (env TestingEnvironment) ScaleClusterSize(namespace, clusterName string, newClusterSize int) error

ScaleClusterSize scales a cluster to the requested size

func (TestingEnvironment) TailClusterLogs added in v1.19.4

func (env TestingEnvironment) TailClusterLogs(
	cluster *apiv1.Cluster,
	writer io.Writer,
	parseTimestamps bool,
) error

TailClusterLogs streams the cluster pod logs to a single output io.Writer, starting from the current time, and watching for any new pods, and any new logs, until the context is cancelled or there are no pods left.

If `parseTimestamps` is true, the log line will have the timestamp in human-readable prepended. NOTE: this will make log-lines NON-JSON

type Timeout added in v1.18.5

type Timeout string

Timeout represents an event whose time we want to limit in the test suite

const (
	Failover                  Timeout = "failover"
	NamespaceCreation         Timeout = "namespaceCreation"
	ClusterIsReady            Timeout = "clusterIsReady"
	ClusterIsReadyQuick       Timeout = "clusterIsReadyQuick"
	ClusterIsReadySlow        Timeout = "clusterIsReadySlow"
	NewPrimaryAfterSwitchover Timeout = "newPrimaryAfterSwitchover"
	NewPrimaryAfterFailover   Timeout = "newPrimaryAfterFailover"
	NewTargetOnFailover       Timeout = "newTargetOnFailover"
	PodRollout                Timeout = "podRollout"
	OperatorIsReady           Timeout = "operatorIsReady"
	LargeObject               Timeout = "largeObject"
	WalsInMinio               Timeout = "walsInMinio"
	MinioInstallation         Timeout = "minioInstallation"
	BackupIsReady             Timeout = "backupIsReady"
	DrainNode                 Timeout = "drainNode"
	VolumeSnapshotIsReady     Timeout = "volumeSnapshotIsReady"
	Short                     Timeout = "short"
)

the events we're setting timeouts for NOTE: the text representation will be used as the fields in the JSON representation of the timeout object passed to the ginkgo command as an environment variable

Directories

Path Synopsis
Package nodes contains the helper methods/functions for nodes
Package nodes contains the helper methods/functions for nodes

Jump to

Keyboard shortcuts

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