-
-
Notifications
You must be signed in to change notification settings - Fork 119
Expand file tree
/
Copy pathjobs.yaml
More file actions
739 lines (731 loc) · 31.3 KB
/
jobs.yaml
File metadata and controls
739 lines (731 loc) · 31.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
{{- if and .Values.st2.rbac.enabled (not (.Values.jobs.skip | has "apply_rbac_definitions")) -}}
---
apiVersion: batch/v1
kind: Job
metadata:
name: {{ .Release.Name }}-job-st2-apply-rbac-definitions
labels: {{- include "stackstorm-ha.labels" (list $ "st2-apply-rbac-definitions") | nindent 4 }}
annotations:
helm.sh/hook: post-install, post-upgrade, post-rollback
helm.sh/hook-delete-policy: before-hook-creation
helm.sh/hook-weight: "5"
{{- if .Values.jobs.annotations }}
{{- toYaml .Values.jobs.annotations | nindent 4 }}
{{- end }}
spec:
template:
metadata:
name: job-st2-apply-rbac-definitions
labels: {{- include "stackstorm-ha.labels" (list $ "st2-apply-rbac-definitions") | nindent 8 }}
annotations:
# TODO: Investigate/propose running Helm hook only on condition when ConfigMap or Secret has changed
checksum/config: {{ include (print $.Template.BasePath "/configmaps_st2-conf.yaml") . | sha256sum }}
checksum/rbac: {{ include (print $.Template.BasePath "/configmaps_rbac.yaml") . | sha256sum }}
{{- if .Values.jobs.annotations }}
{{- toYaml .Values.jobs.annotations | nindent 8 }}
{{- end }}
spec:
imagePullSecrets:
{{- if .Values.image.pullSecret }}
- name: {{ .Values.image.pullSecret }}
{{- end }}
containers:
- name: st2-apply-rbac-definitions
image: '{{ template "stackstorm-ha.imageRepository" . }}/st2actionrunner:{{ tpl (.Values.jobs.image.tag | default (.Values.st2actionrunner.image.tag | default .Values.image.tag)) . }}'
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- with .Values.securityContext }}
securityContext: {{- toYaml . | nindent 10 }}
{{- end }}
command:
- st2-apply-rbac-definitions
- --verbose
{{- include "stackstorm-ha.st2-config-file-parameters" . | nindent 10 }}
{{- if .Values.jobs.env }}
env: {{- include "stackstorm-ha.customEnv" .Values.jobs | nindent 8 }}
{{- end }}
{{- if .Values.jobs.envFromSecrets }}
envFrom:
{{- range .Values.jobs.envFromSecrets }}
- secretRef:
name: {{ . }}
{{- end }}
{{- end }}
volumeMounts:
{{- include "stackstorm-ha.st2-config-volume-mounts" . | nindent 8 }}
- name: st2-rbac-roles-vol
mountPath: /opt/stackstorm/rbac/roles/
- name: st2-rbac-assignments-vol
mountPath: /opt/stackstorm/rbac/assignments/
- name: st2-rbac-mappings-vol
mountPath: /opt/stackstorm/rbac/mappings/
{{- range $.Values.jobs.extra_volumes }}
- name: {{ required "Each volume must have a 'name' in jobs.extra_volumes" .name }}
{{- tpl (required "Each volume must have a 'mount' definition in jobs.extra_volumes" .mount | toYaml) $ | nindent 10 }}
{{- end }}
# TODO: Find out default resource limits for this specific service (#5)
#resources:
volumes:
{{- include "stackstorm-ha.st2-config-volume" . | nindent 8 }}
- name: st2-rbac-roles-vol
configMap:
name: {{ .Release.Name }}-st2-rbac-roles
- name: st2-rbac-assignments-vol
configMap:
name: {{ .Release.Name }}-st2-rbac-assignments
- name: st2-rbac-mappings-vol
configMap:
name: {{ .Release.Name }}-st2-rbac-mappings
{{- range $.Values.jobs.extra_volumes }}
- name: {{ required "Each volume must have a 'name' in jobs.extra_volumes" .name }}
{{- tpl (required "Each volume must have a 'volume' definition in jobs.extra_volumes" .volume | toYaml) $ | nindent 10 }}
{{- end }}
restartPolicy: OnFailure
{{- if .Values.dnsPolicy }}
dnsPolicy: {{ .Values.dnsPolicy }}
{{- end }}
{{- with .Values.dnsConfig }}
dnsConfig: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.podSecurityContext }}
securityContext: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.jobs.nodeSelector }}
nodeSelector: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.jobs.affinity }}
affinity: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.jobs.tolerations }}
tolerations: {{- toYaml . | nindent 8 }}
{{- end }}
{{- end }}
{{- if not (.Values.jobs.skip | has "apikey_load") }}
---
apiVersion: batch/v1
kind: Job
metadata:
name: {{ .Release.Name }}-job-st2-apikey-load
labels: {{- include "stackstorm-ha.labels" (list $ "st2") | nindent 4 }}
annotations:
helm.sh/hook: post-install, post-upgrade, post-rollback
helm.sh/hook-delete-policy: before-hook-creation
helm.sh/hook-weight: "6"
{{- if .Values.jobs.annotations }}
{{- toYaml .Values.jobs.annotations | nindent 4 }}
{{- end }}
spec:
template:
metadata:
name: job-st2-apikey-load
labels: {{- include "stackstorm-ha.labels" (list $ "st2") | nindent 8 }}
annotations:
# TODO: Investigate/propose running Helm hook only on condition when ConfigMap or Secret has changed
checksum/urls: {{ include (print $.Template.BasePath "/configmaps_st2-urls.yaml") . | sha256sum }}
checksum/apikeys: {{ include (print $.Template.BasePath "/secrets_st2apikeys.yaml") . | sha256sum }}
{{- if .Values.jobs.annotations }}
{{- toYaml .Values.jobs.annotations | nindent 8 }}
{{- end }}
spec:
imagePullSecrets:
{{- if .Values.image.pullSecret }}
- name: {{ .Values.image.pullSecret }}
{{- end }}
initContainers:
{{- include "stackstorm-ha.init-containers-wait-for-db" . | nindent 6 }}
- name: wait-for-api
image: {{ template "stackstorm-ha.utilityImage" . }}
{{- with .Values.securityContext }}
securityContext: {{- toYaml . | nindent 10 }}
{{- end }}
command:
- 'sh'
- '-c'
- >
until nc -z -w 2 {{ .Release.Name }}-st2api 9101 && echo st2api ready;
do sleep 2;
done
# Sidecar container for generating st2client config with st2 username & password pair and sharing produced file with the main container
- name: generate-st2client-config
image: '{{ template "stackstorm-ha.imageRepository" . }}/st2actionrunner:{{ tpl (.Values.jobs.image.tag | default (.Values.st2actionrunner.image.tag | default .Values.image.tag)) . }}'
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- with .Values.securityContext }}
securityContext: {{- toYaml . | nindent 10 }}
{{- end }}
envFrom:
- configMapRef:
name: {{ .Release.Name }}-st2-urls
- secretRef:
name: {{ include "stackstorm-ha.secrets.st2Auth" . }}
{{- range .Values.jobs.envFromSecrets }}
- secretRef:
name: {{ . }}
{{- end }}
volumeMounts:
- name: st2client-config-vol
mountPath: /root/.st2/
# `st2 login` doesn't exit on failure correctly, use old methods instead. See bug: https://github.com/StackStorm/st2/issues/4338
command:
- 'sh'
- '-ec'
- |
cat <<EOT > /root/.st2/config
{{- tpl .Values.jobs.st2clientConfig . | nindent 12 }}
EOT
containers:
- name: st2-apikey-load
image: '{{ template "stackstorm-ha.imageRepository" . }}/st2actionrunner:{{ tpl (.Values.jobs.image.tag | default (.Values.st2actionrunner.image.tag | default .Values.image.tag)) . }}'
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- with .Values.securityContext }}
securityContext: {{- toYaml . | nindent 10 }}
{{- end }}
command:
- st2
- apikey
- load
- /etc/st2/apikeys.yaml
{{- if .Values.jobs.env }}
env: {{- include "stackstorm-ha.customEnv" .Values.jobs | nindent 8 }}
{{- end }}
envFrom:
- configMapRef:
name: {{ .Release.Name }}-st2-urls
{{- range .Values.jobs.envFromSecrets }}
- secretRef:
name: {{ . }}
{{- end }}
volumeMounts:
- name: st2client-config-vol
mountPath: /root/.st2/
- name: st2-apikeys-vol
mountPath: /etc/st2/apikeys.yaml
subPath: apikeys.yaml
{{- range $.Values.jobs.extra_volumes }}
- name: {{ required "Each volume must have a 'name' in jobs.extra_volumes" .name }}
{{- tpl (required "Each volume must have a 'mount' definition in jobs.extra_volumes" .mount | toYaml) $ | nindent 10 }}
{{- end }}
# TODO: Find out default resource limits for this specific service (#5)
#resources:
volumes:
- name: st2client-config-vol
emptyDir:
medium: Memory
- name: st2-apikeys-vol
secret:
secretName: {{ .Release.Name }}-st2-apikeys
{{- range $.Values.jobs.extra_volumes }}
- name: {{ required "Each volume must have a 'name' in jobs.extra_volumes" .name }}
{{- tpl (required "Each volume must have a 'volume' definition in jobs.extra_volumes" .volume | toYaml) $ | nindent 10 }}
{{- end }}
restartPolicy: OnFailure
{{- if .Values.dnsPolicy }}
dnsPolicy: {{ .Values.dnsPolicy }}
{{- end }}
{{- with .Values.dnsConfig }}
dnsConfig: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.podSecurityContext }}
securityContext: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.jobs.nodeSelector }}
nodeSelector: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.jobs.affinity }}
affinity: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.jobs.tolerations }}
tolerations: {{- toYaml . | nindent 8 }}
{{- end }}
{{- end }}
{{- if not (.Values.jobs.skip | has "key_load") }}
---
apiVersion: batch/v1
kind: Job
metadata:
name: {{ .Release.Name }}-job-st2-key-load
labels: {{- include "stackstorm-ha.labels" (list $ "st2") | nindent 4 }}
annotations:
helm.sh/hook: post-install, post-upgrade, post-rollback
helm.sh/hook-delete-policy: before-hook-creation
helm.sh/hook-weight: "6"
{{- if .Values.jobs.annotations }}
{{- toYaml .Values.jobs.annotations | nindent 4 }}
{{- end }}
spec:
template:
metadata:
name: job-st2-key-load
labels: {{- include "stackstorm-ha.labels" (list $ "st2") | nindent 8 }}
annotations:
# TODO: Investigate/propose running Helm hook only on condition when ConfigMap or Secret has changed
checksum/config: {{ include (print $.Template.BasePath "/configmaps_st2-conf.yaml") . | sha256sum }}
checksum/urls: {{ include (print $.Template.BasePath "/configmaps_st2-urls.yaml") . | sha256sum }}
{{- if .Values.jobs.annotations }}
{{- toYaml .Values.jobs.annotations | nindent 8 }}
{{- end }}
spec:
imagePullSecrets:
{{- if .Values.image.pullSecret }}
- name: {{ .Values.image.pullSecret }}
{{- end }}
initContainers:
{{- include "stackstorm-ha.init-containers-wait-for-db" . | nindent 6 }}
# Sidecar container for generating st2client config with st2 username & password pair and sharing produced file with the main container
- name: generate-st2client-config
image: '{{ template "stackstorm-ha.imageRepository" . }}/st2actionrunner:{{ tpl (.Values.jobs.image.tag | default (.Values.st2actionrunner.image.tag | default .Values.image.tag)) . }}'
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- with .Values.securityContext }}
securityContext: {{- toYaml . | nindent 10 }}
{{- end }}
envFrom:
- configMapRef:
name: {{ .Release.Name }}-st2-urls
- secretRef:
name: {{ include "stackstorm-ha.secrets.st2Auth" . }}
{{- range .Values.jobs.envFromSecrets }}
- secretRef:
name: {{ . }}
{{- end }}
volumeMounts:
- name: st2client-config-vol
mountPath: /root/.st2/
# `st2 login` doesn't exit on failure correctly, use old methods instead. See bug: https://github.com/StackStorm/st2/issues/4338
command:
- 'sh'
- '-ec'
- |
cat <<EOT > /root/.st2/config
{{- tpl .Values.jobs.st2clientConfig . | nindent 12 }}
EOT
containers:
- name: st2-key-load
image: '{{ template "stackstorm-ha.imageRepository" . }}/st2actionrunner:{{ tpl (.Values.jobs.image.tag | default (.Values.st2actionrunner.image.tag | default .Values.image.tag)) . }}'
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- with .Values.securityContext }}
securityContext: {{- toYaml . | nindent 10 }}
{{- end }}
command:
- st2
- key
- load
- "--convert" # Convert non-string types (hash, array, boolean, int, float) to a JSON string before loading
- /etc/st2/st2kv.yaml
{{- if .Values.jobs.env }}
env: {{- include "stackstorm-ha.customEnv" .Values.jobs | nindent 8 }}
{{- end }}
envFrom:
- configMapRef:
name: {{ .Release.Name }}-st2-urls
{{- range .Values.jobs.envFromSecrets }}
- secretRef:
name: {{ . }}
{{- end }}
volumeMounts:
{{- include "stackstorm-ha.st2-config-volume-mounts" . | nindent 8 }}
- name: st2client-config-vol
mountPath: /root/.st2/
- name: st2-kv-vol
mountPath: /etc/st2/st2kv.yaml
subPath: st2kv.yaml
{{- range $.Values.jobs.extra_volumes }}
- name: {{ required "Each volume must have a 'name' in jobs.extra_volumes" .name }}
{{- tpl (required "Each volume must have a 'mount' definition in jobs.extra_volumes" .mount | toYaml) $ | nindent 10 }}
{{- end }}
# TODO: Find out default resource limits for this specific service (#5)
#resources:
volumes:
{{- include "stackstorm-ha.st2-config-volume" . | nindent 8 }}
- name: st2client-config-vol
emptyDir:
medium: Memory
- name: st2-kv-vol
secret:
secretName: {{ .Release.Name }}-st2-kv
{{- range $.Values.jobs.extra_volumes }}
- name: {{ required "Each volume must have a 'name' in jobs.extra_volumes" .name }}
{{- tpl (required "Each volume must have a 'volume' definition in jobs.extra_volumes" .volume | toYaml) $ | nindent 10 }}
{{- end }}
restartPolicy: OnFailure
{{- if .Values.dnsPolicy }}
dnsPolicy: {{ .Values.dnsPolicy }}
{{- end }}
{{- with .Values.dnsConfig }}
dnsConfig: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.podSecurityContext }}
securityContext: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.jobs.nodeSelector }}
nodeSelector: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.jobs.affinity }}
affinity: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.jobs.tolerations }}
tolerations: {{- toYaml . | nindent 8 }}
{{- end }}
{{- end }}
{{- if not (.Values.jobs.skip | has "register_content") }}
---
apiVersion: batch/v1
kind: Job
metadata:
name: {{ .Release.Name }}-job-st2-register-content
labels: {{- include "stackstorm-ha.labels" (list $ "st2-register-content") | nindent 4 }}
annotations:
helm.sh/hook: post-install, post-upgrade, post-rollback
helm.sh/hook-delete-policy: before-hook-creation
helm.sh/hook-weight: "7"
{{- if .Values.jobs.annotations }}
{{- toYaml .Values.jobs.annotations | nindent 4 }}
{{- end }}
spec:
template:
metadata:
name: job-st2-register-content
labels: {{- include "stackstorm-ha.labels" (list $ "st2-register-content") | nindent 8 }}
annotations:
# TODO: Investigate/propose running Helm hook only on condition when ConfigMap or Secret has changed
checksum/config: {{ include (print $.Template.BasePath "/configmaps_st2-conf.yaml") . | sha256sum }}
checksum/packs: {{ include (print $.Template.BasePath "/configmaps_packs.yaml") . | sha256sum }}
{{- if .Values.st2.overrides }}
checksum/overrides: {{ include (print $.Template.BasePath "/configmaps_overrides.yaml") . | sha256sum }}
{{- end }}
{{- if .Values.jobs.annotations }}
{{- toYaml .Values.jobs.annotations | nindent 8 }}
{{- end }}
spec:
imagePullSecrets:
{{- if .Values.image.pullSecret }}
- name: {{ .Values.image.pullSecret }}
{{- end }}
{{- if $.Values.st2.packs.images -}}
{{- include "stackstorm-ha.packs-pullSecrets" . | nindent 6 }}
{{- end }}
initContainers:
{{- include "stackstorm-ha.init-containers-wait-for-db" . | nindent 6 }}
{{- include "stackstorm-ha.packs-initContainers" . | nindent 6 }}
{{- include "stackstorm-ha.cleanup-packs" . | nindent 6 }}
{{- if $.Values.jobs.preRegisterContentCommand }}
- name: st2-register-content-custom-init
image: '{{ template "stackstorm-ha.imageRepository" . }}/st2actionrunner:{{ tpl (.Values.jobs.image.tag | default (.Values.st2actionrunner.image.tag | default .Values.image.tag)) . }}'
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- with .Values.securityContext }}
securityContext: {{- toYaml . | nindent 10 }}
{{- end }}
command: {{- toYaml $.Values.jobs.preRegisterContentCommand | nindent 8 }}
volumeMounts:
{{- include "stackstorm-ha.overrides-config-mounts" . | nindent 8 }}
{{- include "stackstorm-ha.st2-config-volume-mounts" . | nindent 8 }}
{{- include "stackstorm-ha.pack-configs-volume-mount" . | nindent 8 }}
{{- include "stackstorm-ha.packs-volume-mounts-for-register-job" . | nindent 8 }}
{{ end }}
containers:
- name: st2-register-content
image: '{{ template "stackstorm-ha.imageRepository" . }}/st2actionrunner:{{ tpl (.Values.jobs.image.tag | default (.Values.st2actionrunner.image.tag | default .Values.image.tag)) . }}'
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- with .Values.securityContext }}
securityContext: {{- toYaml . | nindent 10 }}
{{- end }}
command:
- st2-register-content
{{- include "stackstorm-ha.st2-config-file-parameters" . | nindent 10 }}
- --register-all
- --register-fail-on-failure
{{- if .Values.jobs.env }}
env: {{- include "stackstorm-ha.customEnv" .Values.jobs | nindent 8 }}
{{- end }}
{{- if .Values.jobs.envFromSecrets }}
envFrom:
{{- range .Values.jobs.envFromSecrets }}
- secretRef:
name: {{ . }}
{{- end }}
{{- end }}
volumeMounts:
{{- include "stackstorm-ha.overrides-config-mounts" . | nindent 8 }}
{{- include "stackstorm-ha.st2-config-volume-mounts" . | nindent 8 }}
{{- include "stackstorm-ha.packs-volume-mounts-for-register-job" . | nindent 8 }}
{{- include "stackstorm-ha.pack-configs-volume-mount" . | nindent 8 }}
{{- range $.Values.jobs.extra_volumes }}
- name: {{ required "Each volume must have a 'name' in jobs.extra_volumes" .name }}
{{- tpl (required "Each volume must have a 'mount' definition in jobs.extra_volumes" .mount | toYaml) $ | nindent 10 }}
{{- end }}
# TODO: Find out default resource limits for this specific service (#5)
#resources:
volumes:
{{- include "stackstorm-ha.overrides-configs" . | nindent 8 }}
{{- include "stackstorm-ha.st2-config-volume" . | nindent 8 }}
{{- include "stackstorm-ha.packs-volumes" . | nindent 8 }}
{{- include "stackstorm-ha.pack-configs-volume" . | nindent 8 }}
- name: st2-cleanup-packs
configMap:
name: {{ .Release.Name }}-st2-cleanup-packs
defaultMode: 0777
{{- range $.Values.jobs.extra_volumes }}
- name: {{ required "Each volume must have a 'name' in jobs.extra_volumes" .name }}
{{- tpl (required "Each volume must have a 'volume' definition in jobs.extra_volumes" .volume | toYaml) $ | nindent 10 }}
{{- end }}
restartPolicy: OnFailure
{{- if .Values.dnsPolicy }}
dnsPolicy: {{ .Values.dnsPolicy }}
{{- end }}
{{- with .Values.dnsConfig }}
dnsConfig: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.podSecurityContext }}
securityContext: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.jobs.nodeSelector }}
nodeSelector: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.jobs.affinity }}
affinity: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.jobs.tolerations }}
tolerations: {{- toYaml . | nindent 8 }}
{{- end }}
{{- end }}
{{- if $.Values.st2.packs.volumes.enabled }}
---
apiVersion: batch/v1
kind: Job
metadata:
name: {{ $.Release.Name }}-job-ensure-packs-volumes-are-writable
labels: {{- include "stackstorm-ha.labels" (list $ "st2canary") | nindent 4 }}
annotations:
helm.sh/hook: pre-install, pre-upgrade, pre-rollback
helm.sh/hook-weight: "-5" # fairly high priority
helm.sh/hook-delete-policy: hook-succeeded
{{- if $.Values.jobs.annotations }}
{{- toYaml $.Values.jobs.annotations | nindent 4 }}
{{- end }}
spec:
template:
metadata:
name: job-st2canary-for-writable-packs-volumes
labels: {{- include "stackstorm-ha.labels" (list $ "st2canary") | nindent 8 }}
annotations:
{{- if $.Values.jobs.annotations }}
{{- toYaml $.Values.jobs.annotations | nindent 8 }}
{{- end }}
spec:
imagePullSecrets:
{{- if $.Values.image.pullSecret }}
- name: {{ $.Values.image.pullSecret }}
{{- end }}
initContainers: []
containers:
- name: st2canary-for-writable-packs-volumes
image: '{{ template "stackstorm-ha.imageRepository" $ }}/st2actionrunner:{{ tpl $.Values.image.tag $ }}'
imagePullPolicy: {{ $.Values.image.pullPolicy }}
{{- with $.Values.securityContext }}
securityContext: {{- toYaml . | nindent 10 }}
{{- end }}
# TODO: maybe use kubectl to assert the volumes have RWX mode
# If volume is a persistentVolumeClaim, then:
# the PVC must only have ReadWriteMany in spec.accessModes
# If volume is something else, then validating through metadata is iffy.
# azureFile, cephfs, csi, glusterfs, nfs, pvc, quobyte, need at least:
# readOnly: false
# ephemeral volumes could also work, ... but that config is even deeper.
command:
- 'sh'
# -e => exit on failure
# -E => trap ERR is inherited in subfunctions
- '-eEc'
- |
cat << 'INTRO'
Testing write permissions for packs volumes.
If this passes, the pod will automatically be deleted.
If this fails, inspect the pod for errors in kubernetes,
and then delete this st2canary pod manually.
INTRO
function __handle_error__(){
cat <<- 'FAIL'
ERROR: One or more volumes in st2.packs.volumes (from helm values) does not meet
StackStorm's shared volumes requirements!
see: https://github.com/StackStorm/stackstorm-k8s#method-2-shared-volumes
HINT: The volumes defined in st2.packs.volumes must use ReadWriteMany (RWX) access mode
so StackStorm can dynamically install packs from any of the st2actionrunner pods
and have those file changes available in all of the other StackStorm pods.
see: https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes
FAIL
}
trap __handle_error__ ERR
for volume in packs virtualenvs {{ if $.Values.st2.packs.volumes.configs }}configs{{ end }}; do
echo Testing write permissions on ${volume} volume...
touch /opt/stackstorm/${volume}/.write-test
rm /opt/stackstorm/${volume}/.write-test
echo
done
echo DONE
volumeMounts:
{{- include "stackstorm-ha.packs-volume-mounts" $ | nindent 8 }}
{{/* do not include the pack-configs-volume-mount helper here */}}
- name: st2-pack-configs-vol
mountPath: /opt/stackstorm/configs/
readOnly: false
# TODO: Find out default resource limits for this specific job (#5)
#resources:
volumes:
{{- include "stackstorm-ha.packs-volumes" $ | nindent 8 }}
{{- if $.Values.st2.packs.volumes.configs }}
{{/* do not include the pack-configs-volume helper here */}}
- name: st2-pack-configs-vol
{{- toYaml $.Values.st2.packs.volumes.configs | nindent 10 }}
{{- end }}
# st2canary job does not support extra_volumes. Let us know if you need this.
{{- if $.Values.dnsPolicy }}
dnsPolicy: {{ $.Values.dnsPolicy }}
{{- end }}
{{- with $.Values.dnsConfig }}
dnsConfig: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with $.Values.podSecurityContext }}
securityContext: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with $.Values.jobs.nodeSelector }}
nodeSelector: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with $.Values.jobs.affinity }}
affinity: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with $.Values.jobs.tolerations }}
tolerations: {{- toYaml . | nindent 8 }}
{{- end }}
{{- end }}
{{- range .Values.jobs.extra_hooks -}}
{{- $name := print "extra-helm-hook" (include "stackstorm-ha.hyphenPrefix" (required "You must name each entry in jobs.extra_hooks." .name)) }}
{{- if not ($.Values.jobs.skip | has $name) }}
---
apiVersion: batch/v1
kind: Job
metadata:
name: {{ $.Release.Name }}-job-{{ $name }}
labels: {{- include "stackstorm-ha.labels" (list $ $name) | nindent 4 }}
annotations:
helm.sh/hook: {{ required "Each entry in jobs.extra_hooks must include 'hook' (the helm.sh/hook value)" .hook }}
helm.sh/hook-delete-policy: before-hook-creation
helm.sh/hook-weight: {{ .hook_weight | default 10 | toString | quote }}
{{- if $.Values.jobs.annotations }}
{{- toYaml $.Values.jobs.annotations | nindent 4 }}
{{- end }}
spec:
template:
metadata:
name: job-{{ $name }}
labels: {{- include "stackstorm-ha.labels" (list $ $name) | nindent 8 }}
annotations:
checksum/config: {{ include (print $.Template.BasePath "/configmaps_st2-conf.yaml") $ | sha256sum }}
checksum/packs: {{ include (print $.Template.BasePath "/configmaps_packs.yaml") $ | sha256sum }}
{{- if $.Values.st2.overrides }}
checksum/overrides: {{ include (print $.Template.BasePath "/configmaps_overrides.yaml") $ | sha256sum }}
{{- end }}
{{- if $.Values.jobs.annotations }}
{{- toYaml $.Values.jobs.annotations | nindent 8 }}
{{- end }}
spec:
imagePullSecrets:
{{- if $.Values.image.pullSecret }}
- name: {{ $.Values.image.pullSecret }}
{{- end }}
{{- if $.Values.st2.packs.images -}}
{{- include "stackstorm-ha.packs-pullSecrets" $ | nindent 6 }}
{{- end }}
initContainers:
{{- include "stackstorm-ha.init-containers-wait-for-db" $ | nindent 6 }}
{{- include "stackstorm-ha.packs-initContainers" $ | nindent 6 }}
- name: generate-st2client-config
image: '{{ template "stackstorm-ha.imageRepository" $ }}/st2actionrunner:{{ tpl ($.Values.jobs.image.tag | default ($.Values.st2actionrunner.image.tag | default $.Values.image.tag)) $ }}'
imagePullPolicy: {{ $.Values.image.pullPolicy }}
{{- with $.Values.securityContext }}
securityContext: {{- toYaml . | nindent 10 }}
{{- end }}
envFrom:
- configMapRef:
name: {{ $.Release.Name }}-st2-urls
- secretRef:
name: {{ include "stackstorm-ha.secrets.st2Auth" $ }}
{{- range $.Values.jobs.envFromSecrets }}
- secretRef:
name: {{ . }}
{{- end }}
volumeMounts:
- name: st2client-config-vol
mountPath: /root/.st2/
# `st2 login` doesn't exit on failure correctly, use old methods instead. See bug: https://github.com/StackStorm/st2/issues/4338
command:
- 'sh'
- '-ec'
- |
cat <<EOT > /root/.st2/config
{{- tpl $.Values.jobs.st2clientConfig $ | nindent 12 }}
EOT
containers:
- name: {{ $name }}
image: '{{ template "stackstorm-ha.imageRepository" $ }}/st2actionrunner:{{ tpl ($.Values.jobs.image.tag | default ($.Values.st2actionrunner.image.tag | default $.Values.image.tag)) $ }}'
imagePullPolicy: {{ $.Values.image.pullPolicy }}
{{- with $.Values.securityContext }}
securityContext: {{- toYaml . | nindent 10 }}
{{- end }}
{{- if $.Values.jobs.env }}
env: {{- include "stackstorm-ha.customEnv" $.Values.jobs | nindent 8 }}
{{- end }}
envFrom:
- configMapRef:
name: {{ $.Release.Name }}-st2-urls
{{- range $.Values.jobs.envFromSecrets }}
- secretRef:
name: {{ . }}
{{- end }}
command:
{{- range (required "Each entry in jobs.extra_hooks must include the 'command' to run." .command) }}
{{- tpl . $ | list | toYaml | nindent 10 }}
{{- end }}
volumeMounts:
- name: st2client-config-vol
mountPath: /root/.st2/
{{- include "stackstorm-ha.overrides-config-mounts" $ | nindent 8 }}
{{- include "stackstorm-ha.st2-config-volume-mounts" $ | nindent 8 }}
{{- include "stackstorm-ha.packs-volume-mounts-for-register-job" $ | nindent 8 }}
{{- include "stackstorm-ha.pack-configs-volume-mount" $ | nindent 8 }}
{{- range $.Values.jobs.extra_volumes }}
- name: {{ required "Each volume must have a 'name' in jobs.extra_volumes" .name }}
{{- tpl (required "Each volume must have a 'mount' definition in jobs.extra_volumes" .mount | toYaml) $ | nindent 10 }}
{{- end }}
{{- if .resources }}
resources: {{- toYaml .resources | nindent 10 }}
{{- end }}
volumes:
- name: st2client-config-vol
emptyDir:
medium: Memory
{{- include "stackstorm-ha.overrides-configs" $ | nindent 8 }}
{{- include "stackstorm-ha.st2-config-volume" $ | nindent 8 }}
{{- include "stackstorm-ha.packs-volumes" $ | nindent 8 }}
{{- include "stackstorm-ha.pack-configs-volume" $ | nindent 8 }}
{{- range $.Values.jobs.extra_volumes }}
- name: {{ required "Each volume must have a 'name' in jobs.extra_volumes" .name }}
{{- tpl (required "Each volume must have a 'volume' definition in jobs.extra_volumes" .volume | toYaml) $ | nindent 10 }}
{{- end }}
restartPolicy: OnFailure
{{- if $.Values.dnsPolicy }}
dnsPolicy: {{ $.Values.dnsPolicy }}
{{- end }}
{{- with $.Values.dnsConfig }}
dnsConfig: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with $.Values.podSecurityContext }}
securityContext: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with $.Values.jobs.nodeSelector }}
nodeSelector: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with $.Values.jobs.affinity }}
affinity: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with $.Values.jobs.tolerations }}
tolerations: {{- toYaml . | nindent 8 }}
{{- end }}
{{- end }}
{{- end }}