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

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

<pre><code>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
</code></pre>

<p>However this makes it possible to enable both of them.</p>

<p>Is there an easy way to make sure only one is selected?</p>

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

<p>I don't think there's a straightforward way to do this.  In particular, it looks like the <code>requirements.yaml</code> <code>condition:</code> field only takes a boolean value (or a list of them) and not an arbitrary expression.  From <a href="https://helm.sh/docs/developing_charts/#tags-and-condition-fields-in-requirements-yaml" rel="nofollow noreferrer">the Helm documentation</a>:</p>

<blockquote>
  <p>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.</p>
</blockquote>

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

<p>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 <code>NOTES.txt</code> file.</p>

<pre><code>{{ 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 -}}
</code></pre>
