Choosing between alternative dependencies in helm

2/24/2019

I have a helm chart for an application that needs some kind of database. Both mysql or postgresql would be fine.

I would like to give the chart user the option to install one of these as a dependency like this:

dependencies:
- name: mysql
  version: 0.10.2
  repository: https://kubernetes-charts.storage.googleapis.com/
  condition: mysql.enabled
- name: postgresql
  version: 3.11.5
  repository: https://kubernetes-charts.storage.googleapis.com/
  condition: postgresql.enabled

However this makes it possible to enable both of them.

Is there an easy way to make sure only one is selected?

I was thinking of a single variable selecting one of [mysql, postgres, manual] and depend on a specific database if it is selected. - Is there a way to do so?

-- michas
kubernetes
kubernetes-helm

1 Answer

2/25/2019

I don't think there's a straightforward way to do this. In particular, it looks like the requirements.yaml condition: field only takes a boolean value (or a list of them) and not an arbitrary expression. From the Helm documentation:

The condition field holds one or more YAML paths (delimited by commas). If this path exists in the top parent’s values and resolves to a boolean value, the chart will be enabled or disabled based on that boolean value. Only the first valid path found in the list is evaluated and if no paths exist then the condition has no effect.

(The tags mechanism described below that is extremely similar and doesn't really help.)

When it comes down to actually writing your Deployment spec you have a more normal conditional system and can test that only one of the values is set; so I don't think you can prevent having redundant databases installed, but you'll at least only use one of them. You could also put an after-the-fact warning to this effect in your NOTES.txt file.

{{ if and .Values.mysql.enabled .Values.postgresql.enabled -}}
WARNING: you have multiple databases enabled in your Helm values file.
Both MySQL and PostgreSQL are installed as part of this chart, but only
PostgreSQL is being used.  You can update this chart installation setting
`--set mysql.enabled=false` to remove the redundant database.

{{ end -}}
-- David Maze
Source: StackOverflow