28893199 by Adam Heath

Proper initContainers for wait-for-pg/wait-for-elasticsearch.

1 parent 3b159690
#!/bin/sh
set -ex
elasticsearch_timeout=${elasticsearch_timeout:-3}
check_es() {
status="$(curl -o /dev/null -w "%{http_code}" --max-time ${elasticsearch_timeout} -XGET -g -s -k -u "${elasticsearch_user}:${elasticsearch_password}" "${elasticsearch_url}")"
if [ "z$status" = z200 ]; then
return 0
fi
return 1
}
while ! check_es; do
echo "Waiting for Elasticsearch" 1>&2
sleep 1
count=5
while [ $count -gt 0 ] && ! check_es; do
count=$(($count - 1))
sleep 1
done
done
......@@ -4,3 +4,10 @@ kind: Kustomization
resources:
- ./elasticsearch.yaml
configMapGenerator:
- name: moqui-elasticsearch-scripts
files:
- ./es_isready
options:
disableNameSuffixHash: true
......
......@@ -7,7 +7,6 @@ resources:
configMapGenerator:
- name: moqui-scripts
files:
- ./pg_isready
- ./copy-jdbc-drivers
options:
disableNameSuffixHash: true
......
......@@ -4,3 +4,10 @@ kind: Kustomization
resources:
- ./postgresql.yaml
configMapGenerator:
- name: moqui-postgresql-scripts
files:
- ./pg_isready
options:
disableNameSuffixHash: true
......
......@@ -51,6 +51,69 @@ releases:
- name: moqui-jdbc-drivers
newName: localhost:31234/moqui-jdbc-drivers
newTag: test-latest
jsonPatches:
- target:
group: apps
version: v1
kind: Deployment
name: {{ .Values.name }}-moqui-app
namespace: {{ .Values.namespace }}
patch:
{{- if .Values.postgresql.enabled }}
- op: add
path: /spec/template/spec/volumes/-
value:
name: postgresql-scripts
configMap:
name: {{ .Values.name }}-moqui-postgresql-scripts
defaultMode: 0755
- op: add
path: /spec/template/spec/initContainers/-
value:
name: wait-for-pg
image: registry.opensource.zalan.do/acid/spilo-14:2.1-p6
command: ["/postgresql-scripts/pg_isready"]
volumeMounts:
- name: postgresql-scripts
mountPath: /postgresql-scripts
env:
- name: POSTGRES_HOST
value: {{ .Values.name }}-moqui-postgresql
- name: POSTGRES_USER
valueFrom:
secretKeyRef:
name: moqui.{{ .Values.name }}-moqui-postgresql.credentials.postgresql.acid.zalan.do
key: username
{{- end }}
{{- if .Values.elasticsearch.enabled }}
- op: add
path: /spec/template/spec/volumes/-
value:
name: elasticsearch-scripts
configMap:
name: {{ .Values.name }}-moqui-elasticsearch-scripts
defaultMode: 0755
- op: add
path: /spec/template/spec/initContainers/-
value:
name: wait-for-elasticsearch
image: localhost:31234/moqui-app:test-latest
command: ["/elasticsearch-scripts/es_isready"]
volumeMounts:
- name: elasticsearch-scripts
mountPath: /elasticsearch-scripts
env:
- name: elasticsearch_url
value: https://{{ .Values.name }}-moqui-es-http:9200
- name: elasticsearch_user
value: elastic
- name: elasticsearch_password
valueFrom:
secretKeyRef:
name: {{ .Values.name }}-moqui-es-elastic-user
key: elastic
{{- end }}
strategicMergePatches:
- apiVersion: apps/v1
kind: Deployment
......