diff --git a/cmd/postgres-operator/main.go b/cmd/postgres-operator/main.go index eba40e69a7..50faf7f2ad 100644 --- a/cmd/postgres-operator/main.go +++ b/cmd/postgres-operator/main.go @@ -79,6 +79,7 @@ func main() { features := feature.NewGate() err = features.SetFromMap(map[string]bool{ string(feature.InstanceSidecars): true, // needed for PMM + string(feature.PGBouncerSidecars): true, // K8SPG-645 string(feature.TablespaceVolumes): true, }) assertNoError(err) diff --git a/e2e-tests/run-pr.csv b/e2e-tests/run-pr.csv index 1a005a4e37..5980607e79 100644 --- a/e2e-tests/run-pr.csv +++ b/e2e-tests/run-pr.csv @@ -10,6 +10,7 @@ pitr scaling scheduled-backup self-healing +sidecars start-from-backup tablespaces telemetry-transfer diff --git a/e2e-tests/run-release.csv b/e2e-tests/run-release.csv index 639f97fc77..412a9c1daa 100644 --- a/e2e-tests/run-release.csv +++ b/e2e-tests/run-release.csv @@ -12,6 +12,7 @@ pitr scaling scheduled-backup self-healing +sidecars start-from-backup tablespaces telemetry-transfer diff --git a/e2e-tests/tests/sidecars/00-assert.yaml b/e2e-tests/tests/sidecars/00-assert.yaml new file mode 100644 index 0000000000..ae5a062d84 --- /dev/null +++ b/e2e-tests/tests/sidecars/00-assert.yaml @@ -0,0 +1,24 @@ +apiVersion: kuttl.dev/v1beta1 +kind: TestAssert +timeout: 120 +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: perconapgclusters.pgv2.percona.com +spec: + group: pgv2.percona.com + names: + kind: PerconaPGCluster + listKind: PerconaPGClusterList + plural: perconapgclusters + singular: perconapgcluster + scope: Namespaced +--- +apiVersion: kuttl.dev/v1beta1 +kind: TestAssert +metadata: + name: check-operator-deploy-status +timeout: 120 +commands: + - script: kubectl assert exist-enhanced deployment percona-postgresql-operator -n ${OPERATOR_NS:-$NAMESPACE} --field-selector status.readyReplicas=1 diff --git a/e2e-tests/tests/sidecars/00-deploy-operator.yaml b/e2e-tests/tests/sidecars/00-deploy-operator.yaml new file mode 100644 index 0000000000..544ecbeb95 --- /dev/null +++ b/e2e-tests/tests/sidecars/00-deploy-operator.yaml @@ -0,0 +1,14 @@ +apiVersion: kuttl.dev/v1beta1 +kind: TestStep +timeout: 10 +commands: + - script: |- + set -o errexit + set -o xtrace + + source ../../functions + init_temp_dir # do this only in the first TestStep + + deploy_operator + deploy_client + diff --git a/e2e-tests/tests/sidecars/01-assert.yaml b/e2e-tests/tests/sidecars/01-assert.yaml new file mode 100644 index 0000000000..731258761f --- /dev/null +++ b/e2e-tests/tests/sidecars/01-assert.yaml @@ -0,0 +1,185 @@ +apiVersion: kuttl.dev/v1beta1 +kind: TestAssert +timeout: 180 +--- +kind: StatefulSet +apiVersion: apps/v1 +metadata: + name: sidecars-repo-host + labels: + postgres-operator.crunchydata.com/cluster: sidecars + postgres-operator.crunchydata.com/data: pgbackrest + postgres-operator.crunchydata.com/pgbackrest: '' + postgres-operator.crunchydata.com/pgbackrest-dedicated: '' + ownerReferences: + - apiVersion: postgres-operator.crunchydata.com/v1beta1 + kind: PostgresCluster + name: sidecars + controller: true + blockOwnerDeletion: true +status: + observedGeneration: 1 + replicas: 1 + readyReplicas: 1 + currentReplicas: 1 + updatedReplicas: 1 + collisionCount: 0 +--- +kind: StatefulSet +apiVersion: apps/v1 +metadata: + labels: + postgres-operator.crunchydata.com/cluster: sidecars + postgres-operator.crunchydata.com/data: postgres + postgres-operator.crunchydata.com/instance-set: instance1 + ownerReferences: + - apiVersion: postgres-operator.crunchydata.com/v1beta1 + kind: PostgresCluster + name: sidecars + controller: true + blockOwnerDeletion: true +status: + observedGeneration: 1 + replicas: 1 + readyReplicas: 1 + currentReplicas: 1 + updatedReplicas: 1 + collisionCount: 0 +--- +kind: Deployment +apiVersion: apps/v1 +metadata: + name: sidecars-pgbouncer + labels: + postgres-operator.crunchydata.com/cluster: sidecars + postgres-operator.crunchydata.com/role: pgbouncer + annotations: + deployment.kubernetes.io/revision: '1' + ownerReferences: + - apiVersion: postgres-operator.crunchydata.com/v1beta1 + kind: PostgresCluster + name: sidecars + controller: true + blockOwnerDeletion: true +status: + observedGeneration: 1 + replicas: 3 + updatedReplicas: 3 + readyReplicas: 3 +--- +kind: Job +apiVersion: batch/v1 +metadata: + labels: + postgres-operator.crunchydata.com/cluster: sidecars + postgres-operator.crunchydata.com/pgbackrest: '' + postgres-operator.crunchydata.com/pgbackrest-backup: replica-create + postgres-operator.crunchydata.com/pgbackrest-repo: repo1 + ownerReferences: + - apiVersion: pgv2.percona.com/v2 + kind: PerconaPGBackup + controller: true + blockOwnerDeletion: true +status: + succeeded: 1 +--- +apiVersion: postgres-operator.crunchydata.com/v1beta1 +kind: PostgresCluster +metadata: + name: sidecars + ownerReferences: + - apiVersion: pgv2.percona.com/v2 + kind: PerconaPGCluster + name: sidecars + controller: true + blockOwnerDeletion: true + finalizers: + - postgres-operator.crunchydata.com/finalizer +status: + instances: + - name: instance1 + readyReplicas: 3 + replicas: 3 + updatedReplicas: 3 + observedGeneration: 1 + pgbackrest: + repoHost: + apiVersion: apps/v1 + kind: StatefulSet + ready: true + repos: + - bound: true + name: repo1 + replicaCreateBackupComplete: true + stanzaCreated: true + proxy: + pgBouncer: + readyReplicas: 3 + replicas: 3 +--- +apiVersion: pgv2.percona.com/v2 +kind: PerconaPGCluster +metadata: + labels: + e2e: sidecars + name: sidecars +spec: + instances: + - affinity: + podAntiAffinity: + preferredDuringSchedulingIgnoredDuringExecution: + - podAffinityTerm: + labelSelector: + matchLabels: + postgres-operator.crunchydata.com/data: postgres + topologyKey: kubernetes.io/hostname + weight: 1 + dataVolumeClaimSpec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi + name: instance1 + replicas: 3 + sidecars: + - command: + - sleep + - 30d + image: busybox + name: sidecar1 + - command: + - sleep + - 30d + image: busybox + name: sidecar2 + proxy: + pgBouncer: + affinity: + podAntiAffinity: + preferredDuringSchedulingIgnoredDuringExecution: + - podAffinityTerm: + labelSelector: + matchLabels: + postgres-operator.crunchydata.com/role: pgbouncer + topologyKey: kubernetes.io/hostname + weight: 1 + replicas: 3 + sidecars: + - command: + - sleep + - 30d + image: busybox + name: sidecar1 +status: + pgbouncer: + ready: 3 + size: 3 + postgres: + instances: + - name: instance1 + ready: 3 + size: 3 + ready: 3 + size: 3 + state: ready diff --git a/e2e-tests/tests/sidecars/01-create-cluster.yaml b/e2e-tests/tests/sidecars/01-create-cluster.yaml new file mode 100644 index 0000000000..9c0ef9187f --- /dev/null +++ b/e2e-tests/tests/sidecars/01-create-cluster.yaml @@ -0,0 +1,18 @@ +apiVersion: kuttl.dev/v1beta1 +kind: TestStep +timeout: 20 +commands: + - script: |- + set -o errexit + set -o xtrace + + source ../../functions + + get_cr \ + | yq eval '.spec.instances[0].sidecars = [{"name": "sidecar1", "image": "busybox", "command": ["sleep", "30d"]}]' - \ + | yq eval '.spec.instances[0].sidecars += [{"name": "sidecar2", "image": "busybox", "command": ["sleep", "30d"]}]' - \ + | yq eval '.spec.proxy.pgBouncer.sidecars = [{"name": "sidecar1", "image": "busybox", "command": ["sleep", "30d"]}]' - \ + | kubectl -n "${NAMESPACE}" apply -f - + timeout: 30 + + diff --git a/e2e-tests/tests/sidecars/99-remove-cluster-gracefully.yaml b/e2e-tests/tests/sidecars/99-remove-cluster-gracefully.yaml new file mode 100644 index 0000000000..59f953f9dc --- /dev/null +++ b/e2e-tests/tests/sidecars/99-remove-cluster-gracefully.yaml @@ -0,0 +1,21 @@ +apiVersion: kuttl.dev/v1beta1 +kind: TestStep +delete: + - apiVersion: pgv2.percona.com/v2 + kind: PerconaPGCluster + metadata: + name: self-healing + - apiVersion: postgres-operator.crunchydata.com/v1beta1 + kind: PostgresCluster + metadata: + name: self-healing +commands: + - script: |- + set -o errexit + set -o xtrace + + source ../../functions + + destroy_operator + timeout: 60 +