yaml 锚定一个列表对象,并与 kustomize 合并
yaml anchor a list object, and merge with kustomize
我有兴趣将 YAML 锚点用于对象列表。我有一个包含容器列表的 Kubernetes pod 清单。我正在尝试使用 kustomize 构建它,但找不到正确的语法。
所以,我认为这看起来是最正确的。
apiVersion: v1
kind: Pod
metadata: { name: anchor-test }
spec:
containers:
- &foo
name: foo
image: traefik/whoami
ports: [ containerPort: 80 ]
- <<: *foo
name: bar
但是 kustomize 抛出了这个错误:
Error: map[string]interface {}{"apiVersion":"v1", "kind":"Pod", "metadata":map[string]interface {}{"name":"anchor-test"}, "spec":map[string]interface {}{"containers":[]interface {}{map[string]interface {}{"image":"traefik/whoami", "name":"foo", "ports":[]interface {}{map[string]interface {}{"containerPort":80}}}, map[interface {}]interface {}{"image":"traefik/whoami", "name":"bar", "ports":[]interface {}{map[string]interface {}{"containerPort":80}}}}}}:
json: unsupported type: map[interface {}]interface {}
所以,这个问题是 kustomize
特有的。它适用于 kubectl apply -f
。这意味着 YAML 实际上是这样有效的。可以用http://www.yamllint.com/.
来测试
因此目前 kustomize
无法做到这一点。关于这个 GitHub 有一些问题。
我有兴趣将 YAML 锚点用于对象列表。我有一个包含容器列表的 Kubernetes pod 清单。我正在尝试使用 kustomize 构建它,但找不到正确的语法。
所以,我认为这看起来是最正确的。
apiVersion: v1
kind: Pod
metadata: { name: anchor-test }
spec:
containers:
- &foo
name: foo
image: traefik/whoami
ports: [ containerPort: 80 ]
- <<: *foo
name: bar
但是 kustomize 抛出了这个错误:
Error: map[string]interface {}{"apiVersion":"v1", "kind":"Pod", "metadata":map[string]interface {}{"name":"anchor-test"}, "spec":map[string]interface {}{"containers":[]interface {}{map[string]interface {}{"image":"traefik/whoami", "name":"foo", "ports":[]interface {}{map[string]interface {}{"containerPort":80}}}, map[interface {}]interface {}{"image":"traefik/whoami", "name":"bar", "ports":[]interface {}{map[string]interface {}{"containerPort":80}}}}}}:
json: unsupported type: map[interface {}]interface {}
所以,这个问题是 kustomize
特有的。它适用于 kubectl apply -f
。这意味着 YAML 实际上是这样有效的。可以用http://www.yamllint.com/.
因此目前 kustomize
无法做到这一点。关于这个 GitHub 有一些问题。