mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 01:14:22 +00:00
add option to choose prepend/append in merge
This commit is contained in:
@@ -3,6 +3,10 @@
|
||||
|
||||
package merge2_test
|
||||
|
||||
import (
|
||||
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||
)
|
||||
|
||||
var listTestCases = []testCase{
|
||||
{description: `strategic merge patch delete 1`,
|
||||
source: `
|
||||
@@ -38,6 +42,9 @@ spec:
|
||||
- name: foo2
|
||||
- name: foo3
|
||||
`,
|
||||
mergeOptions: yaml.MergeOptions{
|
||||
ListIncreaseDirection: yaml.MergeOptionsListAppend,
|
||||
},
|
||||
},
|
||||
{description: `strategic merge patch delete 2`,
|
||||
source: `
|
||||
@@ -73,8 +80,48 @@ spec:
|
||||
- name: foo1
|
||||
- name: foo2
|
||||
`,
|
||||
mergeOptions: yaml.MergeOptions{
|
||||
ListIncreaseDirection: yaml.MergeOptionsListAppend,
|
||||
},
|
||||
},
|
||||
{description: `merge k8s deployment containers`,
|
||||
{description: `merge k8s deployment containers - prepend`,
|
||||
source: `
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: foo1
|
||||
- name: foo2
|
||||
- name: foo3
|
||||
`,
|
||||
dest: `
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: foo0
|
||||
`,
|
||||
expected: `
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: foo1
|
||||
- name: foo2
|
||||
- name: foo3
|
||||
- name: foo0
|
||||
`,
|
||||
mergeOptions: yaml.MergeOptions{
|
||||
ListIncreaseDirection: yaml.MergeOptionsListPrepend,
|
||||
},
|
||||
},
|
||||
{description: `merge k8s deployment containers - append`,
|
||||
source: `
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
@@ -107,8 +154,11 @@ spec:
|
||||
- name: foo2
|
||||
- name: foo3
|
||||
`,
|
||||
mergeOptions: yaml.MergeOptions{
|
||||
ListIncreaseDirection: yaml.MergeOptionsListAppend,
|
||||
},
|
||||
},
|
||||
{description: `merge k8s deployment volumes`,
|
||||
{description: `merge k8s deployment volumes - append`,
|
||||
source: `
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
@@ -141,6 +191,46 @@ spec:
|
||||
- name: foo2
|
||||
- name: foo3
|
||||
`,
|
||||
mergeOptions: yaml.MergeOptions{
|
||||
ListIncreaseDirection: yaml.MergeOptionsListAppend,
|
||||
},
|
||||
},
|
||||
{description: `merge k8s deployment volumes - prepend`,
|
||||
source: `
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
volumes:
|
||||
- name: foo1
|
||||
- name: foo2
|
||||
- name: foo3
|
||||
`,
|
||||
dest: `
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
volumes:
|
||||
- name: foo0
|
||||
`,
|
||||
expected: `
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
volumes:
|
||||
- name: foo1
|
||||
- name: foo2
|
||||
- name: foo3
|
||||
- name: foo0
|
||||
`,
|
||||
mergeOptions: yaml.MergeOptions{
|
||||
ListIncreaseDirection: yaml.MergeOptionsListPrepend,
|
||||
},
|
||||
},
|
||||
{description: `merge k8s deployment containers -- $patch directive`,
|
||||
source: `
|
||||
@@ -267,6 +357,9 @@ items:
|
||||
- 2
|
||||
- 3
|
||||
`,
|
||||
mergeOptions: yaml.MergeOptions{
|
||||
ListIncreaseDirection: yaml.MergeOptionsListAppend,
|
||||
},
|
||||
},
|
||||
|
||||
{description: `replace List -- missing from dest`,
|
||||
@@ -287,6 +380,9 @@ items:
|
||||
- 2
|
||||
- 3
|
||||
`,
|
||||
mergeOptions: yaml.MergeOptions{
|
||||
ListIncreaseDirection: yaml.MergeOptionsListAppend,
|
||||
},
|
||||
},
|
||||
|
||||
//
|
||||
@@ -314,6 +410,9 @@ items:
|
||||
- 2
|
||||
- 3
|
||||
`,
|
||||
mergeOptions: yaml.MergeOptions{
|
||||
ListIncreaseDirection: yaml.MergeOptionsListAppend,
|
||||
},
|
||||
},
|
||||
|
||||
//
|
||||
@@ -337,6 +436,9 @@ items:
|
||||
- 2
|
||||
- 3
|
||||
`,
|
||||
mergeOptions: yaml.MergeOptions{
|
||||
ListIncreaseDirection: yaml.MergeOptionsListAppend,
|
||||
},
|
||||
},
|
||||
|
||||
//
|
||||
@@ -357,6 +459,9 @@ items:
|
||||
expected: `
|
||||
kind: Deployment
|
||||
`,
|
||||
mergeOptions: yaml.MergeOptions{
|
||||
ListIncreaseDirection: yaml.MergeOptionsListAppend,
|
||||
},
|
||||
},
|
||||
|
||||
//
|
||||
@@ -378,5 +483,8 @@ items:
|
||||
kind: Deployment
|
||||
items: []
|
||||
`,
|
||||
mergeOptions: yaml.MergeOptions{
|
||||
ListIncreaseDirection: yaml.MergeOptionsListAppend,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user