Cannot bind the value of k8s env ValueFrom field to struct passed with yaml

8/19/2021

I'm trying to pass the Kubernetes env variables from custom yaml file. But, the env variables which uses valueFrom syntax are not getting bound to the struct in Go.

demo.yaml

env:
  resource:
    - name: DEMO1
      value: value1
    - name: POD_LABELS
      valueFrom:
        fieldRef:
          fieldPath: metadata.labels

Go struct:

type Config struct {
    Env EnvData `yaml:"env"`
}

type EnvData struct {
  Resource []corev1.EnvVar `yaml:"resource"`
}

After unmarshalling the output is:

env: {resource: [{Demo1 value1 nil}, {POD_LABELS  nil}]}
-- Avadhut Pisal
go
kubernetes
kubernetes-pod
yaml

0 Answers