Skip to content

Commit 55c2fe3

Browse files
committed
feat(helm): add snapshot functionality with automatic cleanup
- Add snapshot configuration section to values.yaml with: - Enable/disable toggle - Cron schedule configuration - Format selection (dragonfly/rdb) - Cleaner settings (image, interval, max count, resources) - Add snapshot-cleaner sidecar container to pod template: - Automatically removes old snapshots based on max_count - Supports both dragonfly (.dfs) and rdb formats - Configurable cleanup interval and resource limits - Add snapshot cron arguments to main dragonfly container - Maintains backward compatibility with existing configurations
1 parent fbc47ff commit 55c2fe3

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

contrib/charts/dragonfly/templates/_pod.tpl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ containers:
8383
{{- end }}
8484
args:
8585
- "--alsologtostderr"
86+
{{- if .Values.snapshot.enabled }}
87+
- "--snapshot_cron"
88+
- "{{ .Values.snapshot.schedule }}"
89+
{{- if eq .Values.snapshot.format "rdb" }}
90+
- "--nodf_snapshot_format"
91+
{{- end }}
92+
{{- end }}
8693
{{- with .Values.extraArgs }}
8794
{{- toYaml . | trim | nindent 6 }}
8895
{{- end }}
@@ -123,6 +130,31 @@ containers:
123130
envFrom:
124131
{{- toYaml . | trim | nindent 6 }}
125132
{{- end }}
133+
{{- if .Values.snapshot.enabled }}
134+
- name: snapshot-cleaner
135+
image: {{ .Values.snapshot.cleaner.image }}
136+
command:
137+
- /bin/sh
138+
- -c
139+
- |
140+
while true; do
141+
{{- if eq .Values.snapshot.format "dragonfly" }}
142+
# Keep only the last {{ .Values.snapshot.cleaner.max_count }} snapshots (composed of two files each)
143+
ls -1t /data/dump-*.dfs | tail -n +{{ add 1 (mul .Values.snapshot.cleaner.max_count 2) }} | xargs rm -f
144+
{{- else }}
145+
# Keep only the last {{ .Values.snapshot.cleaner.max_count }} snapshots
146+
ls -1t /data/dump-*.rdb | tail -n +{{ add 1 .Values.snapshot.cleaner.max_count }} | xargs rm -f
147+
{{- end }}
148+
sleep {{ .Values.snapshot.cleaner.interval }}
149+
done
150+
volumeMounts:
151+
- mountPath: /data
152+
name: "{{ .Release.Name }}-data"
153+
{{- with .Values.snapshot.cleaner.resources }}
154+
resources:
155+
{{- toYaml . | trim | nindent 6 }}
156+
{{- end }}
157+
{{- end }}
126158

127159
{{- if or (.Values.tls.enabled) (.Values.extraVolumes) }}
128160
volumes:

contrib/charts/dragonfly/values.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,32 @@ storage:
9898
# -- Volume size to request for the PVC
9999
requests: 128Mi
100100

101+
snapshot:
102+
# -- enable snapshot
103+
enabled: false
104+
# -- snapshot cron schedule format (crontab style)
105+
schedule: ""
106+
# -- snapshot format (default: "df" for Dragonfly, "rdb" is also supported)
107+
format: "df"
108+
# -- snapshot cleaner
109+
cleaner:
110+
# -- snapshot cleaner image
111+
image: "alpine:3.22"
112+
# -- snapshot cleaner interval
113+
interval: 30m
114+
# -- max snapshots to keep (default: 10)
115+
max_count: 10
116+
# -- snapshot cleaner resources
117+
resources:
118+
# -- The requested resources for the cleaner container
119+
requests: {}
120+
# cpu: 50m
121+
# memory: 128Mi
122+
# -- The resource limits for the cleaner container
123+
limits: {}
124+
# cpu: 50m
125+
# memory: 128Mi
126+
101127
tls:
102128
# -- enable TLS
103129
enabled: false

0 commit comments

Comments
 (0)