【问题标题】:How to parse PodSpec.spec.imagePullSecrets from a yaml file?如何从 yaml 文件中解析 PodSpec.spec.imagePullSecrets?
【发布时间】:2022-01-20 14:36:18
【问题描述】:

我想用 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

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

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

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]

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

【问题讨论】:

    标签: go kubernetes yaml container-ssh


    【解决方案1】:

    这是输入的问题 - 可能不是很清楚的错误消息。

    imagePullSecrets 必须使用键 name 指定,例如:

    imagePullSecrets:
      - name: docker-registry-secret
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-01
      • 2012-02-16
      • 2012-02-07
      • 2011-04-22
      • 2010-12-18
      • 2017-06-03
      • 2021-11-04
      相关资源
      最近更新 更多