|
| 1 | +apiVersion: kuttl.dev/v1beta1 |
| 2 | +kind: TestStep |
| 3 | +timeout: 60 |
| 4 | +commands: |
| 5 | + - script: |- |
| 6 | + set -o errexit |
| 7 | + set -o xtrace |
| 8 | +
|
| 9 | + source ../../functions |
| 10 | +
|
| 11 | + LEADER=$(kubectl get pods -n "${NAMESPACE}" \ |
| 12 | + -l postgres-operator.crunchydata.com/role=primary \ |
| 13 | + -o jsonpath='{.items[0].metadata.name}') |
| 14 | +
|
| 15 | + echo "Current leader: $LEADER" |
| 16 | +
|
| 17 | + REPLICA=$(kubectl get pods -n "${NAMESPACE}" \ |
| 18 | + -l postgres-operator.crunchydata.com/role=replica \ |
| 19 | + -o jsonpath='{.items[0].metadata.name}') |
| 20 | +
|
| 21 | + echo "Replica to promote: $REPLICA" |
| 22 | +
|
| 23 | + kubectl get pods -n "${NAMESPACE}" \ |
| 24 | + -l postgres-operator.crunchydata.com/role=pgbouncer \ |
| 25 | + -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' \ |
| 26 | + > /tmp/pgbouncer-pods-before.txt |
| 27 | +
|
| 28 | + echo "PgBouncer pods before switchover:" |
| 29 | + cat /tmp/pgbouncer-pods-before.txt |
| 30 | +
|
| 31 | + kubectl exec "$LEADER" -c database -n "${NAMESPACE}" -- \ |
| 32 | + patronictl switchover \ |
| 33 | + --leader "$LEADER" \ |
| 34 | + --candidate "$REPLICA" \ |
| 35 | + --force |
| 36 | +
|
| 37 | + echo "Switchover triggered successfully" |
| 38 | +
|
| 39 | + # Wait for PgBouncer pods to be recreated (they should be deleted and recreated) |
| 40 | + sleep 15 |
| 41 | +
|
| 42 | + kubectl get pods -n "${NAMESPACE}" \ |
| 43 | + -l postgres-operator.crunchydata.com/role=pgbouncer \ |
| 44 | + -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' \ |
| 45 | + > /tmp/pgbouncer-pods-after.txt |
| 46 | +
|
| 47 | + echo "PgBouncer pods after switchover:" |
| 48 | + cat /tmp/pgbouncer-pods-after.txt |
| 49 | +
|
| 50 | + if diff /tmp/pgbouncer-pods-before.txt /tmp/pgbouncer-pods-after.txt > /dev/null; then |
| 51 | + echo "ERROR: PgBouncer pods were NOT recreated after failover!" |
| 52 | + exit 1 |
| 53 | + else |
| 54 | + echo "SUCCESS: PgBouncer pods were recreated after failover" |
| 55 | + fi |
0 commit comments