mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-13 10:00:56 +00:00
Fix error during expansion of !!merge <<: anchor tags (#4383)
* WIP * Fix merge corner cases * Add test for explicit !!merge tag * Fix tests * Cleanup * Cleanup * Fix deanchoring lists * Add test case for keeping comments * Add MapEntrySetter and fix json marshalling after deanchoring * Keep duplicated keys * Move MergeTag definition to yaml alias * Remove go-spew from api * Add support for sequence nodes on merge tags * Add docstring to MapEntrySetter.Key * Add docstring to MapEntrySetter struct * Add tests to MapEntrySetter * Fix duplicate merge key * Revert whitespace changes on forked go-yaml * Remove AssocMapEntry function * Refactoring merge order * Return errors on VisitFields and PipeE * Add tests for each non-conforming map merges
This commit is contained in:
@@ -958,6 +958,53 @@ metadata:
|
||||
`), strings.TrimSpace(string(yaml)))
|
||||
}
|
||||
|
||||
func TestDeAnchorIntoDoc(t *testing.T) {
|
||||
input := `apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: probes-test
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
readinessProbe: &probe
|
||||
periodSeconds: 5
|
||||
timeoutSeconds: 3
|
||||
failureThreshold: 3
|
||||
httpGet:
|
||||
port: http
|
||||
path: /health
|
||||
livenessProbe:
|
||||
<<: *probe
|
||||
`
|
||||
rm, err := rmF.NewResMapFromBytes([]byte(input))
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, rm.DeAnchor())
|
||||
yaml, err := rm.AsYaml()
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, strings.TrimSpace(`apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: probes-test
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
livenessProbe:
|
||||
failureThreshold: 3
|
||||
httpGet:
|
||||
path: /health
|
||||
port: http
|
||||
periodSeconds: 5
|
||||
timeoutSeconds: 3
|
||||
readinessProbe:
|
||||
failureThreshold: 3
|
||||
httpGet:
|
||||
path: /health
|
||||
port: http
|
||||
periodSeconds: 5
|
||||
timeoutSeconds: 3
|
||||
`), strings.TrimSpace(string(yaml)))
|
||||
}
|
||||
|
||||
// Anchor references don't cross YAML document boundaries.
|
||||
func TestDeAnchorMultiDoc(t *testing.T) {
|
||||
input := `apiVersion: v1
|
||||
|
||||
@@ -335,13 +335,7 @@ kind: List
|
||||
"listWithAnchorReference": {
|
||||
input: []types.PatchStrategicMerge{patchList2},
|
||||
expectedOut: []*Resource{testDeploymentA, testDeploymentB},
|
||||
// The error using kyaml is:
|
||||
// json: unsupported type: map[interface {}]interface {}
|
||||
// maybe arising from too many conversions between
|
||||
// yaml, json, Resource, RNode, etc.
|
||||
// These conversions go away after closing #3506
|
||||
// TODO(#3271) This shouldn't have an error, but does when kyaml is used.
|
||||
expectedErr: true,
|
||||
expectedErr: false,
|
||||
},
|
||||
"listWithNoEntries": {
|
||||
input: []types.PatchStrategicMerge{patchList3},
|
||||
|
||||
Reference in New Issue
Block a user