What happened:
After upgrading kubectl to version 1.21 kustomize command fails when YAML anchors are references by '<<'
What you expected to happen:
As it was in v. 1.20, command should provide correct output, but not the erorr
How to reproduce it (as minimally and precisely as possible):
Given this 2 files:
kustomization.yaml
api.yaml
kustomization.yaml:
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- api.yaml
api.yaml:
apiVersion: v1
kind: Service
metadata:
name: service
labels: &labels
label: test
spec:
selector:
<<: *labels
Execute kubectl kustomize . and see the following output:
v. 1.20:
apiVersion: v1
kind: Service
metadata:
labels:
label: test
name: service
spec:
selector:
label: test
v. 1.21:
Error: map[string]interface {}{"apiVersion":"v1", "kind":"Service", "metadata":map[string]interface {}{"labels":map[string]interface {}{"label":"test"}, "name":"service"}, "spec":map[string]interface {}{"selector":map[interface {}]interface {}{"label":"test"}}}: json: unsupported type: map[interface {}]interface {}
So, now kubectl cannot recognize << while parsing yaml. Replacement with any string fixes the issue. Even "<<" fixes it.
Environment:
@ZhilinS: This issue is currently awaiting triage.
SIG CLI takes a lead on issue triage for this repo, but any Kubernetes member can accept issues by applying the triage/accepted label.
The triage/accepted label can be added by org members by writing /triage accepted in a comment.
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.
It can be fixed by changing api.yaml to
apiVersion: v1
kind: Service
metadata:
name: service
labels: &labels
label: test
spec:
selector: *labels
but it's strange to see that previous version of tool was working with standard YAML syntax and the newest one isn't
We have been experiencing a lot of issues with regard to the use of anchors. Following YAML that used to work with kubectl v1.20.4 no longer seems to be working and errors out with the message : node must be a scalar, sequence or map.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: &app my-app
subjects:
- kind: ServiceAccount
name: *app
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: *app
Also rendering https://github.com/knative-sandbox/eventing-kafka-broker/releases/download/v0.22.1/eventing-kafka-controller.yaml using kubectl kustomize errors out due to the following usage:
livenessProbe:
!!merge <<: *probe
initialDelaySeconds: 20
Similarly rendering https://github.com/knative-sandbox/eventing-kafka/releases/download/v0.22.3/source.yaml errors out due to the use of YAML anchors.
edit: none of the above issues are experienced with kubectl 1.20.4
Kubectl 1.21 contains a large version bump to Kustomize, from v2 to v4. There are already several issues open on the Kustomize repo about problems with YAML anchors. Please follow along there. I believe the most relevant to this particular case is https://github.com/kubernetes-sigs/kustomize/issues/3614.
/triage duplicate
/close
@KnVerey: Closing this issue.
In response to this:
Kubectl 1.21 contains a large version bump to Kustomize, from v2 to v4. There are already several issues open on the Kustomize repo about problems with YAML anchors. Please follow along there. I believe the most relevant to this particular case is https://github.com/kubernetes-sigs/kustomize/issues/3614.
/triage duplicate
/close
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.