From a2a18902153f4bc520d5875d6439e631dffb0e25 Mon Sep 17 00:00:00 2001 From: Om Mishra <32200996+mishraomp@users.noreply.github.com> Date: Fri, 25 Oct 2024 13:46:51 -0700 Subject: [PATCH] fix: crunchydb remove user and db when pr is closed. (#2142) --- .github/workflows/pr-close.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/pr-close.yml b/.github/workflows/pr-close.yml index 313f5007c..1b96fadf3 100644 --- a/.github/workflows/pr-close.yml +++ b/.github/workflows/pr-close.yml @@ -52,5 +52,15 @@ jobs: PATCH_JSON=$(jq -n --argjson users "${UPDATED_USERS}" '{"spec": {"users": $users}}') oc patch PostgresCluster/postgres-crunchy --type=merge -p "${PATCH_JSON}" + + # get primary crunchy pod and remove the role and db + CRUNCHY_PG_PRIMARY_POD_NAME=$(oc get pods -l postgres-operator.crunchydata.com/role=master -o json | jq -r '.items[0].metadata.name') + + echo "${CRUNCHY_PG_PRIMARY_POD_NAME}" + + oc exec "${CRUNCHY_PG_PRIMARY_POD_NAME}" -- psql -c "DROP DATABASE \"app-${{ github.event.number }}\" --cascade" + oc exec "${CRUNCHY_PG_PRIMARY_POD_NAME}" -- psql -c "DROP ROLE \"app-${{ github.event.number }}\" --cascade" + echo 'database and role deleted' + exit 0