softplayer-controller/hooks/uninstall-application.sh

42 lines
1.4 KiB
Bash
Raw Permalink Normal View History

2024-05-13 11:33:36 +00:00
#!/usr/bin/env bash
# ---------------------------------------------------------------------
# This script should bootstrap a new environment, or update
# existing ones
# Get the configmap name and namespace to prepare the
# ---------------------------------------------------------------------
if [[ $1 == "--config" ]] ; then
cat <<EOF
configVersion: v1
kubernetes:
- name: Watch application configmaps getting created
apiVersion: v1
kind: Secret
executeHookOnSynchronization: false
executeHookOnEvent: ["Modified"]
jqFilter: ".metadata.deletionTimestamp"
labelSelector:
matchExpressions:
- key: "component"
operator: "In"
values: ["install"]
EOF
else
export $(jq -r .[0].object.data.vars $BINDING_CONTEXT_PATH)
export NAMESPACE=$(jq -r .[0].object.metadata.namespace $BINDING_CONTEXT_PATH)
export NAME=$(jq -r .[0].object.metadata.name $BINDING_CONTEXT_PATH)
export SP_APPLICATION=$(jq -r '.[0].object.data."values.yaml"' $BINDING_CONTEXT_PATH | base64 -d | yq '.helm.release')
export SP_ENVIRONMENT_ID=$(jq -r .[0].object.metadata.labels.environment $BINDING_CONTEXT_PATH)
flux delete source helm $SP_APPLICATION \
--namespace=$NAMESPACE \
flux delete helmrelease $SP_APPLICATION \
--namespace=$NAMESPACE
kubectl patch configmap -n ${SP_CUSTOMER_ID} ${SP_ENVIRONMENT} \
-p '{"metadata":{"finalizers":null}}' --type=merge
fi