From e99dfc1c8422a2b2cc3e29264d8ce8f45e89e754 Mon Sep 17 00:00:00 2001 From: Ruslan Aliev Date: Tue, 14 Jun 2022 15:34:34 -0500 Subject: [PATCH] Add run migrator job prior running grafana pods During the first run, grafana will run migrator job, which populates necessary fields in database. Previously, if there are two or more grafana pods which start up simultaneously, it causes the race condition for database access and finally one of the pods will fail (in some cases both of them), leaving the grafana database in incomplete state. Signed-off-by: Ruslan Aliev Change-Id: I5a7993b3cad2d48af3f73218d6c61c216520e1c5 --- grafana/Chart.yaml | 2 +- grafana/templates/bin/_grafana.sh.tpl | 20 ++- grafana/templates/job-run-migrator.yaml | 156 ++++++++++++++++++++++++ grafana/values.yaml | 22 ++++ grafana/values_overrides/apparmor.yaml | 3 + releasenotes/notes/grafana.yaml | 1 + 6 files changed, 200 insertions(+), 4 deletions(-) create mode 100644 grafana/templates/job-run-migrator.yaml diff --git a/grafana/Chart.yaml b/grafana/Chart.yaml index 46da6dfb2..c77b51ac4 100644 --- a/grafana/Chart.yaml +++ b/grafana/Chart.yaml @@ -15,7 +15,7 @@ apiVersion: v1 appVersion: v7.4.5 description: OpenStack-Helm Grafana name: grafana -version: 0.1.13 +version: 0.1.14 home: https://grafana.com/ sources: - https://github.com/grafana/grafana diff --git a/grafana/templates/bin/_grafana.sh.tpl b/grafana/templates/bin/_grafana.sh.tpl index db8c98bbf..0c5ad8fdb 100644 --- a/grafana/templates/bin/_grafana.sh.tpl +++ b/grafana/templates/bin/_grafana.sh.tpl @@ -13,15 +13,29 @@ See the License for the specific language governing permissions and limitations under the License. */}} -set -ex +set -exo pipefail COMMAND="${@:-start}" +PORT={{ tuple "grafana" "internal" "grafana" . | include "helm-toolkit.endpoints.endpoint_port_lookup" }} +PIDFILE=/tmp/pid function start () { - exec /usr/share/grafana/bin/grafana-server -homepath=/usr/share/grafana -config=/etc/grafana/grafana.ini + exec /usr/share/grafana/bin/grafana-server -homepath=/usr/share/grafana -config=/etc/grafana/grafana.ini --pidfile="$PIDFILE" +} + +function run_migrator () { + start & + timeout 60 bash -c "until timeout 5 bash -c '