hades-chart/hades/templates/deployment.yaml
2026-02-24 12:13:32 +05:30

184 lines
6.5 KiB
YAML

apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "hades.fullname" . }}
labels:
{{- include "hades.labels" . | nindent 4 }}
annotations:
# ArgoCD sync wave - run after dbinit job (wave 0)
argocd.argoproj.io/sync-wave: "1"
# Stakater Reloader - auto restart on ConfigMap/Secret changes
reloader.stakater.com/auto: "true"
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "hades.selectorLabels" . | nindent 6 }}
template:
metadata:
annotations:
checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
{{- with .Values.podAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "hades.selectorLabels" . | nindent 8 }}
{{- with .Values.commonLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "hades.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
initContainers:
# Wait for MySQL to be ready
- name: wait-for-mysql
image: busybox:1.36
command:
- sh
- -c
- |
echo "Waiting for MySQL to be ready..."
until nc -z {{ include "hades.databaseHost" . }} {{ include "hades.databasePort" . }}; do
echo "MySQL is unavailable - sleeping"
sleep 2
done
echo "MySQL is up - waiting a bit more for it to fully initialize..."
sleep 10
echo "MySQL is ready!"
# Wait for database migrations to complete
- name: wait-for-db-migrations
image: mysql:8.0
env:
- name: MYSQL_HOST
value: {{ include "hades.databaseHost" . | quote }}
- name: MYSQL_PORT
value: {{ include "hades.databasePort" . | quote }}
- name: MYSQL_DATABASE
value: {{ include "hades.databaseName" . | quote }}
- name: MYSQL_USER
value: {{ include "hades.databaseUsername" . | quote }}
- name: MYSQL_PWD
valueFrom:
secretKeyRef:
name: {{ include "hades.databaseSecretName" . }}
key: mysql-password
command:
- sh
- -c
- |
echo "Checking if database migrations have been applied..."
# Wait for MySQL to accept connections
until mysql -h"${MYSQL_HOST}" -P"${MYSQL_PORT}" -u"${MYSQL_USER}" -e "SELECT 1" "${MYSQL_DATABASE}" &> /dev/null; do
echo "Waiting for MySQL to accept connections..."
sleep 2
done
# Check if tables exist (basic migration check)
echo "Verifying database schema..."
TABLE_COUNT=$(mysql -h"${MYSQL_HOST}" -P"${MYSQL_PORT}" -u"${MYSQL_USER}" "${MYSQL_DATABASE}" -sN -e "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema='${MYSQL_DATABASE}';")
if [ "$TABLE_COUNT" -gt 0 ]; then
echo "✓ Database migrations completed - found $TABLE_COUNT tables"
else
echo "⚠ Warning: No tables found in database. Migrations may not have completed yet."
echo "Waiting 10 seconds for migrations to apply..."
sleep 10
fi
echo "Database is ready for application startup!"
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 }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
env:
{{- range .Values.env }}
- name: {{ .name }}
value: {{ .value | quote }}
{{- end }}
# Database connection environment variables
- name: DB_HOST
value: {{ include "hades.databaseHost" . | quote }}
- name: DB_PORT
value: {{ include "hades.databasePort" . | quote }}
- name: DB_NAME
value: {{ include "hades.databaseName" . | quote }}
- name: DB_USERNAME
value: {{ include "hades.databaseUsername" . | quote }}
- name: DB_PASSWORD
valueFrom:
secretKeyRef:
name: {{ include "hades.databaseSecretName" . }}
key: mysql-password
- name: JDBC_URL
value: {{ include "hades.jdbcUrl" . | quote }}
# Hibernate configuration
- name: HIBERNATE_DIALECT
value: "org.hibernate.dialect.MySQL5Dialect"
- name: HIBERNATE_SHOW_SQL
value: "false"
- name: HIBERNATE_HBM2DDL_AUTO
value: "validate"
{{- if or .Values.config.enabled .Values.allhosts.enabled }}
volumeMounts:
{{- if .Values.config.enabled }}
- name: config
mountPath: /etc/onlinesales/config/hades
readOnly: true
{{- end }}
{{- if .Values.allhosts.enabled }}
- name: allhosts
mountPath: /etc/onlinesales/config/allhosts/allhosts.tsv
subPath: allhosts.tsv
readOnly: true
{{- end }}
{{- end }}
{{- if or .Values.config.enabled .Values.allhosts.enabled }}
volumes:
{{- if .Values.config.enabled }}
- name: config
configMap:
name: {{ include "hades.fullname" . }}-config
{{- end }}
{{- if .Values.allhosts.enabled }}
- name: allhosts
configMap:
name: {{ include "hades.fullname" . }}-allhosts
{{- end }}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}