Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions patterns/min-helm-version/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Define the minimum Helm version for a chart

The [mychart](./mychart/) chart contains a simple pattern that you can use to enforce a minimum version of the Helm client for any chart.

1. Add `annotations.minimumHelmVersion` to your `Chart.yaml`. For example:

```yaml
apiVersion: v2
name: mychart
version: 0.1.0
annotations:
minimumHelmVersion: 3.18.2
```
_See [mychart/Chart.yaml](./mychart/Chart.yaml)._
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.

```tpl
{{- define "mychart.validateHelmVersion" -}}
{{- $minVersion := .Chart.Annotations.minimumHelmVersion }}
{{- $helmVersion := trimPrefix "v" .Capabilities.HelmVersion.Version }}
{{- if lt $helmVersion $minVersion }}
{{- $message := printf "\n\nThis chart requires a minimum version of Helm %s. Please upgrade your Helm version." $minVersion }}
{{- fail $message }}
{{- end }}
{{- end }}
```
_See [mychart/templates/_helpers.tpl](./mychart/templates/_helpers.tpl)._
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.

```yaml
{{- include "mychart.validateHelmVersion" . }}
apiVersion: v1
kind: Secret
metadata:
name: mysecret
data:
foo: YmFyCg==
```
_See [mychart/templates/secret.yaml](./mychart/templates/secret.yaml)._
5 changes: 5 additions & 0 deletions patterns/min-helm-version/mychart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v2
name: mychart
version: 0.1.0
annotations:
minimumHelmVersion: 3.18.2
8 changes: 8 additions & 0 deletions patterns/min-helm-version/mychart/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{{- define "mychart.validateHelmVersion" -}}
{{- $minVersion := .Chart.Annotations.minimumHelmVersion }}
{{- $helmVersion := trimPrefix "v" .Capabilities.HelmVersion.Version }}
{{- if lt $helmVersion $minVersion }}
{{- $message := printf "\n\nThis chart requires a minimum version of Helm %s. Please upgrade your Helm version." $minVersion }}
{{- fail $message }}
{{- end }}
{{- end }}
7 changes: 7 additions & 0 deletions patterns/min-helm-version/mychart/templates/secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{- include "mychart.validateHelmVersion" . }}
apiVersion: v1
kind: Secret
metadata:
name: mysecret
data:
foo: YmFyCg==