2

Based on this SO, this should work and I'm not sure what I'm missing.

I'm trying to combine env variables in a helm chart. TARGET and TARGET_KEY, but I'm getting:

 - name: TARGET_KEY # combining keys together
   value: Hello $(TARGET)

I'm expecting

 - name: TARGET_KEY # combining keys together
   value: Hello World
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: hello
  namespace: myapp
spec:
  template:
    metadata:
      annotations:
        autoscaling.knative.dev/minScale: "1"
        autoscaling.knative.dev/target: "10"
    spec:
       containers:
        - image: gcr.io/knative-samples/helloworld-go
          ports:
            - containerPort: 8080
          env:
            - name: TARGET
              value: "World"
            - name: APIKEY
              valueFrom: # get single key from secret at key
                secretKeyRef:
                  name: {{ .Values.keys.name }}
                  key: apiKey
            - name: TARGET_KEY # combining keys together
              value: Hello $(TARGET)
          envFrom: # set ENV variables from all the values in secret
            - secretRef:
                name: {{ .Values.keys.name }}

I am using ArgoCD to sync the helm charts. Checking the newly deployed pod's ENV vars.

Teebu
  • 677
  • 7
  • 18
  • 1
    How are you verifying this? The `value: $(VARIABLE)` syntax isn't resolved by Kubernetes until it creates the runtime environment for the program inside the container, so you will literally see `$(TARGET)` in both `helm template` and `kubectl get -o yaml` output and that's normal. – David Maze Aug 05 '22 at 10:14
  • I'm using ArgoCD and it syncs and deploys the pod. I am seeing the ENV vars directly on the pod. – Teebu Aug 05 '22 at 15:33

1 Answers1

0

@David is correct. The ENV variable shown in template and pod description keep the template name, but once I ssh'ed into the pod, doing printenv shows the env variable was properly filled in.

However, I did read there are issues with alphabetic sorting and ordering when trying to mix multiple ENV vars this way. That's a topic for another SO.

Teebu
  • 677
  • 7
  • 18