From 4d5337daaf3a4e4d94c2105fa9da73b29f450f9b Mon Sep 17 00:00:00 2001 From: Teodoro Cook Date: Fri, 30 Jun 2023 19:58:43 -0600 Subject: [PATCH] Limit retries during metabase init script (#42) * Update values file example and docs * Adjust retries/timeout for metabase hook script * Move hook scripts to bash shell * Refactor kafkaconnector names --- README.md | 16 ++++++----- charts/dataplane/templates/metabase/hook.yaml | 28 ++++++++++++++++--- charts/dataplane/templates/registry/hook.yaml | 2 +- .../templates/strimzi/connector.yaml | 2 +- values.minimal.yml | 9 +++--- 5 files changed, 39 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index cbfbdf2..2b6dcdf 100644 --- a/README.md +++ b/README.md @@ -26,19 +26,21 @@ This is an example values definition for replicating pagila db: ``` metabase: admin: - email: metabase@nephelai.io - password: dataplane + email: metabase@nephelai.io ingress: - enabled: true - className: nginx-private - hostName: metabase.nephelai.io + enabled: true + className: nginx-private + hostName: metabase.nephelai.io cdc: postgres: - hostname: pagilahost - port: 5432 id: pagila dbname: pagila - signaling: True + exclude: + - "public.staff" + partitions: + - source: "public.payment.*" + sink: "payment" strimzi: connect: secret: "metabase-pagila-db" diff --git a/charts/dataplane/templates/metabase/hook.yaml b/charts/dataplane/templates/metabase/hook.yaml index 69c2f88..61d7913 100644 --- a/charts/dataplane/templates/metabase/hook.yaml +++ b/charts/dataplane/templates/metabase/hook.yaml @@ -55,31 +55,46 @@ spec: key: password command: - - "sh" + - "bash" - "-c" - >- set -ex echo "[$(date -Iseconds)] [INFO] [metabase-setup] waiting for metabase service"; + retries=10; until \ curl -s \ -H "X-Forwarded-Host: $MB_SITE_URL" \ -H "X-Forwarded-Proto: $MB_SITE_PROTO" \ http://{{ $svcName }}:{{ $svcPort }}/ -o /dev/null; do echo "[$(date -Iseconds)] [INFO] [metabase-setup] waiting for metabase service"; - sleep 10; + if (( retries > 0 )); then + retries=$(( retries - 1 )); + sleep 30; + else + echo "[$(date -Iseconds)] [ERROR] [metabase-setup] metabase service failed to start"; + exit 1; + fi done; echo "[$(date -Iseconds)] [INFO] [metabase-setup] retrieve metabase setup token"; + retries=10; until [[ ${setup_token:-""} != "" ]]; do setup_token=$(curl -s -X GET \ -H "X-Forwarded-Host: $MB_SITE_URL" \ -H "X-Forwarded-Proto: $MB_SITE_PROTO" \ http://{{ $svcName }}:{{ $svcPort }}/api/session/properties | jq '.["setup-token"]' -r); + if (( retries > 0 )); then + retries=$(( retries - 1 )); + sleep 30; + else + echo "[$(date -Iseconds)] [ERROR] [metabase-setup] unable to retrieve metabase setup token"; + exit 1; + fi done; retries=10; response_code=""; echo "[$(date -Iseconds)] [INFO] [metabase-setup] initial metabase setup start"; response_header=$(mktemp); - until [[ "$response_code" == "200" || "$response_code" == "403" || "$retries" == "0" ]]; do + until [[ "$response_code" == "200" || "$response_code" == "403" ]]; do response_body=$(curl -s -D $response_header -X POST \ -H "Content-Type: application/json" \ -H "X-Forwarded-Host: $MB_SITE_URL" \ @@ -119,7 +134,12 @@ spec: }" \ http://{{ $svcName }}:{{ $svcPort }}/api/setup); response_code=$(cat $response_header | grep ^HTTP | awk '{print $2}'); - retries=$(($retries - 1)); + if (( retries > 0 )); then + retries=$(( retries - 1 )); + else + echo "[$(date -Iseconds)] [ERROR] [metabase-setup] unable to initialize metabase"; + exit 1; + fi if [[ "$response_code" != "200" && "$response_code" != "403" ]]; then echo "$response_body (response_code=$response_code)"; sleep 30; diff --git a/charts/dataplane/templates/registry/hook.yaml b/charts/dataplane/templates/registry/hook.yaml index 11ba456..03f407d 100644 --- a/charts/dataplane/templates/registry/hook.yaml +++ b/charts/dataplane/templates/registry/hook.yaml @@ -24,7 +24,7 @@ spec: resources: {{- toYaml .Values.util.resources | nindent 12 }} command: - - "sh" + - "bash" - "-c" - >- until curl -s http://{{ $svcName }}:{{ $svcPort }}/ -o /dev/null; do diff --git a/charts/dataplane/templates/strimzi/connector.yaml b/charts/dataplane/templates/strimzi/connector.yaml index 401de33..bf12846 100644 --- a/charts/dataplane/templates/strimzi/connector.yaml +++ b/charts/dataplane/templates/strimzi/connector.yaml @@ -4,7 +4,7 @@ {{- range $db := .Values.cdc.postgres }} {{- $dbId := required "database id is required" $db.id }} -{{- $dbConnectorName := lower (printf "%s-%s-%s" $fullName $dbId $db.dbname) }} +{{- $dbConnectorName := lower (printf "%s-%s" $fullName $dbId) }} {{- $dbSlotName := $dbConnectorName | replace "-" "_" }} {{- $exclude := list }} {{- $include := list }} diff --git a/values.minimal.yml b/values.minimal.yml index 0025a63..6d50906 100644 --- a/values.minimal.yml +++ b/values.minimal.yml @@ -1,12 +1,11 @@ --- metabase: admin: - email: metabase@nephelai.io - password: dataplane + email: metabase@nephelai.io ingress: - enabled: true - className: nginx-private - hostName: metabase.nephelai.io + enabled: true + className: nginx-private + hostName: metabase.nephelai.io cdc: postgres: - hostname: pagilahost