|
| 1 | +apiVersion: chainsaw.kyverno.io/v1alpha1 |
| 2 | +kind: StepTemplate |
| 3 | +metadata: |
| 4 | + name: change-parameters |
| 5 | +spec: |
| 6 | + try: |
| 7 | + - |
| 8 | + description: > |
| 9 | + Read the timestamp at which PostgreSQL last started |
| 10 | + script: |
| 11 | + outputs: [{ name: before, value: (trim_space($stdout)) }] |
| 12 | + content: | |
| 13 | + PRIMARY=$( |
| 14 | + kubectl get pod --namespace "${NAMESPACE}" \ |
| 15 | + --output name --selector ' |
| 16 | + postgres-operator.crunchydata.com/cluster=original, |
| 17 | + postgres-operator.crunchydata.com/role=master' |
| 18 | + ) |
| 19 | +
|
| 20 | + kubectl exec --namespace "${NAMESPACE}" "${PRIMARY}" \ |
| 21 | + -- psql -qAt --command 'SELECT pg_postmaster_start_time()' |
| 22 | +
|
| 23 | + - patch: |
| 24 | + resource: |
| 25 | + apiVersion: postgres-operator.crunchydata.com/v1beta1 |
| 26 | + kind: PostgresCluster |
| 27 | + metadata: |
| 28 | + name: original |
| 29 | + spec: |
| 30 | + config: |
| 31 | + parameters: ($parameters) |
| 32 | + |
| 33 | + - |
| 34 | + description: > |
| 35 | + Wait for Postgres to restart, signal the WAL archiver, then wait for WAL to archive |
| 36 | + script: |
| 37 | + timeout: 30s |
| 38 | + env: [{ name: BEFORE, value: ($before) }] |
| 39 | + content: | |
| 40 | + PRIMARY=$( |
| 41 | + kubectl get pod --namespace "${NAMESPACE}" \ |
| 42 | + --output name --selector ' |
| 43 | + postgres-operator.crunchydata.com/cluster=original, |
| 44 | + postgres-operator.crunchydata.com/role=master' |
| 45 | + ) |
| 46 | +
|
| 47 | + while true; do |
| 48 | + START=$( |
| 49 | + kubectl exec --namespace "${NAMESPACE}" "${PRIMARY}" \ |
| 50 | + -- psql -qAt --command 'SELECT pg_postmaster_start_time()' |
| 51 | + ) |
| 52 | + if [ "${START}" ] && [ "${START}" != "${BEFORE}" ]; then break; else sleep 1; fi |
| 53 | + done |
| 54 | + echo "${START} != ${BEFORE}" |
| 55 | +
|
| 56 | + kubectl exec --namespace "${NAMESPACE}" "${PRIMARY}" \ |
| 57 | + -- psql -qb --command "SELECT pg_stat_reset_shared('archiver')" --command 'SELECT pg_switch_wal()' |
| 58 | +
|
| 59 | + while [ 0 = "$( |
| 60 | + kubectl exec --namespace "${NAMESPACE}" "${PRIMARY}" \ |
| 61 | + -- psql -qAt --command 'SELECT archived_count FROM pg_stat_archiver' |
| 62 | + )" ]; do sleep 1; done |
0 commit comments