How to parse PodSpec.spec.imagePullSecrets from a yaml file?

I want to parse the following structure using go:

---
prjA:
  user1:
    metadata:
      namespace: prj-ns
    spec:
      containers:
        - image: some-contaner:latest
          name: containerssh-client-image
          resources:
            limits:
              ephemeral-storage: 4Gi
            requests:
              ephemeral-storage: 2Gi
      securityContext:
        runAsGroup: 1000
        runAsNonRoot: true
        runAsUser: 1000
      imagePullSecrets:
        - docker-registry-secret

I'm using sigs.k8s.io/yaml to unmarshal YAML:

var userConfig map[string]map[string]kubernetes.PodConfig
err = yaml.UnmarshalStrict(yamlFile, &userConfig)

where kubernetes is imported from github.com/containerssh/kubernetes. Everything works fine - except the immagePullSecrets which gives the following error:

ERROR unmarshal user config file; error [error unmarshaling JSON: while decoding JSON: json: cannot unmarshal string into Go struct field PodSpec.spec.imagePullSecrets of type v1.LocalObjectReference]

What is the correct way to specify / parse an imagePullSecrets in go?


This is a problem with the input - and maybe not a very clear error message.

The imagePullSecrets must be specified using the key name like:

imagePullSecrets:
  - name: docker-registry-secret

I leave the question as it might help other people who run in the same problem.