Helm chart with dependent values

11/27/2018

I have a helm chart that can either use an internal database or an external database. The values are mutually exclusive. If one value is true, the other value should be false.

Is there a way to enforce mutual exclusivity so a user doesn't accidentally enable both?

Example to use built in database (redis)

helm install foo --set redis.enabled=true --set corvus.enabled=false

Examaple to use an external database (corvus)

helm install foo --set redis.enabled=false --set corvus.enabled=true --set corvus.location=foobar

I have considered not using 2 separate values redis.enabled corvus.enabled and instead using a single value like database which can be set to either internal or external, however because helm conditionals in the requriements.yaml can only perform logic on a boolean, I don't believe this is possible.

dependencies:
  - name: redis
    version: 4.2.7
    repository: https://kubernetes-charts.storage.googleapis.com
    condition: redis.enabled,global.redis.enabled
-- spuder
kubernetes-helm

1 Answer

11/28/2018

You can use some Sprig templating magic in order to force the config keys to be mutually exclusive. For your case, you can add a block of the following sort to any of your Chart's templates.

{{- if .Values.redis.enabled }}
{{- if .Values.corvus.enabled }}
{{- fail "redis and corvus are mutually exclusive!" }}
{{- end }}
{{- end }}

This will cause the Chart installation to fail when both config values are evaluated as true.

-- yanivoliver
Source: StackOverflow