Skip to content

Commit 8c3297d

Browse files
authored
fix: Add Helm hooks for schema Job to fix deployment ordering (#888)
* fix: Add Helm hooks for schema Job to fix deployment ordering
1 parent 5a99926 commit 8c3297d

8 files changed

Lines changed: 204 additions & 2 deletions

File tree

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,14 @@ web:
595595
value: /custom-path
596596
```
597597

598+
### Schema Setup and Deployment Ordering
599+
600+
By default, the schema Job uses [Helm hooks](https://helm.sh/docs/topics/charts_hooks/) (`pre-install`, `pre-upgrade`) to ensure database and Elasticsearch schemas are set up before server pods start.
601+
602+
ArgoCD [maps Helm hooks to ArgoCD hooks](https://argo-cd.readthedocs.io/en/stable/user-guide/helm/) (`pre-install`/`pre-upgrade` → PreSync, `post-install`/`post-upgrade` → PostSync, `hook-weight` → sync-wave), so the default should work with ArgoCD. Caveats: ArgoCD cannot distinguish install from upgrade (every operation is a sync), and delete-policy follows [ArgoCD sync semantics](https://argo-cd.readthedocs.io/en/stable/user-guide/sync-waves/) rather than Helm's per-hook lifecycle. If any ArgoCD-native hooks are defined, all Helm hooks are ignored.
603+
604+
For explicit control, or when using Flux, Rancher or Terraform, set `useHelmHooks: false`.
605+
598606
## Uninstalling
599607

600608
Note: Depending on how the persistence is configured, this may remove all of the Temporal data.

charts/temporal/templates/server-job.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,16 @@ metadata:
55
name: {{ $jobName }}
66
labels:
77
{{- include "temporal.resourceLabels" (list $ "database" "") | nindent 4 }}
8-
{{- with $.Values.schema.jobAnnotations }}
8+
{{- if or $.Values.schema.useHelmHooks $.Values.schema.jobAnnotations }}
99
annotations:
10+
{{- if $.Values.schema.useHelmHooks }}
11+
"helm.sh/hook": pre-install,pre-upgrade
12+
"helm.sh/hook-weight": "0"
13+
"helm.sh/hook-delete-policy": before-hook-creation
14+
{{- end }}
15+
{{- with $.Values.schema.jobAnnotations }}
1016
{{- toYaml . | nindent 4 }}
17+
{{- end }}
1118
{{- end }}
1219
spec:
1320
backoffLimit: {{ $.Values.schema.backoffLimit }}

charts/temporal/templates/server-secret.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,16 @@ metadata:
66
name: {{ include "temporal.persistence.secretName" (list $ $store) }}
77
labels:
88
{{- include "temporal.resourceLabels" (list $ "" "secret") | nindent 4 }}
9-
{{- with $.Values.server.secretAnnotations }}
9+
{{- if or $.Values.schema.useHelmHooks $.Values.server.secretAnnotations }}
1010
annotations:
11+
{{- if $.Values.schema.useHelmHooks }}
12+
"helm.sh/hook": pre-install,pre-upgrade
13+
"helm.sh/hook-weight": "-1"
14+
"helm.sh/hook-delete-policy": before-hook-creation
15+
{{- end }}
16+
{{- with $.Values.server.secretAnnotations }}
1117
{{- toYaml . | nindent 4 }}
18+
{{- end }}
1219
{{- end }}
1320
type: Opaque
1421
data:

charts/temporal/templates/shim-configmap.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ metadata:
55
name: "{{ include "temporal.fullname" $ }}-shims"
66
labels:
77
{{- include "temporal.resourceLabels" (list $ "" "") | nindent 4 }}
8+
{{- if $.Values.schema.useHelmHooks }}
9+
annotations:
10+
"helm.sh/hook": pre-install,pre-upgrade
11+
"helm.sh/hook-weight": "-1"
12+
"helm.sh/hook-delete-policy": before-hook-creation
13+
{{- end }}
814
data:
915
{{- if $.Values.shims.dockerize }}
1016
dockerize: |-

charts/temporal/tests/server_job_test.yaml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,80 @@ tests:
206206
- equal:
207207
path: spec.template.spec.initContainers[*].resources.limits.memory
208208
value: 16Gi
209+
- it: includes Helm hook annotations by default
210+
set:
211+
server:
212+
config:
213+
persistence:
214+
datastores:
215+
default:
216+
sql:
217+
pluginName: mysql8
218+
connectAddr: "temporal-persistence:3306"
219+
databaseName: temporal
220+
visibility:
221+
sql:
222+
pluginName: mysql8
223+
connectAddr: "temporal-visibility:3306"
224+
databaseName: temporal_visibility
225+
asserts:
226+
- equal:
227+
path: metadata.annotations["helm.sh/hook"]
228+
value: "pre-install,pre-upgrade"
229+
- equal:
230+
path: metadata.annotations["helm.sh/hook-weight"]
231+
value: "0"
232+
- equal:
233+
path: metadata.annotations["helm.sh/hook-delete-policy"]
234+
value: "before-hook-creation"
235+
- it: excludes Helm hook annotations when useHelmHooks is false
236+
set:
237+
server:
238+
config:
239+
persistence:
240+
datastores:
241+
default:
242+
sql:
243+
pluginName: mysql8
244+
connectAddr: "temporal-persistence:3306"
245+
databaseName: temporal
246+
visibility:
247+
sql:
248+
pluginName: mysql8
249+
connectAddr: "temporal-visibility:3306"
250+
databaseName: temporal_visibility
251+
schema:
252+
useHelmHooks: false
253+
asserts:
254+
- isNull:
255+
path: metadata.annotations
256+
- it: merges Helm hook annotations with custom jobAnnotations
257+
set:
258+
server:
259+
config:
260+
persistence:
261+
datastores:
262+
default:
263+
sql:
264+
pluginName: mysql8
265+
connectAddr: "temporal-persistence:3306"
266+
databaseName: temporal
267+
visibility:
268+
sql:
269+
pluginName: mysql8
270+
connectAddr: "temporal-visibility:3306"
271+
databaseName: temporal_visibility
272+
schema:
273+
useHelmHooks: true
274+
jobAnnotations:
275+
custom-job-annotation: abc
276+
asserts:
277+
- equal:
278+
path: metadata.annotations["helm.sh/hook"]
279+
value: "pre-install,pre-upgrade"
280+
- equal:
281+
path: metadata.annotations.custom-job-annotation
282+
value: abc
209283
- it: includes custom annotations and labels for pod and job
210284
set:
211285
server:
@@ -223,6 +297,7 @@ tests:
223297
connectAddr: "temporal-visibility:3306"
224298
databaseName: temporal_visibility
225299
schema:
300+
useHelmHooks: false
226301
jobAnnotations:
227302
custom-job-annotation: abc
228303
podAnnotations:

charts/temporal/tests/server_secret_test.yaml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,74 @@ tests:
5757
- containsDocument:
5858
kind: Secret
5959
apiVersion: v1
60+
- it: includes Helm hook annotations by default
61+
set:
62+
server:
63+
config:
64+
persistence:
65+
datastores:
66+
default:
67+
sql:
68+
password: "test"
69+
visibility:
70+
sql:
71+
password: "test"
72+
documentSelector:
73+
path: metadata.name
74+
value: RELEASE-NAME-temporal-default-store
75+
asserts:
76+
- equal:
77+
path: metadata.annotations["helm.sh/hook"]
78+
value: "pre-install,pre-upgrade"
79+
- equal:
80+
path: metadata.annotations["helm.sh/hook-weight"]
81+
value: "-1"
82+
- equal:
83+
path: metadata.annotations["helm.sh/hook-delete-policy"]
84+
value: "before-hook-creation"
85+
- it: excludes Helm hook annotations when useHelmHooks is false
86+
set:
87+
server:
88+
config:
89+
persistence:
90+
datastores:
91+
default:
92+
sql:
93+
password: "test"
94+
visibility:
95+
sql:
96+
password: "test"
97+
schema:
98+
useHelmHooks: false
99+
documentSelector:
100+
path: metadata.name
101+
value: RELEASE-NAME-temporal-default-store
102+
asserts:
103+
- isNull:
104+
path: metadata.annotations
105+
- it: merges Helm hook annotations with custom secretAnnotations
106+
set:
107+
server:
108+
secretAnnotations:
109+
custom-annotation: abc
110+
config:
111+
persistence:
112+
datastores:
113+
default:
114+
sql:
115+
password: "test"
116+
visibility:
117+
sql:
118+
password: "test"
119+
schema:
120+
useHelmHooks: true
121+
documentSelector:
122+
path: metadata.name
123+
value: RELEASE-NAME-temporal-default-store
124+
asserts:
125+
- equal:
126+
path: metadata.annotations["helm.sh/hook"]
127+
value: "pre-install,pre-upgrade"
128+
- equal:
129+
path: metadata.annotations.custom-annotation
130+
value: abc
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
suite: test shim configmap
2+
templates:
3+
- shim-configmap.yaml
4+
tests:
5+
- it: includes Helm hook annotations when useHelmHooks is true
6+
set:
7+
schema:
8+
useHelmHooks: true
9+
asserts:
10+
- equal:
11+
path: metadata.annotations["helm.sh/hook"]
12+
value: "pre-install,pre-upgrade"
13+
- equal:
14+
path: metadata.annotations["helm.sh/hook-weight"]
15+
value: "-1"
16+
- equal:
17+
path: metadata.annotations["helm.sh/hook-delete-policy"]
18+
value: "before-hook-creation"
19+
- it: excludes Helm hook annotations when useHelmHooks is false
20+
set:
21+
schema:
22+
useHelmHooks: false
23+
asserts:
24+
- isNull:
25+
path: metadata.annotations

charts/temporal/values.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,9 @@ web:
528528
minReadySeconds: 0
529529
podDisruptionBudget: {}
530530
schema:
531+
# Use Helm hooks to ensure schema setup completes before server pods start.
532+
# Set to false if using Flux, Rancher or Terraform.
533+
useHelmHooks: true
531534
backoffLimit: 100
532535
ttlSecondsAfterFinished: 86400
533536
jobAnnotations: {}

0 commit comments

Comments
 (0)