Skip to content

Commit f7aa83e

Browse files
authored
Minimum Helm version pattern (#77)
Signed-off-by: Scott Rigby <[email protected]>
1 parent a106750 commit f7aa83e

File tree

4 files changed

+59
-0
lines changed

4 files changed

+59
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Define the minimum Helm version for a chart
2+
3+
The [mychart](./mychart/) chart contains a simple pattern that you can use to enforce a minimum version of the Helm client for any chart.
4+
5+
1. Add `annotations.minimumHelmVersion` to your `Chart.yaml`. For example:
6+
7+
```yaml
8+
apiVersion: v2
9+
name: mychart
10+
version: 0.1.0
11+
annotations:
12+
minimumHelmVersion: 3.18.2
13+
```
14+
_See [mychart/Chart.yaml](./mychart/Chart.yaml)._
15+
1. Add a helper function to your chart's `templates/_helpers.tpl` file, like the `mychart.validateHelmVersion` function below. Replace `mychart` with the name of your chart.
16+
17+
```tpl
18+
{{- define "mychart.validateHelmVersion" -}}
19+
{{- $minVersion := .Chart.Annotations.minimumHelmVersion }}
20+
{{- $helmVersion := trimPrefix "v" .Capabilities.HelmVersion.Version }}
21+
{{- if lt $helmVersion $minVersion }}
22+
{{- $message := printf "\n\nThis chart requires a minimum version of Helm %s. Please upgrade your Helm version." $minVersion }}
23+
{{- fail $message }}
24+
{{- end }}
25+
{{- end }}
26+
```
27+
_See [mychart/templates/_helpers.tpl](./mychart/templates/_helpers.tpl)._
28+
1. Include your helper function at the top of any template. Make sure this include statement is outside of any rendering conditional logic if you want to always enfore the minimum Helm version.
29+
30+
```yaml
31+
{{- include "mychart.validateHelmVersion" . }}
32+
apiVersion: v1
33+
kind: Secret
34+
metadata:
35+
name: mysecret
36+
data:
37+
foo: YmFyCg==
38+
```
39+
_See [mychart/templates/secret.yaml](./mychart/templates/secret.yaml)._
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
apiVersion: v2
2+
name: mychart
3+
version: 0.1.0
4+
annotations:
5+
minimumHelmVersion: 3.18.2
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{{- define "mychart.validateHelmVersion" -}}
2+
{{- $minVersion := .Chart.Annotations.minimumHelmVersion }}
3+
{{- $helmVersion := trimPrefix "v" .Capabilities.HelmVersion.Version }}
4+
{{- if lt $helmVersion $minVersion }}
5+
{{- $message := printf "\n\nThis chart requires a minimum version of Helm %s. Please upgrade your Helm version." $minVersion }}
6+
{{- fail $message }}
7+
{{- end }}
8+
{{- end }}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{{- include "mychart.validateHelmVersion" . }}
2+
apiVersion: v1
3+
kind: Secret
4+
metadata:
5+
name: mysecret
6+
data:
7+
foo: YmFyCg==

0 commit comments

Comments
 (0)