mysql issue fix 1
This commit is contained in:
parent
03d088b692
commit
f7c1ed5830
@ -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 <<EOF
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE hibernate-configuration PUBLIC
|
||||
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
|
||||
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
|
||||
<hibernate-configuration>
|
||||
<session-factory>
|
||||
<property name="connection.driver_class">com.mysql.cj.jdbc.Driver</property>
|
||||
<property name="connection.url">jdbc:mysql://${MYSQL_HOST}:${MYSQL_PORT}/${MYSQL_DB}?useUnicode=true&characterEncoding=utf8</property>
|
||||
<property name="connection.username">${MYSQL_USER}</property>
|
||||
<property name="connection.password">${MYSQL_PASSWORD}</property>
|
||||
<property name="connection.pool_size">1</property>
|
||||
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
|
||||
<property name="current_session_context_class">thread</property>
|
||||
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
|
||||
<property name="show_sql">false</property>
|
||||
<property name="connection.isolation">2</property>
|
||||
<property name="connection.autocommit">true</property>
|
||||
</session-factory>
|
||||
</hibernate-configuration>
|
||||
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 }}
|
||||
|
||||
@ -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: |
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE hibernate-configuration PUBLIC
|
||||
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
|
||||
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
|
||||
<hibernate-configuration>
|
||||
<session-factory>
|
||||
<property name="connection.driver_class">com.mysql.cj.jdbc.Driver</property>
|
||||
<property name="connection.url">jdbc:mysql://{{ $dbHost }}:{{ .Values.externalDatabase.port }}/{{ .Values.externalDatabase.database }}?useUnicode=true&characterEncoding=utf8</property>
|
||||
<property name="connection.username">{{ .Values.externalDatabase.username }}</property>
|
||||
<property name="connection.password">{{ .Values.externalDatabase.password }}</property>
|
||||
<property name="connection.pool_size">1</property>
|
||||
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
|
||||
<property name="current_session_context_class">thread</property>
|
||||
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
|
||||
<property name="show_sql">false</property>
|
||||
<!-- Transaction isolation 2 = READ_COMMITTED -->
|
||||
<property name="connection.isolation">2</property>
|
||||
<property name="connection.autocommit">true</property>
|
||||
</session-factory>
|
||||
</hibernate-configuration>
|
||||
{{- end }}
|
||||
Loading…
x
Reference in New Issue
Block a user