Skip to content

Commit

Permalink
K8SPG-645 turn on sidecar containers for pgbouncer (#968)
Browse files Browse the repository at this point in the history
* K8SPG-645 turn on sidecar conteiners for pgbouncer

* Update cmd/postgres-operator/main.go

Co-authored-by: Andrii Dema <[email protected]>

* add sidecar test

* update test

---------

Co-authored-by: Andrii Dema <[email protected]>
Co-authored-by: Viacheslav Sarzhan <[email protected]>
  • Loading branch information
3 people authored Dec 11, 2024
1 parent 453b7e5 commit 76b98e6
Show file tree
Hide file tree
Showing 8 changed files with 265 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/postgres-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions e2e-tests/run-pr.csv
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pitr
scaling
scheduled-backup
self-healing
sidecars
start-from-backup
tablespaces
telemetry-transfer
Expand Down
1 change: 1 addition & 0 deletions e2e-tests/run-release.csv
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pitr
scaling
scheduled-backup
self-healing
sidecars
start-from-backup
tablespaces
telemetry-transfer
Expand Down
24 changes: 24 additions & 0 deletions e2e-tests/tests/sidecars/00-assert.yaml
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions e2e-tests/tests/sidecars/00-deploy-operator.yaml
Original file line number Diff line number Diff line change
@@ -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
185 changes: 185 additions & 0 deletions e2e-tests/tests/sidecars/01-assert.yaml
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions e2e-tests/tests/sidecars/01-create-cluster.yaml
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions e2e-tests/tests/sidecars/99-remove-cluster-gracefully.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 76b98e6

Please sign in to comment.