2

I have the following deployment definition:

...
containers:
        - name: {{ .Release.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          {{ if .Values.env.enabled }}
          env:
          {{- range .Values.env.vars }}
             ?????What comes here?????
          {{- end }}
          {{ end }}
          ports:
            - name: http
              containerPort: 8080
              protocol: TCP
          livenessProbe:
            httpGet:
              path: /
              port: http
          readinessProbe:
            httpGet:
              path: /
              port: http
          resources:
            {{- toYaml .Values.resources | nindent 12 }}
...

in the values.yaml, I have defined:

env:
  enabled: false
  vars: [] 

What I would like to do is, to set environment dynamically via --set, for instance:

helm template user-svc \
  --set image.tag=0.1.0 \
  --set image.repository=user-svc \
  --set env.enabled=true \
  --set env.vars.POSTGRES_URL="jdbc:postgresql://localhost:5432/users" \
  --set env.vars.POSTGRES_USER="dbuser" \
  ./svc

after rendering, it should show:

...
containers:
- name: demo
  image: game.example/demo-game
  env:
    - name: POSTGRES_URL
      value: jdbc:postgresql://localhost:5432/users
...

and how to set the following option via --set:

- name: UI_PROPERTIES_FILE_NAME
  valueFrom:
    configMapKeyRef:
      name: game-demo
      key: ui_properties_file_name 
softshipper
  • 32,463
  • 51
  • 192
  • 400
  • did you consult [any existing one to see how they work?](https://github.com/helm/charts/blob/47f5c2cd3730331b06a363848c931a33b3799f48/stable/oauth2-proxy/templates/deployment.yaml#L94-L96) – mdaniel Aug 09 '20 at 00:33
  • @mdaniel Could you please provide an example, how to use it and how to pass it with `--set`. – softshipper Aug 09 '20 at 07:27

1 Answers1

3

You can access the --set option using .Values.

{{- if eq .Values.env.enabled "true" -}}
 env:
   - name: {{ .Values.env.vars.POSTGRES_USER }}
     value: {{ .Values.env.vars.env.vars.POSTGRES_URL}}
{{- end }}

Try the above.

Rohit
  • 1,231
  • 10
  • 22