2026-01-30 11:58:25 +05:30

142 lines
5.6 KiB
YAML

apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "schedulerservice.fullname" . }}
labels:
{{- include "schedulerservice.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "schedulerservice.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "schedulerservice.labels" . | nindent 8 }}
{{- with .Values.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "schedulerservice.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
initContainers:
# 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&amp;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 ${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
echo "MySQL is fully initialized!"
env:
- name: MYSQL_PASSWORD
valueFrom:
secretKeyRef:
name: {{ .Release.Namespace }}-os-schedules-argo-syncer-mysql
key: mysql-password
volumeMounts:
- name: db-config
mountPath: /db-config
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: {{ .Values.service.targetPort }}
protocol: TCP
{{- if .Values.livenessProbe }}
livenessProbe:
{{- toYaml .Values.livenessProbe | nindent 12 }}
{{- end }}
{{- if .Values.readinessProbe }}
readinessProbe:
{{- toYaml .Values.readinessProbe | nindent 12 }}
{{- end }}
{{- if .Values.startupProbe }}
startupProbe:
{{- toYaml .Values.startupProbe | nindent 12 }}
{{- end }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
volumeMounts:
{{- if .Values.config.enabled }}
- name: config
mountPath: {{ .Values.config.mountPath }}
{{- end }}
- name: db-config
mountPath: /etc/onlinesales/config/schedulerService/hibernate.cfg.xml
subPath: hibernate.cfg.xml
readOnly: true
{{- with .Values.env }}
env:
{{- toYaml . | nindent 12 }}
{{- end }}
volumes:
{{- if .Values.config.enabled }}
- name: config
configMap:
name: {{ include "schedulerservice.fullname" . }}-config
{{- end }}
- name: db-config
emptyDir: {}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}