diff --git a/helm/schedulerservice/templates/deployment.yaml b/helm/schedulerservice/templates/deployment.yaml index dc2231d..526b2f5 100644 --- a/helm/schedulerservice/templates/deployment.yaml +++ b/helm/schedulerservice/templates/deployment.yaml @@ -30,17 +30,45 @@ spec: serviceAccountName: {{ include "schedulerservice.serviceAccountName" . }} securityContext: {{- toYaml .Values.podSecurityContext | nindent 8 }} - {{- $dbHost := include "schedulerservice.dbHost" . }} - {{- if $dbHost }} initContainers: - - name: wait-for-mysql-init + # Generate hibernate.cfg.xml and wait for MySQL to be ready + - name: init-db-config image: mysql:5.7 command: - sh - -c - | + # Derive MySQL host from namespace + MYSQL_HOST="{{ .Release.Namespace }}-os-schedules-argo-syncer-mysql" + MYSQL_PORT="{{ .Values.externalDatabase.port }}" + MYSQL_DB="{{ .Values.externalDatabase.database }}" + MYSQL_USER="{{ .Values.externalDatabase.username }}" + + echo "Generating hibernate.cfg.xml..." + cat > /db-config/hibernate.cfg.xml < + + + + com.mysql.cj.jdbc.Driver + jdbc:mysql://${MYSQL_HOST}:${MYSQL_PORT}/${MYSQL_DB}?useUnicode=true&characterEncoding=utf8 + ${MYSQL_USER} + ${MYSQL_PASSWORD} + 1 + org.hibernate.dialect.MySQLDialect + thread + org.hibernate.cache.NoCacheProvider + false + 2 + true + + + EOF + echo "Waiting for MySQL to be fully initialized..." - until mysql -h {{ $dbHost }} -P {{ .Values.externalDatabase.port }} -u {{ .Values.externalDatabase.username }} -p${MYSQL_PASSWORD} -e "SELECT 1 FROM group_details LIMIT 1" {{ .Values.externalDatabase.database }} 2>/dev/null; do + until mysql -h ${MYSQL_HOST} -P ${MYSQL_PORT} -u ${MYSQL_USER} -p${MYSQL_PASSWORD} -e "SELECT 1 FROM group_details LIMIT 1" ${MYSQL_DB} 2>/dev/null; do echo "Waiting for database tables to be created..." sleep 5 done @@ -49,9 +77,11 @@ spec: - name: MYSQL_PASSWORD valueFrom: secretKeyRef: - name: {{ include "schedulerservice.fullname" . }}-db-config - key: password - {{- end }} + name: {{ .Release.Namespace }}-os-schedules-argo-syncer-mysql + key: mysql-password + volumeMounts: + - name: db-config + mountPath: /db-config containers: - name: {{ .Chart.Name }} securityContext: @@ -76,36 +106,27 @@ spec: {{- end }} resources: {{- toYaml .Values.resources | nindent 12 }} - {{- if or .Values.config.enabled $dbHost }} volumeMounts: {{- if .Values.config.enabled }} - name: config mountPath: {{ .Values.config.mountPath }} {{- end }} - {{- if $dbHost }} - name: db-config mountPath: /etc/onlinesales/config/schedulerService/hibernate.cfg.xml subPath: hibernate.cfg.xml readOnly: true - {{- end }} - {{- end }} {{- with .Values.env }} env: {{- toYaml . | nindent 12 }} {{- end }} - {{- if or .Values.config.enabled $dbHost }} volumes: {{- if .Values.config.enabled }} - name: config configMap: name: {{ include "schedulerservice.fullname" . }}-config {{- end }} - {{- if $dbHost }} - name: db-config - secret: - secretName: {{ include "schedulerservice.fullname" . }}-db-config - {{- end }} - {{- end }} + emptyDir: {} {{- with .Values.nodeSelector }} nodeSelector: {{- toYaml . | nindent 8 }} diff --git a/helm/schedulerservice/templates/secret-db.yaml b/helm/schedulerservice/templates/secret-db.yaml deleted file mode 100644 index 3744dbd..0000000 --- a/helm/schedulerservice/templates/secret-db.yaml +++ /dev/null @@ -1,33 +0,0 @@ -{{- $dbHost := include "schedulerservice.dbHost" . }} -{{- if $dbHost }} -apiVersion: v1 -kind: Secret -metadata: - name: {{ include "schedulerservice.fullname" . }}-db-config - labels: - {{- include "schedulerservice.labels" . | nindent 4 }} -type: Opaque -stringData: - password: {{ .Values.externalDatabase.password | quote }} - hibernate.cfg.xml: | - - - - - com.mysql.cj.jdbc.Driver - jdbc:mysql://{{ $dbHost }}:{{ .Values.externalDatabase.port }}/{{ .Values.externalDatabase.database }}?useUnicode=true&characterEncoding=utf8 - {{ .Values.externalDatabase.username }} - {{ .Values.externalDatabase.password }} - 1 - org.hibernate.dialect.MySQLDialect - thread - org.hibernate.cache.NoCacheProvider - false - - 2 - true - - -{{- end }}