From 54058f0a35e8f13b9a7e778f0a39b034fe313dac Mon Sep 17 00:00:00 2001 From: Pan Luo Date: Mon, 12 Dec 2022 16:25:35 -0800 Subject: [PATCH] Switch to wait4x to wait for db There is a bug related to nslookup in busybox (https://github.com/docker-library/busybox/issues/48). nslookup doesn't return 0 when one of the hostname+domain suffix failed to resolve. The suffix are listed in /etc/resolve.conf. e.g. default.svc.cluster.local svc.cluster.local cluster.local Also checking DNS doesn't mean service is up. wait4x will try to make connection and valid the servie is up and running. --- compair/Chart.yaml | 2 +- compair/templates/compair-deployment.yaml | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/compair/Chart.yaml b/compair/Chart.yaml index 7fe788c..d13cc7b 100644 --- a/compair/Chart.yaml +++ b/compair/Chart.yaml @@ -6,7 +6,7 @@ keywords: - peer learning - education name: compair -version: 0.9.0 +version: 0.9.1 appVersion: 1.2.13 home: http://ubc.github.io/compair/ sources: diff --git a/compair/templates/compair-deployment.yaml b/compair/templates/compair-deployment.yaml index 951c4fc..676202e 100644 --- a/compair/templates/compair-deployment.yaml +++ b/compair/templates/compair-deployment.yaml @@ -273,9 +273,23 @@ spec: {{- end }} initContainers: - name: wait-for-db-service - image: busybox - command: ["sh", "-c", "until nslookup {{ template "fullname" . }}-db; do echo waiting for {{ template "fullname" . }}-db; sleep 2; done;"] + image: atkrad/wait4x + command: ["sh", "-c", "wait4x", "mysql", "${DB_USERNAME}:${DB_PASSWORD}@tcp(${DB_HOST}:${DB_PORT})/${DB_NAME}"] imagePullPolicy: {{ .Values.app.image.pullPolicy }} + env: + - name: DB_HOST + value: "{{ template "fullname" . }}-db" + - name: DB_PORT + value: {{ .Values.dbPort | quote }} + - name: DB_USERNAME + value: {{ .Values.dbUsername | quote }} + - name: DB_PASSWORD + valueFrom: + secretKeyRef: + name: {{ template "fullname" . }} + key: mysql_password + - name: DB_NAME + value: {{ .Values.dbName | quote }} - name: init-db image: "{{ .Values.app.image.repository }}:{{ .Values.app.image.tag }}" command: ["sh", "-c", "python manage.py database create {{ if .Values.demoInstance }}--sample_data{{ end }}"]