From a4eeb54acde6137aef42aa260107ef82863ebcdd Mon Sep 17 00:00:00 2001 From: Negash Date: Sun, 7 Jan 2024 13:40:00 +0000 Subject: [PATCH] Add cleanup cron script for remove old snapshots --- chart/templates/cleanup-config-map.yaml | 10 ++++++++ chart/templates/cleanup-cron.yaml | 31 +++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 chart/templates/cleanup-config-map.yaml create mode 100644 chart/templates/cleanup-cron.yaml diff --git a/chart/templates/cleanup-config-map.yaml b/chart/templates/cleanup-config-map.yaml new file mode 100644 index 0000000..171ef99 --- /dev/null +++ b/chart/templates/cleanup-config-map.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: cleanup-{{ template "aldaas.fullname" . }} + namespace: {{ .Release.Namespace }} +data: + cleanup.sh: | + #!/bin/sh + # inline remove one old workflow by volumesnapshots and stay latest + kubectl delete -n {{ .Release.Namespace }} workflow --ignore-not-found `kubectl -n aldaas get volumesnapshots -l status=ready,aldaas={{ template "aldaas.fullname" . }} --sort-by=.metadata.creationTimestamp -o json | jq -r '.items | group_by(.metadata.creationTimestamp) | map({"timestamp": .[0].metadata.creationTimestamp, "workflow": .[0].metadata.labels.backup}) | reverse | .[1:] | .[-1].workflow'` \ No newline at end of file diff --git a/chart/templates/cleanup-cron.yaml b/chart/templates/cleanup-cron.yaml new file mode 100644 index 0000000..2b21a86 --- /dev/null +++ b/chart/templates/cleanup-cron.yaml @@ -0,0 +1,31 @@ +apiVersion: argoproj.io/v1alpha1 +kind: CronWorkflow +metadata: + name: cleanup-{{ template "aldaas.fullname" . }} + namespace: {{ .Release.Namespace }} +spec: + workflowSpec: + templates: + - name: cleanup-backups + container: + name: cleanup-backups + image: rancher/kubectl:{{ .Values.kubectl }} + command: + - sh + args: + - /script/cleanup.sh + resources: {} + volumeMounts: + - name: cleanup-script + mountPath: /script + volumes: + - name: cleanup-script + configMap: + name: cleanup-{{ template "aldaas.fullname" . }} + entrypoint: cleanup-backups + arguments: {} + ttlStrategy: + secondsAfterCompletion: 300 + podGC: + strategy: OnPodCompletion + schedule: '* * * * *' \ No newline at end of file