From 0b54e0983d08f4e5d471c220a8e8f65e6539234b Mon Sep 17 00:00:00 2001 From: Vaibhav Pathak Date: Fri, 30 Jan 2026 11:27:28 +0530 Subject: [PATCH] mysql issue fix --- catalog-info.yaml | 3 +-- helm/schedulerservice/templates/_helpers.tpl | 21 +++++++++++++++++++ .../templates/deployment.yaml | 13 ++++++------ .../schedulerservice/templates/secret-db.yaml | 5 +++-- helm/schedulerservice/values-local.yaml | 7 ++++--- helm/schedulerservice/values.yaml | 2 ++ 6 files changed, 38 insertions(+), 13 deletions(-) diff --git a/catalog-info.yaml b/catalog-info.yaml index 1200d89..c3932ff 100644 --- a/catalog-info.yaml +++ b/catalog-info.yaml @@ -19,8 +19,7 @@ metadata: { "mysql": { "source": "os-schedules-argo-syncer", - "helmParam": "externalDatabase.host", - "serviceSuffix": "-mysql" + "helmParam": "externalDatabase.mysqlRelease" } } tags: diff --git a/helm/schedulerservice/templates/_helpers.tpl b/helm/schedulerservice/templates/_helpers.tpl index d504264..f77e21c 100644 --- a/helm/schedulerservice/templates/_helpers.tpl +++ b/helm/schedulerservice/templates/_helpers.tpl @@ -61,3 +61,24 @@ Create the name of the service account to use {{- default "default" .Values.serviceAccount.name }} {{- end }} {{- end }} + +{{/* +Get the effective database host +Returns host if set, otherwise derives from mysqlRelease if set +*/}} +{{- define "schedulerservice.dbHost" -}} +{{- if .Values.externalDatabase.host }} +{{- .Values.externalDatabase.host }} +{{- else if .Values.externalDatabase.mysqlRelease }} +{{- printf "%s-mysql" .Values.externalDatabase.mysqlRelease }} +{{- end }} +{{- end }} + +{{/* +Check if database config is enabled (host or mysqlRelease is set) +*/}} +{{- define "schedulerservice.dbEnabled" -}} +{{- if or .Values.externalDatabase.host .Values.externalDatabase.mysqlRelease }} +{{- true }} +{{- end }} +{{- end }} diff --git a/helm/schedulerservice/templates/deployment.yaml b/helm/schedulerservice/templates/deployment.yaml index fdae37c..31f9ef5 100644 --- a/helm/schedulerservice/templates/deployment.yaml +++ b/helm/schedulerservice/templates/deployment.yaml @@ -30,7 +30,8 @@ spec: serviceAccountName: {{ include "schedulerservice.serviceAccountName" . }} securityContext: {{- toYaml .Values.podSecurityContext | nindent 8 }} - {{- if .Values.externalDatabase.host }} + {{- $dbHost := include "schedulerservice.dbHost" . }} + {{- if $dbHost }} initContainers: - name: wait-for-mysql-init image: mysql:5.7 @@ -39,7 +40,7 @@ spec: - -c - | echo "Waiting for MySQL to be fully initialized..." - until mysql -h {{ .Values.externalDatabase.host }} -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 {{ $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 echo "Waiting for database tables to be created..." sleep 5 done @@ -75,13 +76,13 @@ spec: {{- end }} resources: {{- toYaml .Values.resources | nindent 12 }} - {{- if or .Values.config.enabled .Values.externalDatabase.host }} + {{- if or .Values.config.enabled $dbHost }} volumeMounts: {{- if .Values.config.enabled }} - name: config mountPath: {{ .Values.config.mountPath }} {{- end }} - {{- if .Values.externalDatabase.host }} + {{- if $dbHost }} - name: db-config mountPath: /etc/onlinesales/db readOnly: true @@ -91,14 +92,14 @@ spec: env: {{- toYaml . | nindent 12 }} {{- end }} - {{- if or .Values.config.enabled .Values.externalDatabase.host }} + {{- if or .Values.config.enabled $dbHost }} volumes: {{- if .Values.config.enabled }} - name: config configMap: name: {{ include "schedulerservice.fullname" . }}-config {{- end }} - {{- if .Values.externalDatabase.host }} + {{- if $dbHost }} - name: db-config secret: secretName: {{ include "schedulerservice.fullname" . }}-db-config diff --git a/helm/schedulerservice/templates/secret-db.yaml b/helm/schedulerservice/templates/secret-db.yaml index 6da6318..3744dbd 100644 --- a/helm/schedulerservice/templates/secret-db.yaml +++ b/helm/schedulerservice/templates/secret-db.yaml @@ -1,4 +1,5 @@ -{{- if .Values.externalDatabase.host }} +{{- $dbHost := include "schedulerservice.dbHost" . }} +{{- if $dbHost }} apiVersion: v1 kind: Secret metadata: @@ -16,7 +17,7 @@ stringData: com.mysql.cj.jdbc.Driver - jdbc:mysql://{{ .Values.externalDatabase.host }}:{{ .Values.externalDatabase.port }}/{{ .Values.externalDatabase.database }}?useUnicode=true&characterEncoding=utf8 + jdbc:mysql://{{ $dbHost }}:{{ .Values.externalDatabase.port }}/{{ .Values.externalDatabase.database }}?useUnicode=true&characterEncoding=utf8 {{ .Values.externalDatabase.username }} {{ .Values.externalDatabase.password }} 1 diff --git a/helm/schedulerservice/values-local.yaml b/helm/schedulerservice/values-local.yaml index d4844d6..fcef555 100644 --- a/helm/schedulerservice/values-local.yaml +++ b/helm/schedulerservice/values-local.yaml @@ -101,10 +101,11 @@ env: - name: LOG_LEVEL value: "DEBUG" -# External Database - auto-injected by Backstage from os-schedules-argo-syncer -# Backstage resolves: {namespace}-os-schedules-argo-syncer-mysql +# External Database - connects to os-schedules-argo-syncer's MySQL subchart +# mysqlRelease auto-derives host as {mysqlRelease}-mysql externalDatabase: - host: "" # Auto-injected by Backstage dependency system + host: "" # Leave empty to use mysqlRelease-derived host + mysqlRelease: "" # Set by Backstage: {namespace}-os-schedules-argo-syncer port: "3306" database: "os_scheduling_db" username: "scheduler_user" diff --git a/helm/schedulerservice/values.yaml b/helm/schedulerservice/values.yaml index 9170eff..45809fb 100644 --- a/helm/schedulerservice/values.yaml +++ b/helm/schedulerservice/values.yaml @@ -133,8 +133,10 @@ env: [] # External Database configuration # MySQL is deployed as a shared dependency (not a subchart) # Set externalDatabase.host to connect to the shared MySQL instance +# Or set externalDatabase.mysqlRelease to auto-derive host as {mysqlRelease}-mysql externalDatabase: host: "" + mysqlRelease: "" # If set, derives host as {mysqlRelease}-mysql port: "3306" database: "os_scheduling_db" username: "scheduler_user"