From 3fa4321d599f8ff645943a9cf4f553d978dde0f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Pi=C4=99kos?= Date: Fri, 7 Feb 2025 15:44:08 +0100 Subject: [PATCH] Added cronjob for deleting failed flinkdeployments --- .../cleanup-finished-deployments.yaml | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/templates/flink-k8s-operator/cleanup-finished-deployments.yaml diff --git a/src/templates/flink-k8s-operator/cleanup-finished-deployments.yaml b/src/templates/flink-k8s-operator/cleanup-finished-deployments.yaml new file mode 100644 index 0000000..a1e427f --- /dev/null +++ b/src/templates/flink-k8s-operator/cleanup-finished-deployments.yaml @@ -0,0 +1,35 @@ +{{- $originalContext := . -}} +{{- with .Values.enterprise -}} +{{- with .flinkK8sOperatorDeploymentManager -}} +{{- if .enabled }} +{{- if not (and (hasKey . "disableCleanupOfFinishedDeployments") (.disableCleanupOfFinishedDeployments)) }} +apiVersion: batch/v1 +kind: CronJob +metadata: + name: cleanup-finished-deployments + labels: + {{ include "nussknacker.labels" $originalContext | nindent 4 }} +spec: + schedule: "*/10 * * * *" # Run every 10 minutes + jobTemplate: + spec: + template: + spec: + containers: + - name: cleanup + image: bitnami/kubectl:latest + command: + - /bin/sh + - "-c" + - | + kubectl get flinkdeployments -o json | jq -r ' + .items[] | + select(.status.jobStatus.state == "FAILED" or + (.status.jobStatus.state == "FINISHED" and .status.lifecycleState == "STABLE")) | + .metadata.name' | + xargs -r kubectl delete flinkdeployment + restartPolicy: Never +{{- end }} +{{- end }} +{{- end }} +{{- end }}