28893199 by Adam Heath

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

1 parent 3b159690
1 #!/bin/sh
2 set -ex
3
4 elasticsearch_timeout=${elasticsearch_timeout:-3}
5
6 check_es() {
7 status="$(curl -o /dev/null -w "%{http_code}" --max-time ${elasticsearch_timeout} -XGET -g -s -k -u "${elasticsearch_user}:${elasticsearch_password}" "${elasticsearch_url}")"
8 if [ "z$status" = z200 ]; then
9 return 0
10 fi
11 return 1
12 }
13
14 while ! check_es; do
15 echo "Waiting for Elasticsearch" 1>&2
16 sleep 1
17 count=5
18 while [ $count -gt 0 ] && ! check_es; do
19 count=$(($count - 1))
20 sleep 1
21 done
22 done
...@@ -4,3 +4,10 @@ kind: Kustomization ...@@ -4,3 +4,10 @@ kind: Kustomization
4 resources: 4 resources:
5 - ./elasticsearch.yaml 5 - ./elasticsearch.yaml
6 6
7 configMapGenerator:
8 - name: moqui-elasticsearch-scripts
9 files:
10 - ./es_isready
11 options:
12 disableNameSuffixHash: true
13
......
...@@ -7,7 +7,6 @@ resources: ...@@ -7,7 +7,6 @@ resources:
7 configMapGenerator: 7 configMapGenerator:
8 - name: moqui-scripts 8 - name: moqui-scripts
9 files: 9 files:
10 - ./pg_isready
11 - ./copy-jdbc-drivers 10 - ./copy-jdbc-drivers
12 options: 11 options:
13 disableNameSuffixHash: true 12 disableNameSuffixHash: true
......
...@@ -4,3 +4,10 @@ kind: Kustomization ...@@ -4,3 +4,10 @@ kind: Kustomization
4 resources: 4 resources:
5 - ./postgresql.yaml 5 - ./postgresql.yaml
6 6
7 configMapGenerator:
8 - name: moqui-postgresql-scripts
9 files:
10 - ./pg_isready
11 options:
12 disableNameSuffixHash: true
13
......
...@@ -51,6 +51,69 @@ releases: ...@@ -51,6 +51,69 @@ releases:
51 - name: moqui-jdbc-drivers 51 - name: moqui-jdbc-drivers
52 newName: localhost:31234/moqui-jdbc-drivers 52 newName: localhost:31234/moqui-jdbc-drivers
53 newTag: test-latest 53 newTag: test-latest
54 jsonPatches:
55 - target:
56 group: apps
57 version: v1
58 kind: Deployment
59 name: {{ .Values.name }}-moqui-app
60 namespace: {{ .Values.namespace }}
61 patch:
62 {{- if .Values.postgresql.enabled }}
63 - op: add
64 path: /spec/template/spec/volumes/-
65 value:
66 name: postgresql-scripts
67 configMap:
68 name: {{ .Values.name }}-moqui-postgresql-scripts
69 defaultMode: 0755
70 - op: add
71 path: /spec/template/spec/initContainers/-
72 value:
73 name: wait-for-pg
74 image: registry.opensource.zalan.do/acid/spilo-14:2.1-p6
75 command: ["/postgresql-scripts/pg_isready"]
76 volumeMounts:
77 - name: postgresql-scripts
78 mountPath: /postgresql-scripts
79 env:
80 - name: POSTGRES_HOST
81 value: {{ .Values.name }}-moqui-postgresql
82 - name: POSTGRES_USER
83 valueFrom:
84 secretKeyRef:
85 name: moqui.{{ .Values.name }}-moqui-postgresql.credentials.postgresql.acid.zalan.do
86 key: username
87 {{- end }}
88 {{- if .Values.elasticsearch.enabled }}
89 - op: add
90 path: /spec/template/spec/volumes/-
91 value:
92 name: elasticsearch-scripts
93 configMap:
94 name: {{ .Values.name }}-moqui-elasticsearch-scripts
95 defaultMode: 0755
96 - op: add
97 path: /spec/template/spec/initContainers/-
98 value:
99 name: wait-for-elasticsearch
100 image: localhost:31234/moqui-app:test-latest
101 command: ["/elasticsearch-scripts/es_isready"]
102 volumeMounts:
103 - name: elasticsearch-scripts
104 mountPath: /elasticsearch-scripts
105 env:
106 - name: elasticsearch_url
107 value: https://{{ .Values.name }}-moqui-es-http:9200
108 - name: elasticsearch_user
109 value: elastic
110 - name: elasticsearch_password
111 valueFrom:
112 secretKeyRef:
113 name: {{ .Values.name }}-moqui-es-elastic-user
114 key: elastic
115 {{- end }}
116
54 strategicMergePatches: 117 strategicMergePatches:
55 - apiVersion: apps/v1 118 - apiVersion: apps/v1
56 kind: Deployment 119 kind: Deployment
......