mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 01:14:22 +00:00
Related issues: * https://github.com/kubernetes-sigs/kustomize/issues/5031 * https://github.com/kubernetes-sigs/kustomize/issues/5171 After noting this behaviour was not present ind89b448c74a `git bisect` pointed to the change1b7db20504. The issue with that change is that upon seeing a `null` node it would replace it with a node whose value was equivalent but without a `!!null` tag. This meant that one application of a patch would have the desired approach: the result would be `null` in the output, but on a second application of a similar patch the field would be rendered as `"null"`. To avoid this, define a new attribute on `RNode`s that is checked before clearing any node we should keep. The added `TestApplySmPatch_Idempotency` test verifies this behaviour. See also https://github.com/kubernetes-sigs/kustomize/pull/5365 for an alternative approach
242 lines
3.6 KiB
Go
242 lines
3.6 KiB
Go
// Copyright 2019 The Kubernetes Authors.
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package merge2_test
|
|
|
|
import (
|
|
"sigs.k8s.io/kustomize/kyaml/yaml"
|
|
)
|
|
|
|
var scalarTestCases = []testCase{
|
|
{description: `replace scalar -- different value in dest`,
|
|
source: `
|
|
kind: Deployment
|
|
field: value1
|
|
`,
|
|
dest: `
|
|
kind: Deployment
|
|
field: value0
|
|
`,
|
|
expected: `
|
|
kind: Deployment
|
|
field: value1
|
|
`,
|
|
mergeOptions: yaml.MergeOptions{
|
|
ListIncreaseDirection: yaml.MergeOptionsListAppend,
|
|
},
|
|
},
|
|
|
|
{description: `replace scalar -- missing from dest`,
|
|
source: `
|
|
kind: Deployment
|
|
field: value1
|
|
`,
|
|
dest: `
|
|
kind: Deployment
|
|
`,
|
|
expected: `
|
|
kind: Deployment
|
|
field: value1
|
|
`,
|
|
mergeOptions: yaml.MergeOptions{
|
|
ListIncreaseDirection: yaml.MergeOptionsListAppend,
|
|
},
|
|
},
|
|
|
|
//
|
|
// Test Case
|
|
//
|
|
{description: `keep scalar -- same value in src and dest`,
|
|
source: `
|
|
kind: Deployment
|
|
field: value1
|
|
`,
|
|
dest: `
|
|
kind: Deployment
|
|
field: value1
|
|
`,
|
|
expected: `
|
|
kind: Deployment
|
|
field: value1
|
|
`,
|
|
mergeOptions: yaml.MergeOptions{
|
|
ListIncreaseDirection: yaml.MergeOptionsListAppend,
|
|
},
|
|
},
|
|
|
|
//
|
|
// Test Case
|
|
//
|
|
{description: `keep scalar -- unspecified in src`,
|
|
source: `
|
|
kind: Deployment
|
|
`,
|
|
dest: `
|
|
kind: Deployment
|
|
field: value1
|
|
`,
|
|
expected: `
|
|
kind: Deployment
|
|
field: value1
|
|
`,
|
|
mergeOptions: yaml.MergeOptions{
|
|
ListIncreaseDirection: yaml.MergeOptionsListAppend,
|
|
},
|
|
},
|
|
|
|
//
|
|
// Test Case
|
|
//
|
|
{description: `remove scalar -- null in src`,
|
|
source: `
|
|
kind: Deployment
|
|
field: null
|
|
`,
|
|
dest: `
|
|
kind: Deployment
|
|
field: value1
|
|
`,
|
|
expected: `
|
|
kind: Deployment
|
|
`,
|
|
mergeOptions: yaml.MergeOptions{
|
|
ListIncreaseDirection: yaml.MergeOptionsListAppend,
|
|
},
|
|
},
|
|
|
|
//
|
|
// Test Case
|
|
//
|
|
{description: `remove scalar -- empty in src`,
|
|
source: `
|
|
kind: Deployment
|
|
field:
|
|
`,
|
|
dest: `
|
|
kind: Deployment
|
|
field: value1
|
|
`,
|
|
expected: `
|
|
kind: Deployment
|
|
`,
|
|
mergeOptions: yaml.MergeOptions{
|
|
ListIncreaseDirection: yaml.MergeOptionsListAppend,
|
|
},
|
|
},
|
|
|
|
//
|
|
// Test Case
|
|
//
|
|
{description: `remove scalar -- null in src, missing in dest`,
|
|
source: `
|
|
kind: Deployment
|
|
field: null
|
|
`,
|
|
dest: `
|
|
kind: Deployment
|
|
`,
|
|
expected: `
|
|
kind: Deployment
|
|
`,
|
|
mergeOptions: yaml.MergeOptions{
|
|
ListIncreaseDirection: yaml.MergeOptionsListAppend,
|
|
},
|
|
},
|
|
|
|
//
|
|
// Test Case
|
|
//
|
|
{description: `remove scalar -- null in src, empty in dest`,
|
|
source: `
|
|
kind: Deployment
|
|
field: null
|
|
`,
|
|
dest: `
|
|
kind: Deployment
|
|
field:
|
|
`,
|
|
expected: `
|
|
kind: Deployment
|
|
`,
|
|
mergeOptions: yaml.MergeOptions{
|
|
ListIncreaseDirection: yaml.MergeOptionsListAppend,
|
|
},
|
|
},
|
|
|
|
//
|
|
// Test Case
|
|
//
|
|
{description: `remove scalar -- null in src, null in dest`,
|
|
source: `
|
|
kind: Deployment
|
|
field: null
|
|
`,
|
|
dest: `
|
|
kind: Deployment
|
|
field: null
|
|
`,
|
|
expected: `
|
|
kind: Deployment
|
|
`,
|
|
mergeOptions: yaml.MergeOptions{
|
|
ListIncreaseDirection: yaml.MergeOptionsListAppend,
|
|
},
|
|
},
|
|
|
|
//
|
|
// Test Case
|
|
//
|
|
{description: `keep scalar -- missing in src, null in dest`,
|
|
source: `
|
|
kind: Deployment
|
|
`,
|
|
dest: `
|
|
kind: Deployment
|
|
field: null
|
|
`,
|
|
expected: `
|
|
kind: Deployment
|
|
field: null
|
|
`,
|
|
mergeOptions: yaml.MergeOptions{
|
|
ListIncreaseDirection: yaml.MergeOptionsListAppend,
|
|
},
|
|
},
|
|
{description: `keep scalar -- missing in src, null in dest, preserves null marker`,
|
|
source: `
|
|
kind: Deployment
|
|
`,
|
|
dest: `
|
|
kind: Deployment
|
|
field: ~
|
|
`,
|
|
expected: `
|
|
kind: Deployment
|
|
field: ~
|
|
`,
|
|
mergeOptions: yaml.MergeOptions{
|
|
ListIncreaseDirection: yaml.MergeOptionsListAppend,
|
|
},
|
|
},
|
|
|
|
//
|
|
// Test Case
|
|
//
|
|
{description: `merge an empty value`,
|
|
source: `
|
|
kind: Deployment
|
|
field: {}
|
|
`,
|
|
dest: `
|
|
kind: Deployment
|
|
`,
|
|
expected: `
|
|
kind: Deployment
|
|
field: {}
|
|
`,
|
|
mergeOptions: yaml.MergeOptions{
|
|
ListIncreaseDirection: yaml.MergeOptionsListAppend,
|
|
},
|
|
},
|
|
}
|