Skip to content

Commit 1f120d5

Browse files
committed
Add Job to ensure OLM operator ns finalizers complete
Signed-off-by: Dom Del Nano <ddelnano@gmail.com>
1 parent 672e351 commit 1f120d5

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

k8s/operator/helm/templates/00_olm.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,54 @@ spec:
229229
targetNamespaces:
230230
- {{ .Values.olmNamespace }}
231231
{{- end}}
232+
---
233+
apiVersion: batch/v1
234+
kind: Job
235+
metadata:
236+
name: csv-deleter
237+
namespace: {{ .Values.olmNamespace }}
238+
annotations:
239+
"helm.sh/hook": pre-delete
240+
"helm.sh/hook-delete-policy": hook-succeeded,hook-failed
241+
spec:
242+
template:
243+
spec:
244+
restartPolicy: Never
245+
serviceAccountName: olm-operator-serviceaccount
246+
containers:
247+
- name: trigger-csv-finalizer
248+
image: curlimages/curl:latest
249+
command:
250+
- /bin/sh
251+
- -c
252+
- |
253+
NAMESPACE="{{ .Values.olmOperatorNamespace }}"
254+
API_SERVER="https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_SERVICE_PORT"
255+
CA_CERT=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt
256+
TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
257+
258+
DELETE_STATUS=$(curl --cacert $CA_CERT \
259+
-H "Authorization: Bearer $TOKEN" \
260+
-X DELETE -s \
261+
-o /dev/null -w "%{http_code}" \
262+
$API_SERVER/api/v1/namespaces/$NAMESPACE)
263+
264+
if [ "$DELETE_STATUS" -ne 200 ] && [ "$DELETE_STATUS" -ne 202 ]; then
265+
echo "Failed to initiate deletion for namespace $NAMESPACE. HTTP status code: $DELETE_STATUS"
266+
exit 1
267+
fi
268+
269+
echo "Waiting for finalizer in $NAMESPACE to complete..."
270+
while true; do
271+
STATUS=$(curl --cacert $CA_CERT \
272+
-H "Authorization: Bearer $TOKEN" \
273+
-o /dev/null -w "%{http_code}" -s \
274+
$API_SERVER/api/v1/namespaces/$NAMESPACE)
275+
if [ "$STATUS" = "404" ]; then
276+
echo "Namespace $NAMESPACE finalizer completed."
277+
break
278+
else
279+
echo "Finalizer still running in $NAMESPACE. Retrying in 5 seconds..."
280+
sleep 5
281+
fi
282+
done

0 commit comments

Comments
 (0)