diff --git a/examples/mysql-persistent-template.json b/examples/mysql-persistent-template.json index 96962404..e2c2216f 100644 --- a/examples/mysql-persistent-template.json +++ b/examples/mysql-persistent-template.json @@ -119,6 +119,62 @@ } }, "spec": { + "initContainers": [ + { + "name": "mysql-init", + "image": " ", + "command": [ "/usr/bin/run-mysqld", "init" ], + "env": [ + { + "name": "MYSQL_USER", + "valueFrom": { + "secretKeyRef" : { + "name" : "${DATABASE_SERVICE_NAME}", + "key" : "database-user" + } + } + }, + { + "name": "MYSQL_PASSWORD", + "valueFrom": { + "secretKeyRef" : { + "name" : "${DATABASE_SERVICE_NAME}", + "key" : "database-password" + } + } + }, + { + "name": "MYSQL_ROOT_PASSWORD", + "valueFrom": { + "secretKeyRef" : { + "name" : "${DATABASE_SERVICE_NAME}", + "key" : "database-root-password" + } + } + }, + { + "name": "MYSQL_DATABASE", + "valueFrom": { + "secretKeyRef" : { + "name" : "${DATABASE_SERVICE_NAME}", + "key" : "database-name" + } + } + } + ], + "resources": { + "limits": { + "memory": "${MEMORY_LIMIT}" + } + }, + "volumeMounts": [ + { + "name": "${DATABASE_SERVICE_NAME}-data", + "mountPath": "/var/lib/mysql/data" + } + ] + } + ], "containers": [ { "name": "mysql", diff --git a/root-common/usr/bin/run-mysqld b/root-common/usr/bin/run-mysqld index 36d5bf80..629da498 100755 --- a/root-common/usr/bin/run-mysqld +++ b/root-common/usr/bin/run-mysqld @@ -1,5 +1,7 @@ #!/bin/bash +init_only=false && [ "$1" == "init" ] && init_only=true && shift + export_vars=$(cgroup-limits); export $export_vars source ${CONTAINER_SCRIPTS_PATH}/common.sh set -eu @@ -20,6 +22,10 @@ else start_local_mysql "$@" fi +if $init_only; then + exit 0 +fi + # set mysql_flags and admin_flagsadmin_flags properly if [ -z "${MYSQL_ROOT_PASSWORD:-}" ] || is_allowing_connection_with_empty_password; then mysql_flags="-u root --socket=$MYSQL_LOCAL_SOCKET"