Skip to content

Commit 808b83d

Browse files
authored
Merge pull request #178 from arms11/pods-wait-for-db-mq-availability
Introduced initContainers to wait for DB/MQ availability
2 parents 428edb5 + 2d0862d commit 808b83d

File tree

4 files changed

+79
-4
lines changed

4 files changed

+79
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Changelog
22

33
## In Development
4+
* Implemented initContainers to wait for DB/MQ to be available for St2 Pods (#178)
45
* Add option to define config.js for st2web (#165) (by @moonrail)
56

67
## v0.51.0

templates/_helpers.tpl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,36 @@ Create the name of the stackstorm-ha service account to use
9494
{{- end -}}
9595
{{- end -}}
9696

97+
{{- define "init-containers-wait-for-db" -}}
98+
{{- if index .Values "mongodb" "enabled" }}
99+
{{- $mongodb_port := (int (index .Values "mongodb" "service" "port")) }}
100+
- name: wait-for-db
101+
image: busybox:1.28
102+
command:
103+
- 'sh'
104+
- '-c'
105+
- >
106+
until nc -z -w 2 {{ $.Release.Name }}-mongodb-headless {{ $mongodb_port }} && echo mongodb ok;
107+
do
108+
echo 'Waiting for MongoDB Connection...'
109+
sleep 2;
110+
done
111+
{{- end }}
112+
{{- end -}}
113+
114+
{{- define "init-containers-wait-for-mq" -}}
115+
{{- if index .Values "rabbitmq" "enabled" }}
116+
{{- $rabbitmq_port := (int (index .Values "rabbitmq" "service" "port")) }}
117+
- name: wait-for-queue
118+
image: busybox:1.28
119+
command:
120+
- 'sh'
121+
- '-c'
122+
- >
123+
until nc -z -w 2 {{ $.Release.Name }}-rabbitmq {{ $rabbitmq_port }} && echo rabbitmq ok;
124+
do
125+
echo 'Waiting for RabbitMQ Connection...'
126+
sleep 2;
127+
done
128+
{{- end }}
129+
{{- end -}}

templates/deployments.yaml

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ spec:
4141
{{- if .Values.image.pullSecret }}
4242
- name: {{ .Values.image.pullSecret }}
4343
{{- end }}
44-
# Sidecar container for generating .htpasswd with st2 username & password pair and sharing produced file with the main st2auth container
4544
initContainers:
45+
{{ include "init-containers-wait-for-db" . | indent 6 }}
46+
{{ include "init-containers-wait-for-mq" . | indent 6 }}
47+
# Sidecar container for generating .htpasswd with st2 username & password pair and sharing produced file with the main st2auth container
4648
- name: generate-htpasswd
4749
image: "{{ template "imageRepository" . }}/st2auth{{ template "enterpriseSuffix" . }}:{{ .Chart.AppVersion }}"
4850
imagePullPolicy: {{ .Values.image.pullPolicy }}
@@ -158,8 +160,10 @@ spec:
158160
{{- if .Values.image.pullSecret }}
159161
- name: {{ .Values.image.pullSecret }}
160162
{{- end }}
161-
{{- if .Values.st2.packs.image.repository }}
162163
initContainers:
164+
{{ include "init-containers-wait-for-db" . | indent 6 }}
165+
{{ include "init-containers-wait-for-mq" . | indent 6 }}
166+
{{- if .Values.st2.packs.image.repository }}
163167
# Merge packs and virtualenvs from st2api with those from the st2.packs image
164168
# Custom packs
165169
- name: st2-custom-packs
@@ -302,6 +306,9 @@ spec:
302306
{{- if .Values.image.pullSecret }}
303307
- name: {{ .Values.image.pullSecret }}
304308
{{- end }}
309+
initContainers:
310+
{{ include "init-containers-wait-for-db" . | indent 6 }}
311+
{{ include "init-containers-wait-for-mq" . | indent 6 }}
305312
containers:
306313
- name: st2stream{{ template "enterpriseSuffix" . }}
307314
image: "{{ template "imageRepository" . }}/st2stream{{ template "enterpriseSuffix" . }}:{{ .Chart.AppVersion }}"
@@ -487,6 +494,9 @@ spec:
487494
{{- if .Values.image.pullSecret }}
488495
- name: {{ .Values.image.pullSecret }}
489496
{{- end }}
497+
initContainers:
498+
{{ include "init-containers-wait-for-db" . | indent 6 }}
499+
{{ include "init-containers-wait-for-mq" . | indent 6 }}
490500
containers:
491501
- name: st2rulesengine{{ template "enterpriseSuffix" . }}
492502
image: "{{ template "imageRepository" . }}/st2rulesengine{{ template "enterpriseSuffix" . }}:{{ .Chart.AppVersion }}"
@@ -577,6 +587,9 @@ spec:
577587
{{- if .Values.image.pullSecret }}
578588
- name: {{ .Values.image.pullSecret }}
579589
{{- end }}
590+
initContainers:
591+
{{ include "init-containers-wait-for-db" . | indent 6 }}
592+
{{ include "init-containers-wait-for-mq" . | indent 6 }}
580593
containers:
581594
- name: st2timersengine{{ template "enterpriseSuffix" . }}
582595
image: "{{ template "imageRepository" . }}/st2timersengine{{ template "enterpriseSuffix" . }}:{{ .Chart.AppVersion }}"
@@ -659,6 +672,9 @@ spec:
659672
{{- if .Values.image.pullSecret }}
660673
- name: {{ .Values.image.pullSecret }}
661674
{{- end }}
675+
initContainers:
676+
{{ include "init-containers-wait-for-db" . | indent 6 }}
677+
{{ include "init-containers-wait-for-mq" . | indent 6 }}
662678
containers:
663679
- name: st2workflowengine{{ template "enterpriseSuffix" . }}
664680
image: "{{ template "imageRepository" . }}/st2workflowengine{{ template "enterpriseSuffix" . }}:{{ .Chart.AppVersion }}"
@@ -753,6 +769,9 @@ spec:
753769
{{- if .Values.image.pullSecret }}
754770
- name: {{ .Values.image.pullSecret }}
755771
{{- end }}
772+
initContainers:
773+
{{ include "init-containers-wait-for-db" . | indent 6 }}
774+
{{ include "init-containers-wait-for-mq" . | indent 6 }}
756775
containers:
757776
- name: st2scheduler{{ template "enterpriseSuffix" . }}
758777
image: "{{ template "imageRepository" . }}/st2scheduler{{ template "enterpriseSuffix" . }}:{{ .Chart.AppVersion }}"
@@ -847,6 +866,9 @@ spec:
847866
{{- if .Values.image.pullSecret }}
848867
- name: {{ .Values.image.pullSecret }}
849868
{{- end }}
869+
initContainers:
870+
{{ include "init-containers-wait-for-db" . | indent 6 }}
871+
{{ include "init-containers-wait-for-mq" . | indent 6 }}
850872
containers:
851873
- name: st2notifier{{ template "enterpriseSuffix" . }}
852874
image: "{{ template "imageRepository" . }}/st2notifier{{ template "enterpriseSuffix" . }}:{{ .Chart.AppVersion }}"
@@ -939,8 +961,10 @@ spec:
939961
{{- if $.Values.image.pullSecret }}
940962
- name: {{ $.Values.image.pullSecret }}
941963
{{- end }}
942-
{{- if $.Values.st2.packs.image.repository }}
943964
initContainers:
965+
{{ include "init-containers-wait-for-db" $ | indent 6 }}
966+
{{ include "init-containers-wait-for-mq" $ | indent 6 }}
967+
{{- if $.Values.st2.packs.image.repository }}
944968
# Merge packs and virtualenvs from st2sensorcontainer with those from the st2.packs image
945969
# Custom packs
946970
- name: st2-custom-packs
@@ -1108,8 +1132,10 @@ spec:
11081132
{{- if .Values.image.pullSecret }}
11091133
- name: {{ .Values.image.pullSecret }}
11101134
{{- end }}
1111-
{{- if .Values.st2.packs.image.repository }}
11121135
initContainers:
1136+
{{ include "init-containers-wait-for-db" . | indent 6 }}
1137+
{{ include "init-containers-wait-for-mq" . | indent 6 }}
1138+
{{- if .Values.st2.packs.image.repository }}
11131139
# Merge packs and virtualenvs from st2actionrunner with those from the st2.packs image
11141140
# Custom packs
11151141
- name: st2-custom-packs
@@ -1259,6 +1285,9 @@ spec:
12591285
{{- if .Values.image.pullSecret }}
12601286
- name: {{ .Values.image.pullSecret }}
12611287
{{- end }}
1288+
initContainers:
1289+
{{ include "init-containers-wait-for-db" . | indent 6 }}
1290+
{{ include "init-containers-wait-for-mq" . | indent 6 }}
12621291
containers:
12631292
- name: st2garbagecollector{{ template "enterpriseSuffix" . }}
12641293
image: "{{ template "imageRepository" . }}/st2garbagecollector{{ template "enterpriseSuffix" . }}:{{ .Chart.AppVersion }}"

templates/jobs.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,16 @@ spec:
121121
- name: {{ .Values.image.pullSecret }}
122122
{{- end }}
123123
initContainers:
124+
{{ include "init-containers-wait-for-db" . | indent 6 }}
125+
- name: wait-for-api
126+
image: busybox:1.28
127+
command:
128+
- 'sh'
129+
- '-c'
130+
- >
131+
until nc -z -w 2 {{ .Release.Name }}-st2api 9101 && echo st2api ready;
132+
do sleep 2;
133+
done
124134
# Sidecar container for generating st2client config with st2 username & password pair and sharing produced file with the main container
125135
- name: generate-st2client-config
126136
image: "{{ template "imageRepository" . }}/st2actionrunner{{ template "enterpriseSuffix" . }}:{{ .Chart.AppVersion }}"
@@ -223,6 +233,7 @@ spec:
223233
- name: {{ .Values.image.pullSecret }}
224234
{{- end }}
225235
initContainers:
236+
{{ include "init-containers-wait-for-db" . | indent 6 }}
226237
# Sidecar container for generating st2client config with st2 username & password pair and sharing produced file with the main container
227238
- name: generate-st2client-config
228239
image: "{{ template "imageRepository" . }}/st2actionrunner{{ template "enterpriseSuffix" . }}:{{ .Chart.AppVersion }}"
@@ -338,6 +349,7 @@ spec:
338349
{{- end }}
339350
{{- if .Values.st2.packs.image.repository }}
340351
initContainers:
352+
{{ include "init-containers-wait-for-db" . | indent 6 }}
341353
# Merge packs and virtualenvs from st2actionrunner with those from the st2.packs image
342354
# Custom packs
343355
- name: st2-custom-packs

0 commit comments

Comments
 (0)