From 66dcf2f01091aa4d9c0b2295f01295a5ffec4c4f Mon Sep 17 00:00:00 2001 From: Aitor Carrera Date: Tue, 24 May 2022 15:29:21 +0100 Subject: [PATCH] Add pre-hook to check minimal version for customer package (#129) * Add pre-hook to check minimal version for customer package * remove comments * doc --- README.md | 12 +++++ chart/Chart.yaml | 3 ++ .../pre-upgrade-check-versions-cm.yaml | 28 ++++++++++++ .../pre-upgrade-check-versions-job.yaml | 44 +++++++++++++++++++ 4 files changed, 87 insertions(+) create mode 100644 chart/templates/pre-upgrade-check-versions-cm.yaml create mode 100644 chart/templates/pre-upgrade-check-versions-job.yaml diff --git a/README.md b/README.md index 2e8ecac4..a69d6882 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,18 @@ to configure the domain name. 6. Read and follow the instructions provided by the previous command (eg: what you need to configure your DNS). +### Troubleshooting + +:warning: On install and upgrade, before applying changes, a pre-hook will check that your customer package values use a version compatible with current helm chart. It it fails, it will dump the following message +```bash +Error: INSTALLATION FAILED: failed pre-install: job failed: BackoffLimitExceeded +``` +If you see this error you can get the reason running the following command: + +```bash + kubectl logs --selector=job-name=-pre-install +``` + ## Update 1. Authenticate and connect to your cluster diff --git a/chart/Chart.yaml b/chart/Chart.yaml index 8702d848..775a7f85 100644 --- a/chart/Chart.yaml +++ b/chart/Chart.yaml @@ -28,4 +28,7 @@ keywords: name: carto sources: - https://carto.com/ +annotations: + minVersion: "2022.05.12-5" version: 1.23.2 + diff --git a/chart/templates/pre-upgrade-check-versions-cm.yaml b/chart/templates/pre-upgrade-check-versions-cm.yaml new file mode 100644 index 00000000..9a5c5e4a --- /dev/null +++ b/chart/templates/pre-upgrade-check-versions-cm.yaml @@ -0,0 +1,28 @@ +{{- $minVersion := .Chart.Annotations.minVersion -}} +apiVersion: v1 +kind: ConfigMap +metadata: + name: "{{ .Release.Name }}-pre-install-scripts" + labels: + app.kubernetes.io/managed-by: {{ .Release.Service | quote }} + app.kubernetes.io/instance: {{ .Release.Name | quote }} + app.kubernetes.io/version: {{ .Chart.AppVersion }} + helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" + annotations: + # This is what defines this resource as a hook. Without this line, the + # job is considered part of the release. + "helm.sh/hook": pre-install, pre-upgrade + "helm.sh/hook-weight": "-10" + "helm.sh/hook-delete-policy": hook-succeeded, before-hook-creation, hook-fail +data : + check-version.sh: | + #!/bin/bash + printf 'Checking release version\n' + if [[ $(echo ${MINIMAL_VERSION} ${PACKAGE_VERSION} |tr ' ' '\n'| sort -V| head -n1) == ${MINIMAL_VERSION} ]];then + printf 'Release version is OK\n' + exit 0 + else + printf 'Release version is outdated, please contact support team at support-team@carto.com.\n' + exit 1 + fi + diff --git a/chart/templates/pre-upgrade-check-versions-job.yaml b/chart/templates/pre-upgrade-check-versions-job.yaml new file mode 100644 index 00000000..9f6c9729 --- /dev/null +++ b/chart/templates/pre-upgrade-check-versions-job.yaml @@ -0,0 +1,44 @@ +{{- $minVersion := .Chart.Annotations.minVersion -}} +apiVersion: batch/v1 +kind: Job +metadata: + name: "{{ .Release.Name }}-pre-install" + labels: + app.kubernetes.io/managed-by: {{ .Release.Service | quote }} + app.kubernetes.io/instance: {{ .Release.Name | quote }} + app.kubernetes.io/version: {{ .Chart.AppVersion }} + helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" + annotations: + + "helm.sh/hook": pre-install, pre-upgrade + "helm.sh/hook-weight": "-5" + "helm.sh/hook-delete-policy": hook-succeeded, before-hook-creation, hook-fail +spec: + backoffLimit: 0 + template: + metadata: + name: "{{ .Release.Name }}" + labels: + app.kubernetes.io/managed-by: {{ .Release.Service | quote }} + app.kubernetes.io/instance: {{ .Release.Name | quote }} + helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" + spec: + restartPolicy: Never + volumes: + - name: scripts + configMap: + name: "{{ .Release.Name }}-pre-install-scripts" + containers: + - name: pre-upgrade-version-check + terminationMessagePolicy: FallbackToLogsOnError + image: "alpine:latest" + volumeMounts: + - name: scripts + mountPath: /opt/scripts + env: + - name: PACKAGE_VERSION + value: {{ .Values.cartoConfigValues.cartoVersion }} + - name: MINIMAL_VERSION + value: {{ $minVersion }} + command: ["sh"] + args: ["/opt/scripts/check-version.sh"]