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
  • Loading branch information
tamalsaha committed Sep 7, 2024
1 parent 88eaf10 commit ad7be30
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
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
22 changes: 17 additions & 5 deletions charts/openfga/templates/job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,32 @@ 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
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 @@ -87,5 +100,4 @@ spec:
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
backoffLimit: 1
{{- end }}
15 changes: 9 additions & 6 deletions charts/openfga/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -319,15 +319,18 @@ affinity: {}
# containerPort: 1234
sidecars: []
migrate:
extraVolumes: []
extraVolumeMounts: []
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: true
hook: "post-install, post-upgrade, post-rollback, post-delete"
hookWeight: "-5"
hookDeletePolicy: "before-hook-creation"
annotations: {}
labels: {}
timeout:
ttlSecondsAfterFinished: -1

# -- Array of extra K8s manifests to deploy
## Note: Supports use of custom Helm templates
Expand Down

0 comments on commit ad7be30

Please sign in to comment.