如何从 yaml 文件解析 PodSpec.spec.imagePullSecrets ?

And*_*ath 4 yaml go kubernetes

我想使用 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
Run Code Online (Sandbox Code Playgroud)

我用来sigs.k8s.io/yaml解组 YAML:

var userConfig map[string]map[string]kubernetes.PodConfig
err = yaml.UnmarshalStrict(yamlFile, &userConfig)
Run Code Online (Sandbox Code Playgroud)

kubernetes 是从哪里导入的github.com/containerssh/kubernetes。一切正常 - 除了immagePullSecrets给出以下错误:

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]
Run Code Online (Sandbox Code Playgroud)

在 go 中指定/解析 an 的正确方法是什么imagePullSecrets

And*_*ath 6

这是输入的问题 - 并且可能不是一个非常明确的错误消息。

必须imagePullSecrets使用如下键指定name

imagePullSecrets:
  - name: docker-registry-secret
Run Code Online (Sandbox Code Playgroud)

我留下这个问题,因为它可能会帮助其他遇到同样问题的人。