Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## In Development
* Implemented initContainers to wait for DB/MQ to be available for St2 Pods (#178)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI I moved this changelog under the In Development section.

* Add option to define config.js for st2web (#165) (by @moonrail)

## v0.51.0
Expand Down
33 changes: 33 additions & 0 deletions templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,36 @@ Create the name of the stackstorm-ha service account to use
{{- end -}}
{{- end -}}

{{- define "init-containers-wait-for-db" -}}
{{- if index .Values "mongodb" "enabled" }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just thought about that edge case. Perfect to have it already codified here 👍

{{- $mongodb_port := (int (index .Values "mongodb" "service" "port")) }}
- name: wait-for-db
image: busybox:1.28
command:
- 'sh'
- '-c'
- >
until nc -z -w 2 {{ $.Release.Name }}-mongodb-headless {{ $mongodb_port }} && echo mongodb ok;
do
echo 'Waiting for MongoDB Connection...'
sleep 2;
done
{{- end }}
{{- end -}}

{{- define "init-containers-wait-for-mq" -}}
{{- if index .Values "rabbitmq" "enabled" }}
{{- $rabbitmq_port := (int (index .Values "rabbitmq" "service" "port")) }}
- name: wait-for-queue
image: busybox:1.28
command:
- 'sh'
- '-c'
- >
until nc -z -w 2 {{ $.Release.Name }}-rabbitmq {{ $rabbitmq_port }} && echo rabbitmq ok;
do
echo 'Waiting for RabbitMQ Connection...'
sleep 2;
done
{{- end }}
{{- end -}}
37 changes: 33 additions & 4 deletions templates/deployments.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ spec:
{{- if .Values.image.pullSecret }}
- name: {{ .Values.image.pullSecret }}
{{- end }}
# Sidecar container for generating .htpasswd with st2 username & password pair and sharing produced file with the main st2auth container
initContainers:
{{ include "init-containers-wait-for-db" . | indent 6 }}
{{ include "init-containers-wait-for-mq" . | indent 6 }}
# Sidecar container for generating .htpasswd with st2 username & password pair and sharing produced file with the main st2auth container
- name: generate-htpasswd
image: "{{ template "imageRepository" . }}/st2auth{{ template "enterpriseSuffix" . }}:{{ .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
Expand Down Expand Up @@ -158,8 +160,10 @@ spec:
{{- if .Values.image.pullSecret }}
- name: {{ .Values.image.pullSecret }}
{{- end }}
{{- if .Values.st2.packs.image.repository }}
initContainers:
{{ include "init-containers-wait-for-db" . | indent 6 }}
{{ include "init-containers-wait-for-mq" . | indent 6 }}
{{- if .Values.st2.packs.image.repository }}
# Merge packs and virtualenvs from st2api with those from the st2.packs image
# Custom packs
- name: st2-custom-packs
Expand Down Expand Up @@ -302,6 +306,9 @@ spec:
{{- if .Values.image.pullSecret }}
- name: {{ .Values.image.pullSecret }}
{{- end }}
initContainers:
{{ include "init-containers-wait-for-db" . | indent 6 }}
{{ include "init-containers-wait-for-mq" . | indent 6 }}
containers:
- name: st2stream{{ template "enterpriseSuffix" . }}
image: "{{ template "imageRepository" . }}/st2stream{{ template "enterpriseSuffix" . }}:{{ .Chart.AppVersion }}"
Expand Down Expand Up @@ -487,6 +494,9 @@ spec:
{{- if .Values.image.pullSecret }}
- name: {{ .Values.image.pullSecret }}
{{- end }}
initContainers:
{{ include "init-containers-wait-for-db" . | indent 6 }}
{{ include "init-containers-wait-for-mq" . | indent 6 }}
containers:
- name: st2rulesengine{{ template "enterpriseSuffix" . }}
image: "{{ template "imageRepository" . }}/st2rulesengine{{ template "enterpriseSuffix" . }}:{{ .Chart.AppVersion }}"
Expand Down Expand Up @@ -577,6 +587,9 @@ spec:
{{- if .Values.image.pullSecret }}
- name: {{ .Values.image.pullSecret }}
{{- end }}
initContainers:
{{ include "init-containers-wait-for-db" . | indent 6 }}
{{ include "init-containers-wait-for-mq" . | indent 6 }}
containers:
- name: st2timersengine{{ template "enterpriseSuffix" . }}
image: "{{ template "imageRepository" . }}/st2timersengine{{ template "enterpriseSuffix" . }}:{{ .Chart.AppVersion }}"
Expand Down Expand Up @@ -659,6 +672,9 @@ spec:
{{- if .Values.image.pullSecret }}
- name: {{ .Values.image.pullSecret }}
{{- end }}
initContainers:
{{ include "init-containers-wait-for-db" . | indent 6 }}
{{ include "init-containers-wait-for-mq" . | indent 6 }}
containers:
- name: st2workflowengine{{ template "enterpriseSuffix" . }}
image: "{{ template "imageRepository" . }}/st2workflowengine{{ template "enterpriseSuffix" . }}:{{ .Chart.AppVersion }}"
Expand Down Expand Up @@ -753,6 +769,9 @@ spec:
{{- if .Values.image.pullSecret }}
- name: {{ .Values.image.pullSecret }}
{{- end }}
initContainers:
{{ include "init-containers-wait-for-db" . | indent 6 }}
{{ include "init-containers-wait-for-mq" . | indent 6 }}
containers:
- name: st2scheduler{{ template "enterpriseSuffix" . }}
image: "{{ template "imageRepository" . }}/st2scheduler{{ template "enterpriseSuffix" . }}:{{ .Chart.AppVersion }}"
Expand Down Expand Up @@ -847,6 +866,9 @@ spec:
{{- if .Values.image.pullSecret }}
- name: {{ .Values.image.pullSecret }}
{{- end }}
initContainers:
{{ include "init-containers-wait-for-db" . | indent 6 }}
{{ include "init-containers-wait-for-mq" . | indent 6 }}
containers:
- name: st2notifier{{ template "enterpriseSuffix" . }}
image: "{{ template "imageRepository" . }}/st2notifier{{ template "enterpriseSuffix" . }}:{{ .Chart.AppVersion }}"
Expand Down Expand Up @@ -939,8 +961,10 @@ spec:
{{- if $.Values.image.pullSecret }}
- name: {{ $.Values.image.pullSecret }}
{{- end }}
{{- if $.Values.st2.packs.image.repository }}
initContainers:
{{ include "init-containers-wait-for-db" $ | indent 6 }}
{{ include "init-containers-wait-for-mq" $ | indent 6 }}
{{- if $.Values.st2.packs.image.repository }}
# Merge packs and virtualenvs from st2sensorcontainer with those from the st2.packs image
# Custom packs
- name: st2-custom-packs
Expand Down Expand Up @@ -1108,8 +1132,10 @@ spec:
{{- if .Values.image.pullSecret }}
- name: {{ .Values.image.pullSecret }}
{{- end }}
{{- if .Values.st2.packs.image.repository }}
initContainers:
{{ include "init-containers-wait-for-db" . | indent 6 }}
{{ include "init-containers-wait-for-mq" . | indent 6 }}
{{- if .Values.st2.packs.image.repository }}
# Merge packs and virtualenvs from st2actionrunner with those from the st2.packs image
# Custom packs
- name: st2-custom-packs
Expand Down Expand Up @@ -1259,6 +1285,9 @@ spec:
{{- if .Values.image.pullSecret }}
- name: {{ .Values.image.pullSecret }}
{{- end }}
initContainers:
{{ include "init-containers-wait-for-db" . | indent 6 }}
{{ include "init-containers-wait-for-mq" . | indent 6 }}
containers:
- name: st2garbagecollector{{ template "enterpriseSuffix" . }}
image: "{{ template "imageRepository" . }}/st2garbagecollector{{ template "enterpriseSuffix" . }}:{{ .Chart.AppVersion }}"
Expand Down
12 changes: 12 additions & 0 deletions templates/jobs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@ spec:
- name: {{ .Values.image.pullSecret }}
{{- end }}
initContainers:
{{ include "init-containers-wait-for-db" . | indent 6 }}
- name: wait-for-api
image: busybox:1.28
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 "imageRepository" . }}/st2actionrunner{{ template "enterpriseSuffix" . }}:{{ .Chart.AppVersion }}"
Expand Down Expand Up @@ -223,6 +233,7 @@ spec:
- name: {{ .Values.image.pullSecret }}
{{- end }}
initContainers:
{{ include "init-containers-wait-for-db" . | indent 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 "imageRepository" . }}/st2actionrunner{{ template "enterpriseSuffix" . }}:{{ .Chart.AppVersion }}"
Expand Down Expand Up @@ -338,6 +349,7 @@ spec:
{{- end }}
{{- if .Values.st2.packs.image.repository }}
initContainers:
{{ include "init-containers-wait-for-db" . | indent 6 }}
# Merge packs and virtualenvs from st2actionrunner with those from the st2.packs image
# Custom packs
- name: st2-custom-packs
Expand Down