softplayer-controller/hooks/down.sh

44 lines
1.3 KiB
Bash
Executable File

#!/usr/bin/env bash
if [[ $1 == "--config" ]] ; then
cat <<EOF
configVersion: v1
kubernetes:
- name: Watch bootstrap configmaps getting removed
apiVersion: v1
kind: ConfigMap
executeHookOnSynchronization: false
executeHookOnEvent: ["Modified"]
jqFilter: ".metadata.deletionTimestamp"
labelSelector:
matchExpressions:
- key: "component"
operator: "In"
values: ["bootstrap"]
EOF
else
export $(jq -r .[0].object.data.vars $BINDING_CONTEXT_PATH)
echo "running the ${SP_PROVIDER}-cleanup hook"
if ! [ -f /tpls/${SP_PROVIDER}-cleanup.yaml ]; then
echo "template not found for ${SP_PROVIDER}-cleanup"
exit 1
fi
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)
echo "removing the ${SP_ENVIRONMENT} owned by ${SP_CUSTOMER_ID}"
# -- Remove the pipelinerun, if not removed yet
kubectl delete pipelinerun -n "${SP_TEKTON_RUNTIME_NS}" \
-l softplayer.net/user-uuid="${SP_CUSTOMER_ID}" \
-l softplayer.net/env_name="${SP_ENVIRONMENT}" || true
envsubst < /tpls/${SP_PROVIDER}-cleanup.yaml | kubectl create -f -
# -- Removing the finalizer
kubectl patch configmap -n ${SP_CUSTOMER_ID} ${SP_ENVIRONMENT} \
-p '{"metadata":{"finalizers":null}}' --type=merge
fi