Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Helm If / else with conditional value if exists

I have a values file that contains the following key / value pairs:

domains:
  - name: "one.dev.beta.com"
  - name: "two.dev.beta.com"
  - name: "three.dev.beta.com"
  - name: "four.dev.beta.com" 
    wwwRedirect: true

And a helm chart that I need to conditionalize the behavior for if wwwRedirect is true. I am new to writing conditionals in GO in helm charts, and wanted to validate this would work. I wanted to know if there was a way to test this behavior as well before deploying my service as well to my cluster:

{{ range .Values.domains }}
---
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
  name: {{ .name }}
  namespace: {{ $.Release.Namespace }}
spec:
  secretName: {{ .name }}
  duration: 2h
  renewBefore: 2h
  subject:
    organizations:
    - dev
  isCA: false
  privateKey:
    algorithm: RSA
    encoding: PKCS1
    size: 2048
  commonName: {{ .name }}
  dnsNames:
  {{ if not .name.wwwRedirect }}
    - "{{ .name }}"
    - "www.{{ .name }}"
  {{ else }}
    - "{{ .name }}"
  {{ end }}    
  issuerRef:
    name: letsencrypt-http01-traefik
    kind: ClusterIssuer
{{ end }}

The specific part I want to validate is here:

  dnsNames:
  {{ if not .name.wwwRedirect }}
    - "{{ .name }}"
    - "www.{{ .name }}"
  {{ else }}
    - "{{ .name }}"
  {{ end }}    

My assumption on reading this is that if .name.wwwRedirect is not true or doesn't exist, then it would apply dns names with and without www to the list. If name.Redirect is true, then it would just apply it to the name.

like image 893
Branden Avatar asked Jan 24 '26 15:01

Branden


1 Answers

helm Debugging Templates

helm template --debug test .

It's a great way to have the server render your templates, then return the resulting manifest file.

like image 131
z.x Avatar answered Jan 27 '26 01:01

z.x



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!