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

标签 go kubernetes yaml

我想使用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 的正确方法是什么?

最佳答案

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

必须使用键 name 指定 imagePullSecrets,如下所示:

imagePullSecrets:
  - name: docker-registry-secret

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

关于go - 如何从 yaml 文件解析 PodSpec.spec.imagePullSecrets ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70788081/

相关文章:

go - 如何使用 gorilla 处理程序允许移动设备上的 OPTIONS 方法?

kubernetes - 有没有办法从 kubernetes 环境中的 pod 下载容器镜像?

azure - 无法授权 Azure 订阅在基于 YAML 的管道中使用

r - 在 Quarto 书籍模板中将数据从一个 qmd 文件传递​​到另一个文件?

go - 测试来自GitHub.com/Shopify/sarama的日志输出

http - 如何在请求中转义正斜杠以使 url-routers 将其计为 uri 参数的一部分?

python - kubernetes 上的 Airflow : How to install extra python packages?

amazon-web-services - 在 YAML cloudformation 中加入多个资源

go - 为什么emacs-lsp go-mode在路径中找不到go可执行文件?

azure - Strimzi Kafka 监听器自定义证书配置