Skip to content

Commit faf850c

Browse files
authored
feat: add custom migration job for hydra (#732)
1 parent 5d1436f commit faf850c

File tree

2 files changed

+147
-0
lines changed

2 files changed

+147
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
{{- range $jobName, $job := $.Values.hydra.customMigrations.jobs }}
2+
{{- if $job.enabled -}}
3+
{{- $nodeSelector := ternary $job.nodeSelector $.Values.job.nodeSelector (not (empty $job.nodeSelector)) -}}
4+
{{- $migrationExtraEnv := ternary $job.extraEnv $.Values.job.extraEnv (not (empty $job.extraEnv)) -}}
5+
{{- $resources := ternary $job.resources $.Values.job.resources (not (empty $job.resources)) -}}
6+
{{- $annotations := merge $.Values.job.annotations (default dict $job.annotations) -}}
7+
{{- $labels := merge $.Values.job.labels (default dict $job.labels) -}}
8+
9+
---
10+
apiVersion: batch/v1
11+
kind: Job
12+
metadata:
13+
name: {{ include "hydra.fullname" $ }}-{{ $jobName }}
14+
{{- if $.Release.Namespace }}
15+
namespace: {{ $.Release.Namespace }}
16+
{{- end }}
17+
labels:
18+
{{- include "hydra.labels" $ | nindent 4 }}
19+
{{- with $labels }}
20+
{{- toYaml . | nindent 4 }}
21+
{{- end }}
22+
annotations:
23+
{{- with $annotations }}
24+
{{- toYaml . | nindent 4 }}
25+
{{- end }}
26+
spec:
27+
template:
28+
metadata:
29+
annotations:
30+
{{- with $annotations }}
31+
{{- toYaml . | nindent 8 }}
32+
{{- end }}
33+
{{- with $.Values.job.podMetadata.annotations }}
34+
{{- toYaml . | nindent 8 }}
35+
{{- end }}
36+
labels:
37+
app.kubernetes.io/name: {{ include "hydra.fullname" $ }}-{{ $jobName }}-automigrate
38+
app.kubernetes.io/instance: {{ $.Release.Name }}
39+
{{- with $labels }}
40+
{{- toYaml . | nindent 8 }}
41+
{{- end }}
42+
{{- with $.Values.job.podMetadata.labels }}
43+
{{- toYaml . | nindent 8 }}
44+
{{- end }}
45+
spec:
46+
{{- with $.Values.imagePullSecrets }}
47+
imagePullSecrets:
48+
{{- toYaml . | nindent 8 }}
49+
{{- end }}
50+
serviceAccountName: {{ include "hydra.job.serviceAccountName" $ }}
51+
automountServiceAccountToken: {{ $.Values.job.automountServiceAccountToken }}
52+
containers:
53+
- name: {{ $.Chart.Name }}-{{ $jobName }}
54+
image: "{{ $.Values.image.repository }}:{{ $.Values.image.tag }}"
55+
imagePullPolicy: {{ $.Values.image.pullPolicy }}
56+
{{- if $job.customCommand }}
57+
command: {{- toYaml $job.customCommand | nindent 10 }}
58+
{{- else }}
59+
command: ["hydra"]
60+
{{- end }}
61+
args: {{- toYaml $job.customArgs | nindent 10 }}
62+
env:
63+
{{- if not (empty ( include "hydra.dsn" $ )) }}
64+
{{- if not (include "ory.extraEnvContainsEnvName" (list $migrationExtraEnv "DSN")) }}
65+
- name: DSN
66+
valueFrom:
67+
secretKeyRef:
68+
name: {{ include "hydra.secretname" $ }}
69+
key: dsn
70+
{{- end }}
71+
{{- end }}
72+
{{- with $migrationExtraEnv }}
73+
{{- toYaml . | nindent 10 }}
74+
{{- end }}
75+
lifecycle:
76+
{{- if $.Values.job.lifecycle }}
77+
{{- tpl $.Values.job.lifecycle $ | nindent 10 }}
78+
{{- end }}
79+
{{- with $.Values.deployment.securityContext }}
80+
securityContext:
81+
{{- toYaml . | nindent 10 }}
82+
{{- end }}
83+
{{- with $resources }}
84+
resources:
85+
{{- toYaml . | nindent 10 }}
86+
{{- end }}
87+
volumeMounts:
88+
- name: {{ include "hydra.name" $ }}-config-volume
89+
mountPath: /etc/config
90+
readOnly: true
91+
{{- if $job.extraVolumeMounts }}
92+
{{- toYaml $job.extraVolumeMounts | nindent 12 }}
93+
{{- else if $.Values.deployment.extraVolumeMounts }}
94+
{{- toYaml $.Values.deployment.extraVolumeMounts | nindent 12 }}
95+
{{- end }}
96+
{{- if $.Values.job.extraContainers }}
97+
{{- tpl $.Values.job.extraContainers $ | nindent 6 }}
98+
{{- end }}
99+
{{- if $.Values.job.extraInitContainers }}
100+
initContainers:
101+
{{- tpl $.Values.job.extraInitContainers $ | nindent 8 }}
102+
{{- end }}
103+
restartPolicy: Never
104+
{{- with $.Values.deployment.podSecurityContext }}
105+
securityContext:
106+
{{- toYaml . | nindent 8 }}
107+
{{- end }}
108+
shareProcessNamespace: {{ $.Values.job.shareProcessNamespace }}
109+
volumes:
110+
- name: {{ include "hydra.name" $ }}-config-volume
111+
configMap:
112+
name: {{ include "hydra.fullname" $ }}-migrate
113+
{{- if $job.extraVolumes }}
114+
{{- toYaml $job.extraVolumes | nindent 8 }}
115+
{{- else if $.Values.deployment.extraVolumes }}
116+
{{- toYaml $.Values.deployment.extraVolumes | nindent 8 }}
117+
{{- end }}
118+
{{- with $nodeSelector }}
119+
nodeSelector:
120+
{{- toYaml . | nindent 8 }}
121+
{{- end }}
122+
{{- with $.Values.job.tolerations }}
123+
tolerations:
124+
{{- toYaml . | nindent 8 }}
125+
{{- end }}
126+
backoffLimit: {{ $.Values.job.spec.backoffLimit }}
127+
{{- end }}
128+
{{- end }}

helm/charts/hydra/values.yaml

+19
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,25 @@ hydra:
177177
# -- resource requests and limits for the automigration initcontainer
178178
resources: {}
179179

180+
customMigrations:
181+
jobs:
182+
# -- Example of custom migration job (TTL migrations are available only in Hydra with Enterprise license)
183+
oel-postgresql-ttl:
184+
enabled: false
185+
customArgs:
186+
[
187+
"migrate",
188+
"postgresql-addons",
189+
"up",
190+
"--hydra-db-name",
191+
"ory_hydra",
192+
"--pgcron-db-name",
193+
"postgres",
194+
]
195+
nodeSelector: {}
196+
resources: {}
197+
extraEnv: []
198+
180199
# -- Enable dev mode, not secure in production environments
181200
dev: false
182201

0 commit comments

Comments
 (0)