Skip to content

Commit 9e7b50d

Browse files
committed
Run migrate job as pre hook with option to auto cleanup
xref: https://x.com/tsaha/status/1805382111844778275 Signed-off-by: Tamal Saha <[email protected]>
1 parent eed5562 commit 9e7b50d

File tree

4 files changed

+32
-10
lines changed

4 files changed

+32
-10
lines changed

charts/openfga/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: openfga
33
description: A Kubernetes Helm chart for the OpenFGA project.
44

55
type: application
6-
version: 0.2.6
6+
version: 0.2.7
77
appVersion: "v1.5.4"
88

99
home: "https://openfga.github.io/helm-charts"

charts/openfga/templates/deployment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ spec:
1515
selector:
1616
matchLabels:
1717
{{- include "openfga.selectorLabels" . | nindent 6 }}
18+
app.kubernetes.io/component: server
1819
template:
1920
metadata:
2021
annotations:
@@ -26,6 +27,7 @@ spec:
2627
prometheus.io/port: "{{ (split ":" .Values.telemetry.metrics.addr)._1 }}"
2728
labels:
2829
{{- include "openfga.selectorLabels" . | nindent 8 }}
30+
app.kubernetes.io/component: server
2931
spec:
3032
{{- with .Values.imagePullSecrets }}
3133
imagePullSecrets:

charts/openfga/templates/job.yaml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,35 @@ metadata:
88
{{- with .Values.migrate.labels }}
99
{{- toYaml . | nindent 4}}
1010
{{- end}}
11-
{{- with .Values.migrate.annotations }}
1211
annotations:
13-
{{- toYaml . | nindent 4 }}
14-
{{- end }}
12+
{{- with .Values.migrate.annotations }}
13+
{{- toYaml . | nindent 4}}
14+
{{- end}}
15+
{{- if .Values.migrate.hook.enable }}
16+
helm.sh/hook: {{ .Values.migrate.hook.hook | quote }}
17+
helm.sh/hook-weight: {{ .Values.migrate.hook.hookWeight | quote }}
18+
helm.sh/hook-delete-policy: {{ .Values.migrate.hook.hookDeletePolicy | quote }}
19+
{{- end}}
1520
spec:
21+
backoffLimit: 3
22+
{{- if ge (int .Values.migrate.ttlSecondsAfterFinished) 0 }}
23+
ttlSecondsAfterFinished: {{ .Values.migrate.ttlSecondsAfterFinished }}
24+
{{- end }}
25+
manualSelector: true
26+
selector:
27+
matchLabels:
28+
{{- include "openfga.selectorLabels" . | nindent 6 }}
29+
app.kubernetes.io/component: migrate
1630
template:
1731
metadata:
1832
{{- with .Values.migrate.annotations }}
1933
annotations:
2034
{{- toYaml . | nindent 8 }}
2135
{{- end }}
22-
{{- with .Values.migrate.labels }}
2336
labels:
37+
{{- include "openfga.selectorLabels" . | nindent 8 }}
38+
app.kubernetes.io/component: migrate
39+
{{- with .Values.migrate.labels }}
2440
{{- toYaml . | nindent 8 }}
2541
{{- end }}
2642
spec:
@@ -79,5 +95,4 @@ spec:
7995
tolerations:
8096
{{- toYaml . | nindent 8 }}
8197
{{- end }}
82-
backoffLimit: 1
8398
{{- end }}

charts/openfga/values.yaml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,14 @@ affinity: {}
320320
sidecars: []
321321
migrate:
322322
sidecars: []
323-
annotations:
324-
helm.sh/hook: "post-install, post-upgrade, post-rollback, post-delete"
325-
helm.sh/hook-weight: "-5"
326-
helm.sh/hook-delete-policy: "before-hook-creation"
323+
# https://github.com/fluxcd/flux2/discussions/1085#discussioncomment-473271
324+
# https://github.com/helm/helm/issues/9027#issuecomment-1908032461
325+
hook:
326+
enable: true
327+
hook: "post-install, post-upgrade, post-rollback, post-delete"
328+
hookWeight: "-5"
329+
hookDeletePolicy: "before-hook-creation"
330+
annotations: {}
327331
labels: {}
328332
timeout:
333+
ttlSecondsAfterFinished: -1

0 commit comments

Comments
 (0)