diff --git a/mariadb/templates/bin/_stop.sh.tpl b/mariadb/templates/bin/_stop.sh.tpl new file mode 100644 index 0000000000..c197065a0d --- /dev/null +++ b/mariadb/templates/bin/_stop.sh.tpl @@ -0,0 +1,24 @@ +#!/bin/bash +{{/* +Copyright 2017 The Openstack-Helm Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/}} + +set -xe + +exec mysqladmin \ + --defaults-file=/etc/mysql/admin_user.cnf \ + --host=localhost \ + --connect-timeout 2 \ + shutdown diff --git a/mariadb/templates/configmap-bin.yaml b/mariadb/templates/configmap-bin.yaml index 25168fe46e..0570aaecfa 100644 --- a/mariadb/templates/configmap-bin.yaml +++ b/mariadb/templates/configmap-bin.yaml @@ -26,4 +26,6 @@ data: {{ tuple "bin/_readiness.sh.tpl" . | include "helm-toolkit.utils.template" | indent 4 }} start.sh: | {{ tuple "bin/_start.sh.tpl" . | include "helm-toolkit.utils.template" | indent 4 }} + stop.sh: | +{{ tuple "bin/_stop.sh.tpl" . | include "helm-toolkit.utils.template" | indent 4 }} {{- end }} diff --git a/mariadb/templates/statefulset.yaml b/mariadb/templates/statefulset.yaml index 62c02083cd..36206f68e7 100644 --- a/mariadb/templates/statefulset.yaml +++ b/mariadb/templates/statefulset.yaml @@ -62,8 +62,6 @@ spec: image: {{ .Values.images.tags.mariadb }} imagePullPolicy: {{ .Values.images.pull_policy }} {{ tuple $envAll $envAll.Values.pod.resources.server | include "helm-toolkit.snippets.kubernetes_resources" | indent 10 }} - command: - - /tmp/start.sh env: - name: POD_IP valueFrom: @@ -90,6 +88,13 @@ spec: secretKeyRef: name: mariadb-db-root-password key: MYSQL_ROOT_PASSWORD + command: + - /tmp/start.sh + lifecycle: + preStop: + exec: + command: + - /tmp/stop.sh readinessProbe: initialDelaySeconds: 30 periodSeconds: 30 @@ -100,14 +105,18 @@ spec: volumeMounts: - name: mycnfd mountPath: /etc/mysql/conf.d - - name: mariadb-bin - mountPath: /tmp/readiness.sh - subPath: readiness.sh - readOnly: true - name: mariadb-bin mountPath: /tmp/start.sh subPath: start.sh readOnly: true + - name: mariadb-bin + mountPath: /tmp/stop.sh + subPath: stop.sh + readOnly: true + - name: mariadb-bin + mountPath: /tmp/readiness.sh + subPath: readiness.sh + readOnly: true - name: mariadb-etc mountPath: /etc/mysql/my.cnf subPath: my.cnf