Add a cleanup script

This commit is contained in:
Nikolai Rodionov 2024-04-02 18:18:41 +02:00
parent 12516d82fb
commit d20f6904cb
Signed by: allanger
GPG Key ID: 0AA46A90E25592AD
2 changed files with 46 additions and 6 deletions

24
hooks/down.sh Normal file → Executable file
View File

@ -1,15 +1,27 @@
#!/usr/bin/env bash #!/usr/bin/env bash
if [[ $1 == "--config" ]] ; then if [[ $1 == "--config" ]] ; then
cat <<EOF cat <<EOF
configVersion: v1 configVersion: v1
kubernetes: kubernetes:
- apiVersion: v1 - name: Watch softplayer configmaps
kind: Pod apiVersion: v1
executeHookOnEvent: ["Added"] kind: ConfigMap
executeHookOnEvent: ["Deleted"]
labelSelector:
matchExpressions:
- key: "component"
operator: "In"
values: ["bootstrap"]
EOF EOF
else else
podName=$(jq -r .[0].object.metadata.name $BINDING_CONTEXT_PATH) PROVIDER=$(jq -r .[0].objects.[0].object.data.provider $BINDING_CONTEXT_PATH)
echo "Pod '${podName}' added" KUBERNETES=$(jq -r .[0].objects.[0].object.data.kubernetes $BINDING_CONTEXT_PATH)
if ! [ -f /tpls/${PROVIDER}-cleanup.yaml ]; then
echo "ERROR: template not found for ${PROVIDER}-cleanup"
exit 1
fi
export SP_CUSTOMER_ID=$(jq -r .[0].objects.[0].object.metadata.namespace $BINDING_CONTEXT_PATH)
export SP_ENVIRONMENT=$(jq -r .[0].objects.[0].object.metadata.name $BINDING_CONTEXT_PATH)
envsubst < /tpls/${PROVIDER}-cleanup.yaml | kubectl create -f -
fi fi

28
tpls/hetzner-cleanup.yaml Normal file
View File

@ -0,0 +1,28 @@
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
generateName: hetzner-cleanup
namespace: "${SP_TEKTON_RUNTIME_NS}"
spec:
params:
- name: namespace
value: "${SP_CUSTOMER_ID}"
- name: environment
value: "${SP_ENVIRONMENT}"
tasks:
- name: cleanup-hetzner-infra
retries: 3
taskRef:
resolver: cluster
params:
- name: kind
value: task
- name: name
value: cleanup-hetzner-infra
- name: namespace
value: tekton-pipelines
params:
- name: environment
value: $(params.environment)
- name: namespace
value: $(params.namespace)