Search code examples
kuberneteskubernetes-helm

how to use multiple variables with same name in helm chart?


i have helm chart which need to define multiple same variables name like this

      containers:
      - name: APP_NAME
        image: CONTAINER_IMAGE
        envFrom:
        - secretRef:
            name: secret1
        - secretRef:
            name: secret2
        - configMapRef:
            name: configmap1
        - secretRef:
            name: secret3

i added the nonproduction.yaml chart like this

envFrom:
  secretRef:
    name1: secret1
  secretRef:
    name2: secret2
  configmapRef:
    name3: configmap1
  secretRef:
    name4: secret3

and define the deployment.yaml

      containers:
      - name: {{ .Values.appName }}
        image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
        envFrom:
        - secretRef:
            name: {{ .Values.envFrom.secretRef.name1 }}
        - secretRef:
            name: {{ .Values.envFrom.secretRef.name2 }}
        - configMapRef:
            name: {{ .Values.envFrom.configmapRef.name3 }}
        - secretRef:
            name: {{ .Values.envFrom.secretRef.name4 }}

but it went to duplicate key on the terminal, how can i use same name variable on helm chart without changing the name?

edit: add number so we dont get dizzy by the 'name'


Solution

  • Instead of calling individual secrets and config map, You can call all of them at a time.

      env:
        {{- toYaml .Values.envs | nindent 12 }}
      envFrom:
        {{- toYaml .Values.envFrom | nindent 12 }}