Skip to content

Commit

Permalink
Run migrate job as pre hook with option to auto cleanup
Browse files Browse the repository at this point in the history
xref: https://x.com/tsaha/status/1805382111844778275

Signed-off-by: Tamal Saha <tamal@appscode.com>
  • Loading branch information
tamalsaha committed Jun 25, 2024
1 parent eed5562 commit 95d47a1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
2 changes: 1 addition & 1 deletion charts/openfga/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: openfga
description: A Kubernetes Helm chart for the OpenFGA project.

type: application
version: 0.2.6
version: 0.2.7
appVersion: "v1.5.4"

home: "https://openfga.github.io/helm-charts"
Expand Down
2 changes: 2 additions & 0 deletions charts/openfga/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ spec:
selector:
matchLabels:
{{- include "openfga.selectorLabels" . | nindent 6 }}
app.kubernetes.io/component: server
template:
metadata:
annotations:
Expand All @@ -26,6 +27,7 @@ spec:
prometheus.io/port: "{{ (split ":" .Values.telemetry.metrics.addr)._1 }}"
labels:
{{- include "openfga.selectorLabels" . | nindent 8 }}
app.kubernetes.io/component: server
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
Expand Down
25 changes: 20 additions & 5 deletions charts/openfga/templates/job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,35 @@ metadata:
{{- with .Values.migrate.labels }}
{{- toYaml . | nindent 4}}
{{- end}}
{{- with .Values.migrate.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.migrate.annotations }}
{{- toYaml . | nindent 4}}
{{- end}}
{{- if .Values.migrate.hook.enable }}
helm.sh/hook: {{ .Values.migrate.hook.hook | quote }}
helm.sh/hook-weight: {{ .Values.migrate.hook.hookWeight | quote }}
helm.sh/hook-delete-policy: {{ .Values.migrate.hook.hookDeletePolicy | quote }}
{{- end}}
spec:
backoffLimit: 3
{{- if ge (int .Values.migrate.ttlSecondsAfterFinished) 0 }}
ttlSecondsAfterFinished: {{ .Values.migrate.ttlSecondsAfterFinished }}
{{- end }}
manualSelector: true
selector:
matchLabels:
{{- include "openfga.selectorLabels" . | nindent 6 }}
app.kubernetes.io/component: migrate
template:
metadata:
{{- with .Values.migrate.annotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.migrate.labels }}
labels:
{{- include "openfga.selectorLabels" . | nindent 8 }}
app.kubernetes.io/component: migrate
{{- with .Values.migrate.labels }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
Expand Down Expand Up @@ -79,5 +95,4 @@ spec:
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
backoffLimit: 1
{{- end }}
15 changes: 10 additions & 5 deletions charts/openfga/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,14 @@ affinity: {}
sidecars: []
migrate:
sidecars: []
annotations:
helm.sh/hook: "post-install, post-upgrade, post-rollback, post-delete"
helm.sh/hook-weight: "-5"
helm.sh/hook-delete-policy: "before-hook-creation"
# https://github.com/fluxcd/flux2/discussions/1085#discussioncomment-473271
# https://github.com/helm/helm/issues/9027#issuecomment-1908032461
hook:
enable: false
hook: "post-install, post-upgrade, post-rollback, post-delete"
hookWeight: "-5"
hookDeletePolicy: "before-hook-creation"
annotations: {}
labels: {}
timeout:
timeout: 10m
ttlSecondsAfterFinished: -1

0 comments on commit 95d47a1

Please sign in to comment.