Skip to content

Commit

Permalink
Add Job to ensure OLM operator ns finalizers complete
Browse files Browse the repository at this point in the history
Signed-off-by: Dom Del Nano <ddelnano@gmail.com>
  • Loading branch information
ddelnano committed Dec 10, 2024
1 parent 672e351 commit 1f120d5
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions k8s/operator/helm/templates/00_olm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,54 @@ spec:
targetNamespaces:
- {{ .Values.olmNamespace }}
{{- end}}
---
apiVersion: batch/v1
kind: Job
metadata:
name: csv-deleter
namespace: {{ .Values.olmNamespace }}
annotations:
"helm.sh/hook": pre-delete
"helm.sh/hook-delete-policy": hook-succeeded,hook-failed
spec:
template:
spec:
restartPolicy: Never
serviceAccountName: olm-operator-serviceaccount
containers:
- name: trigger-csv-finalizer
image: curlimages/curl:latest
command:
- /bin/sh
- -c
- |
NAMESPACE="{{ .Values.olmOperatorNamespace }}"
API_SERVER="https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_SERVICE_PORT"
CA_CERT=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt
TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
DELETE_STATUS=$(curl --cacert $CA_CERT \
-H "Authorization: Bearer $TOKEN" \
-X DELETE -s \
-o /dev/null -w "%{http_code}" \
$API_SERVER/api/v1/namespaces/$NAMESPACE)
if [ "$DELETE_STATUS" -ne 200 ] && [ "$DELETE_STATUS" -ne 202 ]; then
echo "Failed to initiate deletion for namespace $NAMESPACE. HTTP status code: $DELETE_STATUS"
exit 1
fi
echo "Waiting for finalizer in $NAMESPACE to complete..."
while true; do
STATUS=$(curl --cacert $CA_CERT \
-H "Authorization: Bearer $TOKEN" \
-o /dev/null -w "%{http_code}" -s \
$API_SERVER/api/v1/namespaces/$NAMESPACE)
if [ "$STATUS" = "404" ]; then
echo "Namespace $NAMESPACE finalizer completed."
break
else
echo "Finalizer still running in $NAMESPACE. Retrying in 5 seconds..."
sleep 5
fi
done

0 comments on commit 1f120d5

Please sign in to comment.