diff --git a/contrib/charts/dragonfly/templates/_pod.tpl b/contrib/charts/dragonfly/templates/_pod.tpl index c73df261dbef..85c41d30c71b 100644 --- a/contrib/charts/dragonfly/templates/_pod.tpl +++ b/contrib/charts/dragonfly/templates/_pod.tpl @@ -83,6 +83,13 @@ containers: {{- end }} args: - "--alsologtostderr" + {{- if .Values.snapshot.enabled }} + - "--snapshot_cron" + - "{{ .Values.snapshot.schedule }}" + {{- if eq .Values.snapshot.format "rdb" }} + - "--nodf_snapshot_format" + {{- end }} + {{- end }} {{- with .Values.extraArgs }} {{- toYaml . | trim | nindent 6 }} {{- end }} @@ -123,6 +130,31 @@ containers: envFrom: {{- toYaml . | trim | nindent 6 }} {{- end }} + {{- if .Values.snapshot.enabled }} + - name: snapshot-cleaner + image: {{ .Values.snapshot.cleaner.image }} + command: + - /bin/sh + - -c + - | + while true; do + {{- if eq .Values.snapshot.format "dragonfly" }} + # Keep only the last {{ .Values.snapshot.cleaner.max_count }} snapshots (composed of two files each) + ls -1t /data/dump-*.dfs | tail -n +{{ add 1 (mul .Values.snapshot.cleaner.max_count 2) }} | xargs rm -f + {{- else }} + # Keep only the last {{ .Values.snapshot.cleaner.max_count }} snapshots + ls -1t /data/dump-*.rdb | tail -n +{{ add 1 .Values.snapshot.cleaner.max_count }} | xargs rm -f + {{- end }} + sleep {{ .Values.snapshot.cleaner.interval }} + done + volumeMounts: + - mountPath: /data + name: "{{ .Release.Name }}-data" + {{- with .Values.snapshot.cleaner.resources }} + resources: + {{- toYaml . | trim | nindent 6 }} + {{- end }} + {{- end }} {{- if or (.Values.tls.enabled) (.Values.extraVolumes) }} volumes: diff --git a/contrib/charts/dragonfly/values.yaml b/contrib/charts/dragonfly/values.yaml index 5863b420c34c..f49b68135b23 100644 --- a/contrib/charts/dragonfly/values.yaml +++ b/contrib/charts/dragonfly/values.yaml @@ -98,6 +98,32 @@ storage: # -- Volume size to request for the PVC requests: 128Mi +snapshot: + # -- enable snapshot + enabled: false + # -- snapshot cron schedule format (crontab style) + schedule: "" + # -- snapshot format (default: "df" for Dragonfly, "rdb" is also supported) + format: "df" + # -- snapshot cleaner + cleaner: + # -- snapshot cleaner image + image: "alpine:3.22" + # -- snapshot cleaner interval + interval: 30m + # -- max snapshots to keep (default: 10) + max_count: 10 + # -- snapshot cleaner resources + resources: + # -- The requested resources for the cleaner container + requests: {} + # cpu: 50m + # memory: 128Mi + # -- The resource limits for the cleaner container + limits: {} + # cpu: 50m + # memory: 128Mi + tls: # -- enable TLS enabled: false