init job fix

This commit is contained in:
Vaibhav Pathak 2026-02-24 10:11:35 +05:30
parent 9c094a62fe
commit 9eff07d2db

View File

@ -287,7 +287,14 @@ spec:
DB_INIT_SQL="${DB_INIT_SQL}
FLUSH PRIVILEGES;"
# Format SQL for YAML embedding (20 spaces indent for content under init-databases.sql: |)
DB_INIT_SQL_FORMATTED=$(echo "$DB_INIT_SQL" | sed 's/^/ /')
# Create ArgoCD Application for shared MySQL
# Write the SQL to a temp file for insertion
INIT_SQL_FILE="/tmp/init-sql-$$.txt"
echo "$DB_INIT_SQL_FORMATTED" > "$INIT_SQL_FILE"
cat > "manifests/${INSTANCE_NAME}-application.yaml" <<EOF
apiVersion: argoproj.io/v1alpha1
kind: Application
@ -305,7 +312,7 @@ spec:
source:
repoURL: https://helm.wso2.com
chart: mysql
targetRevision: "1.6.9"
targetRevision: "$VERSION"
helm:
values: |
image: mysql
@ -314,6 +321,9 @@ spec:
mysqlUser: "mysql_user"
mysqlPassword: "local-mysql-pass"
fullnameOverride: "$INSTANCE_NAME"
initializationFiles:
init-databases.sql: |
INIT_SQL_PLACEHOLDER
persistence:
enabled: true
size: 8Gi
@ -333,6 +343,17 @@ spec:
- ServerSideApply=true
EOF
# Replace placeholder with actual SQL content using awk
awk -v sqlfile="$INIT_SQL_FILE" '
/INIT_SQL_PLACEHOLDER/ {
while ((getline line < sqlfile) > 0) print line
next
}
{ print }
' "manifests/${INSTANCE_NAME}-application.yaml" > "manifests/${INSTANCE_NAME}-application.yaml.tmp"
mv "manifests/${INSTANCE_NAME}-application.yaml.tmp" "manifests/${INSTANCE_NAME}-application.yaml"
rm -f "$INIT_SQL_FILE"
echo "Created ArgoCD Application for $INSTANCE_NAME"
done