Skip to content

Commit

Permalink
Add pre-hook to check minimal version for customer package (#129)
Browse files Browse the repository at this point in the history
* Add pre-hook to check minimal version for customer package

* remove comments

* doc
  • Loading branch information
aitorch authored May 24, 2022
1 parent a3a951a commit 66dcf2f
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<your_release_name>-pre-install
```

## Update

1. Authenticate and connect to your cluster
Expand Down
3 changes: 3 additions & 0 deletions chart/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@ keywords:
name: carto
sources:
- https://carto.com/
annotations:
minVersion: "2022.05.12-5"
version: 1.23.2

28 changes: 28 additions & 0 deletions chart/templates/pre-upgrade-check-versions-cm.yaml
Original file line number Diff line number Diff line change
@@ -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 [email protected].\n'
exit 1
fi
44 changes: 44 additions & 0 deletions chart/templates/pre-upgrade-check-versions-job.yaml
Original file line number Diff line number Diff line change
@@ -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"]

0 comments on commit 66dcf2f

Please sign in to comment.