-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Closed
Labels
kind/bugCategorizes issue or PR as related to a bug.Categorizes issue or PR as related to a bug.kind/regressionCategorizes issue or PR as related to a regression from a prior release.Categorizes issue or PR as related to a regression from a prior release.triage/acceptedIndicates an issue or PR is ready to be actively worked on.Indicates an issue or PR is ready to be actively worked on.
Description
What happened?
I was using yaml anchors successfully in kustomize v4 inside of a replacements transformer. The replacements transformer appeared to have received some fixes in kustomize v5, so I upgraded. When I did, some code that had been working in v4 stopped working, and I started getting errors complaining about having multiple keys in an mapping that has an anchor.
With v5 it produces this error
$ kustomize build
Error: invalid Kustomization: error converting YAML to JSON: yaml: unmarshal errors:
line 25: key "fieldPath" already set in map
line 34: key "fieldPath" already set in map
What did you expect to happen?
I expected kustomize to continue correctly handling yaml anchors in v5 as it did in v4. In v4 the same repo produces this valid & correct output:
$ kustomize build
apiVersion: v1
data:
key1: value1
key2: value2
key3: value3
kind: ConfigMap
metadata:
name: cm1
---
apiVersion: v1
data:
keya: value1
keyb: value2
keyc: value2
kind: ConfigMap
metadata:
name: cm2
How can we reproduce it (as minimally and precisely as possible)?
I created a minimal repoduction repo: https://github.com/jskrzypek/kustomizev5-yaml-anchor-bug
apiVersion: v1
kind: ConfigMap
metadata:
name: cm1
data:
key1: value1
key2: value2
key3: value3apiVersion: v1
kind: ConfigMap
metadata:
name: cm2
data:
keya: valuea
keyb: valueb
keyc: valuecapiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- cm1.yaml
- cm2.yaml
replacements:
- source: &source
version: v1
kind: ConfigMap
name: cm1
fieldPath: data.key1
targets:
- select: &select
version: v1
kind: ConfigMap
name: cm2
options:
create: true
fieldPaths:
- .data.keya
- source:
<<: *source
fieldPath: data.key2
targets:
- select: *select
options:
create: true
fieldPaths:
- .data.keyb
- source:
<<: *source
fieldPath: data.key2
targets:
- select: *select
options:
create: true
fieldPaths:
- .data.keycExpected output
apiVersion: v1
data:
key1: value1
key2: value2
key3: value3
kind: ConfigMap
metadata:
name: cm1
---
apiVersion: v1
data:
keya: value1
keyb: value2
keyc: value2
kind: ConfigMap
metadata:
name: cm2Actual output
Error: invalid Kustomization: error converting YAML to JSON: yaml: unmarshal errors:
line 25: key "fieldPath" already set in map
line 34: key "fieldPath" already set in mapKustomize version
v5.0.0
Operating system
MacOS
pdeva
Metadata
Metadata
Assignees
Labels
kind/bugCategorizes issue or PR as related to a bug.Categorizes issue or PR as related to a bug.kind/regressionCategorizes issue or PR as related to a regression from a prior release.Categorizes issue or PR as related to a regression from a prior release.triage/acceptedIndicates an issue or PR is ready to be actively worked on.Indicates an issue or PR is ready to be actively worked on.