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