Home > Software design >  helm chart conditional install based on a list
helm chart conditional install based on a list

Time:01-28

I'm trying to find a way to optionally install a manifest based on a list or a map (really don't mind which) in the values file.

in the values file I have

provisioners: ["gp","test"]

and in the manifest I have

{{- if has "test" .Values.provisioners  }}

I've also tried

provisioners: 
- "gp"
- "test"

and put this in the yaml

{{- if hasKey  .Values.provisioners "test" }}

but I can't either way to work, the chart never installs anything.

I feel like I'm missing something pretty basic, but I can't figure out what. Can someone point me in the right direction.

CodePudding user response:

I don't think you shared everything in you template and there might be something else. What you already did is correct, as you in my example below:

# templates/configmap.yaml
{{- if has "test" .Values.provisioners }}
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: test-config
  namespace: default
data:
  config.yaml: |
    attr=content
{{- end }}
{{- if has "gp" .Values.provisioners }}
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: gp-config
  namespace: default
data:
  config.yaml: |
    attr=content
{{- end }}
{{- if has "unknown" .Values.provisioners }}
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: not-templated-config
  namespace: default
data:
  config.yaml: |
    attr=content
{{- end }}

Output of the helm template . against local chart:

---
# Source: chart/templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: test-config
  namespace: default
data:
  config.yaml: |
    attr=content
---
# Source: chart/templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: gp-config
  namespace: default
data:
  config.yaml: |
    attr=content
  • Related