Skip to content

Commit

Permalink
Added cronjob for deleting failed flinkdeployments
Browse files Browse the repository at this point in the history
  • Loading branch information
pielas committed Feb 7, 2025
1 parent 606663e commit 3fa4321
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/templates/flink-k8s-operator/cleanup-finished-deployments.yaml
Original file line number Diff line number Diff line change
@@ -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 }}

0 comments on commit 3fa4321

Please sign in to comment.