Skip to content

Commit

Permalink
Add cleanup cron script for remove old snapshots
Browse files Browse the repository at this point in the history
Negashev committed Jan 7, 2024
1 parent 3b877ee commit a4eeb54
Showing 2 changed files with 41 additions and 0 deletions.
10 changes: 10 additions & 0 deletions chart/templates/cleanup-config-map.yaml
Original file line number Diff line number Diff line change
@@ -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'`
31 changes: 31 additions & 0 deletions chart/templates/cleanup-cron.yaml
Original file line number Diff line number Diff line change
@@ -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: '* * * * *'

0 comments on commit a4eeb54

Please sign in to comment.