2024-04-02 15:21:21 +00:00
|
|
|
#!/usr/bin/env bash
|
2024-04-02 16:23:10 +00:00
|
|
|
|
2024-04-02 15:21:21 +00:00
|
|
|
if [[ $1 == "--config" ]] ; then
|
|
|
|
cat <<EOF
|
|
|
|
configVersion: v1
|
|
|
|
kubernetes:
|
2024-04-02 16:23:10 +00:00
|
|
|
- name: Watch bootstrap configmaps getting removed
|
2024-04-02 16:18:41 +00:00
|
|
|
apiVersion: v1
|
|
|
|
kind: ConfigMap
|
2024-04-03 07:50:45 +00:00
|
|
|
executeHookOnSynchronization: false
|
2024-04-02 16:59:16 +00:00
|
|
|
executeHookOnEvent: ["Modified"]
|
|
|
|
jqFilter: ".metadata.deletionTimestamp"
|
2024-04-02 16:18:41 +00:00
|
|
|
labelSelector:
|
|
|
|
matchExpressions:
|
|
|
|
- key: "component"
|
|
|
|
operator: "In"
|
|
|
|
values: ["bootstrap"]
|
2024-04-02 15:21:21 +00:00
|
|
|
EOF
|
|
|
|
else
|
2024-04-03 09:35:54 +00:00
|
|
|
export $(jq -r .[0].object.data.vars $BINDING_CONTEXT_PATH)
|
|
|
|
echo "running the ${SP_PROVIDER}-cleanup hook"
|
2024-04-03 07:50:45 +00:00
|
|
|
|
2024-04-03 09:35:54 +00:00
|
|
|
if ! [ -f /tpls/${SP_PROVIDER}-cleanup.yaml ]; then
|
|
|
|
echo "template not found for ${SP_PROVIDER}-cleanup"
|
2024-04-02 16:18:41 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2024-04-03 07:50:45 +00:00
|
|
|
|
2024-04-03 07:56:47 +00:00
|
|
|
export SP_CUSTOMER_ID=$(jq -r .[0].object.metadata.namespace $BINDING_CONTEXT_PATH)
|
|
|
|
export SP_ENVIRONMENT=$(jq -r .[0].object.metadata.name $BINDING_CONTEXT_PATH)
|
2024-04-03 07:50:45 +00:00
|
|
|
echo "removing the ${SP_ENVIRONMENT} owned by ${SP_CUSTOMER_ID}"
|
|
|
|
|
2024-04-03 09:35:54 +00:00
|
|
|
envsubst < /tpls/${SP_PROVIDER}-cleanup.yaml | kubectl create -f -
|
2024-04-03 07:50:45 +00:00
|
|
|
|
|
|
|
# -- Removing the finalizer
|
2024-04-02 16:39:10 +00:00
|
|
|
kubectl patch configmap -n ${SP_CUSTOMER_ID} ${SP_ENVIRONMENT} \
|
|
|
|
-p '{"metadata":{"finalizers":null}}' --type=merge
|
2024-04-02 15:21:21 +00:00
|
|
|
fi
|
|
|
|
|