Skip to content

Commit f8ff91c

Browse files
authored
Merge pull request #382 from StackStorm/presleep
Presleep for st2auth, st2web, st2api, st2stream
2 parents 912dd75 + 6fd06a7 commit f8ff91c

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

templates/deployments.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ spec:
6060
- 'sh'
6161
- '-ec'
6262
- printf "${ST2_AUTH_USERNAME}:$(openssl passwd -apr1 "${ST2_AUTH_PASSWORD}")\n" > /tmp/st2/htpasswd
63+
terminationGracePeriodSeconds: {{ .Values.st2auth.terminationGracePeriodSeconds | default 30 }}
6364
containers:
6465
- name: st2auth
6566
image: '{{ template "stackstorm-ha.imageRepository" . }}/st2auth:{{ tpl (.Values.st2auth.image.tag | default .Values.image.tag) . }}'
@@ -96,6 +97,11 @@ spec:
9697
mountPath: /post-start.sh
9798
subPath: post-start.sh
9899
lifecycle:
100+
preStop:
101+
exec: # https://blog.laputa.io/graceful-shutdown-in-kubernetes-85f1c8d586da
102+
# kubeproxy and kubelet both race
103+
# wait a bit to ensure kubeproxy has removed the iptables rule.
104+
command: [ "sleep", {{ .Values.st2auth.preStopSleep | toString }} ]
99105
postStart:
100106
exec:
101107
command: ["/bin/bash", "/post-start.sh"]
@@ -179,6 +185,7 @@ spec:
179185
{{- if and .Values.st2.packs.images (not .Values.st2.packs.volumes.enabled) }}
180186
{{- include "stackstorm-ha.packs-initContainers" . | nindent 6 }}
181187
{{- end }}
188+
terminationGracePeriodSeconds: {{ .Values.st2api.terminationGracePeriodSeconds | default 30 }}
182189
containers:
183190
- name: st2api
184191
image: '{{ template "stackstorm-ha.imageRepository" . }}/st2api:{{ tpl (.Values.st2api.image.tag | default .Values.image.tag) . }}'
@@ -220,6 +227,11 @@ spec:
220227
mountPath: /post-start.sh
221228
subPath: post-start.sh
222229
lifecycle:
230+
preStop:
231+
exec: # https://blog.laputa.io/graceful-shutdown-in-kubernetes-85f1c8d586da
232+
# kubeproxy and kubelet both race
233+
# wait a bit to ensure kubeproxy has removed the iptables rule.
234+
command: [ "sleep", {{ .Values.st2api.preStopSleep | toString }} ]
223235
postStart:
224236
exec:
225237
command: ["/bin/bash", "/post-start.sh"]
@@ -305,6 +317,7 @@ spec:
305317
initContainers:
306318
{{- include "stackstorm-ha.init-containers-wait-for-db" . | nindent 6 }}
307319
{{- include "stackstorm-ha.init-containers-wait-for-mq" . | nindent 6 }}
320+
terminationGracePeriodSeconds: {{ .Values.st2stream.terminationGracePeriodSeconds | default 30 }}
308321
containers:
309322
- name: st2stream
310323
image: '{{ template "stackstorm-ha.imageRepository" . }}/st2stream:{{ tpl (.Values.st2stream.image.tag | default .Values.image.tag) . }}'
@@ -337,6 +350,11 @@ spec:
337350
mountPath: /post-start.sh
338351
subPath: post-start.sh
339352
lifecycle:
353+
preStop:
354+
exec: # https://blog.laputa.io/graceful-shutdown-in-kubernetes-85f1c8d586da
355+
# kubeproxy and kubelet both race
356+
# wait a bit to ensure kubeproxy has removed the iptables rule.
357+
command: [ "sleep", {{ .Values.st2stream.preStopSleep | toString }} ]
340358
postStart:
341359
exec:
342360
command: ["/bin/bash", "/post-start.sh"]
@@ -405,6 +423,7 @@ spec:
405423
{{- if .Values.image.pullSecret }}
406424
- name: {{ .Values.image.pullSecret }}
407425
{{- end }}
426+
terminationGracePeriodSeconds: {{ .Values.st2web.terminationGracePeriodSeconds | default 30 }}
408427
containers:
409428
- name: st2web
410429
image: '{{ template "stackstorm-ha.imageRepository" . }}/st2web:{{ tpl (.Values.st2web.image.tag | default .Values.image.tag) . }}'
@@ -457,6 +476,11 @@ spec:
457476
mountPath: /post-start.sh
458477
subPath: post-start.sh
459478
lifecycle:
479+
preStop:
480+
exec: # https://blog.laputa.io/graceful-shutdown-in-kubernetes-85f1c8d586da
481+
# kubeproxy and kubelet both race
482+
# wait a bit to ensure kubeproxy has removed the iptables rule.
483+
command: [ "sleep", {{ .Values.st2web.preStopSleep | toString }} ]
460484
postStart:
461485
exec:
462486
command: ["/bin/bash", "/post-start.sh"]

values.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ st2web:
381381
# The pod will not be marked as "running" until this script completes successfully.
382382
# see: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/
383383
postStartScript: ""
384+
preStopSleep: "10"
384385

385386
# https://docs.stackstorm.com/reference/ha.html#st2auth
386387
# Multiple st2auth processes can be behind a load balancer in an active-active configuration.
@@ -416,6 +417,7 @@ st2auth:
416417
# The pod will not be marked as "running" until this script completes successfully.
417418
# see: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/
418419
postStartScript: ""
420+
preStopSleep: "10"
419421
# mount extra volumes on the st2auth pod(s) (primarily useful for custom logging conf)
420422
## Note that Helm templating is supported in 'mount' and 'volume'
421423
extra_volumes: []
@@ -455,6 +457,7 @@ st2api:
455457
# The pod will not be marked as "running" until this script completes successfully.
456458
# see: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/
457459
postStartScript: ""
460+
preStopSleep: "10"
458461
# mount extra volumes on the st2api pod(s) (primarily useful for custom logging conf)
459462
## Note that Helm templating is supported in 'mount' and 'volume'
460463
extra_volumes: []
@@ -494,6 +497,7 @@ st2stream:
494497
# The pod will not be marked as "running" until this script completes successfully.
495498
# see: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/
496499
postStartScript: ""
500+
preStopSleep: "10"
497501
# mount extra volumes on the st2stream pod(s) (primarily useful for custom logging conf)
498502
## Note that Helm templating is supported in 'mount' and 'volume'
499503
extra_volumes: []

0 commit comments

Comments
 (0)