How can we override dependencies "version" in helm chart Chart.yaml file?

Viewed 2323

I am wondering and apparently have not yet found anywhere if there is a way via which I can specifically override the value of "version" key's value from the dependencies chart in Helm

# Chart.yaml
dependencies:
- name: bitnami/postgresql
  version: **"8.10.5"**
  repository: "https://charts.bitnami.com/bitnami"

I tried something like below:

# Chart.yaml
dependencies:
- name: bitnami/postgresql
  version: "{{.Values.postgresql.version}}"
  repository: "https://charts.bitnami.com/bitnami"

and

# Values.yaml
postgreSQL:
  version: "8.10.5" 

But I am getting below error:

Error: cannot load Chart.yaml: error converting YAML to JSON: yaml: invalid map key: map[interface {}]interface {}{".Values.postgresql.version":interface {}(nil)}

If this is currently not possible then can someone advise how do you update the "version" of dependencies in Charts.yaml whenever new version is available of them?

2 Answers

It's not super well documented in the Helm documentation – the generic helm dependency command documentation mentions it, but not the main discussion of chart dependencies – but the version: field is optional, and it uses semantic versioning if it is present. Helm maintains a separate Chart.lock file that lists precise versions of chart dependencies, and the helm dependency update command will update that file.

So for your uses you might say:

dependencies:
- name: bitnami/postgresql
  version: '^8' # Any 8.x.x version, but not version 7 or 9
  repository: "https://charts.bitnami.com/bitnami"

Or, if you're not configuring the dependency chart at all, just leave out the version: line entirely and use whatever the latest version is.

# Install the chart using the specific Chart.lock version
helm install myservice .

# Get a newer version in Chart.lock and upgrade the database
rm Chart.lock
helm dependency update
helm upgrade myservice .

Do check the Chart.lock file into source control, so you have reproducible deployments.

All of this is also true if you're using the older, Helm v2-compatible layout that lists dependencies in a separate requirements.yaml file. In this case the lock file is requirements.lock, but version: is still a semantic version constraint and the same helm dependency commands update the lock file.

Your approach won't work, because the template engine ({{ .Values.myvar }}) works only in the template folder.

 # Chart.yaml
 dependencies:
 - name: bitnami/postgresql
   version: "{{.Values.postgresql.version}}" # Won't be replaced
   repository: "https://charts.bitnami.com/bitnami"

I am afraid that the helm team won't change this behaviour according to this discussion: https://github.com/helm/helm/issues/2492

Apperantly the only way I can think of, is to replace the version with a shell script and afterwards calling the helm commando.

 sed -i 's/version: "[0-9].[0-9].[0-9]"/version: "9.9.9"/' Chart.yaml
 helm install ....
Related