mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 01:14:22 +00:00
Use OpenAPI when merging (3way) resources
- When merging (3way) resources use the patch strategy from the openAPI if the definition exists for the field - Allow disabling of guessing patch strategy merge keys when no definition exists - Support defining strategy and key directly on configuration fields through line and header coments - Support attaching schema to parent fields of lists, and propagating -- e.g. that a field is a PodTemplate
This commit is contained in:
@@ -7,14 +7,14 @@ var elementTestCases = []testCase{
|
||||
//
|
||||
// Test Case
|
||||
//
|
||||
{`Add an element to an existing list`,
|
||||
`
|
||||
{description: `Add an element to an existing list`,
|
||||
origin: `
|
||||
kind: Deployment
|
||||
containers:
|
||||
- name: foo
|
||||
image: foo:1
|
||||
`,
|
||||
`
|
||||
update: `
|
||||
kind: Deployment
|
||||
containers:
|
||||
- name: foo
|
||||
@@ -22,13 +22,13 @@ containers:
|
||||
- name: baz
|
||||
image: baz:2
|
||||
`,
|
||||
`
|
||||
local: `
|
||||
kind: Deployment
|
||||
containers:
|
||||
- name: foo
|
||||
image: foo:1
|
||||
`,
|
||||
`
|
||||
expected: `
|
||||
kind: Deployment
|
||||
containers:
|
||||
- name: foo
|
||||
@@ -36,65 +36,65 @@ containers:
|
||||
- image: baz:2
|
||||
name: baz
|
||||
|
||||
`, nil},
|
||||
`},
|
||||
|
||||
//
|
||||
// Test Case
|
||||
//
|
||||
{`Add an element to a non-existing list`,
|
||||
`
|
||||
{description: `Add an element to a non-existing list`,
|
||||
origin: `
|
||||
kind: Deployment`,
|
||||
`
|
||||
update: `
|
||||
kind: Deployment
|
||||
containers:
|
||||
- name: foo
|
||||
image: foo:bar
|
||||
`,
|
||||
`
|
||||
local: `
|
||||
kind: Deployment
|
||||
`,
|
||||
`
|
||||
expected: `
|
||||
kind: Deployment
|
||||
containers:
|
||||
- image: foo:bar
|
||||
name: foo
|
||||
`, nil},
|
||||
`},
|
||||
|
||||
{`Add an element to a non-existing list, existing in dest`,
|
||||
`
|
||||
{description: `Add an element to a non-existing list, existing in dest`,
|
||||
origin: `
|
||||
kind: Deployment`,
|
||||
`
|
||||
update: `
|
||||
kind: Deployment
|
||||
containers:
|
||||
- name: foo
|
||||
image: foo:bar
|
||||
`,
|
||||
`
|
||||
local: `
|
||||
kind: Deployment
|
||||
containers:
|
||||
- name: baz
|
||||
image: baz:bar
|
||||
`,
|
||||
`
|
||||
expected: `
|
||||
kind: Deployment
|
||||
containers:
|
||||
- name: baz
|
||||
image: baz:bar
|
||||
- image: foo:bar
|
||||
name: foo
|
||||
`, nil},
|
||||
`},
|
||||
|
||||
//
|
||||
// Test Case
|
||||
// TODO(pwittrock): Figure out if there is something better we can do here
|
||||
// This element is missing from the destination -- only the new fields are added
|
||||
{`Add a field to the element, element missing from dest`,
|
||||
`
|
||||
{description: `Add a field to the element, element missing from dest`,
|
||||
origin: `
|
||||
kind: Deployment
|
||||
containers:
|
||||
- name: foo
|
||||
image: foo:bar`,
|
||||
`
|
||||
update: `
|
||||
kind: Deployment
|
||||
containers:
|
||||
- name: foo
|
||||
@@ -102,22 +102,22 @@ containers:
|
||||
command:
|
||||
- run.sh
|
||||
`,
|
||||
`
|
||||
local: `
|
||||
kind: Deployment
|
||||
`,
|
||||
`
|
||||
expected: `
|
||||
kind: Deployment
|
||||
containers:
|
||||
- command:
|
||||
- run.sh
|
||||
name: foo
|
||||
`, nil},
|
||||
`},
|
||||
|
||||
//
|
||||
// Test Case
|
||||
//
|
||||
{`Update a field on the elem, element missing from the dest`,
|
||||
`
|
||||
{description: `Update a field on the elem, element missing from the dest`,
|
||||
origin: `
|
||||
kind: Deployment
|
||||
containers:
|
||||
- name: foo
|
||||
@@ -125,7 +125,7 @@ containers:
|
||||
command:
|
||||
- run.sh
|
||||
`,
|
||||
`
|
||||
update: `
|
||||
kind: Deployment
|
||||
containers:
|
||||
- name: foo
|
||||
@@ -133,210 +133,210 @@ containers:
|
||||
command:
|
||||
- run2.sh
|
||||
`,
|
||||
`
|
||||
local: `
|
||||
kind: Deployment
|
||||
`,
|
||||
`
|
||||
expected: `
|
||||
kind: Deployment
|
||||
containers:
|
||||
- command:
|
||||
- run2.sh
|
||||
name: foo
|
||||
`, nil},
|
||||
`},
|
||||
|
||||
//
|
||||
// Test Case
|
||||
//
|
||||
{`Update a field on the elem, element present in the dest`,
|
||||
`
|
||||
{description: `Update a field on the elem, element present in the dest`,
|
||||
origin: `
|
||||
kind: Deployment
|
||||
containers:
|
||||
- name: foo
|
||||
image: foo:bar
|
||||
command: ['run.sh']
|
||||
`,
|
||||
`
|
||||
update: `
|
||||
kind: Deployment
|
||||
containers:
|
||||
- name: foo
|
||||
image: foo:bar
|
||||
command: ['run2.sh']
|
||||
`,
|
||||
`
|
||||
local: `
|
||||
kind: Deployment
|
||||
containers:
|
||||
- name: foo
|
||||
image: foo:bar
|
||||
command: ['run.sh']
|
||||
`,
|
||||
`
|
||||
expected: `
|
||||
kind: Deployment
|
||||
containers:
|
||||
- name: foo
|
||||
image: foo:bar
|
||||
command: ['run2.sh']
|
||||
`, nil},
|
||||
`},
|
||||
|
||||
//
|
||||
// Test Case
|
||||
//
|
||||
{`Add a field on the elem, element present in the dest`,
|
||||
`
|
||||
{description: `Add a field on the elem, element present in the dest`,
|
||||
origin: `
|
||||
kind: Deployment
|
||||
containers:
|
||||
- name: foo
|
||||
image: foo:bar
|
||||
`,
|
||||
`
|
||||
update: `
|
||||
kind: Deployment
|
||||
containers:
|
||||
- name: foo
|
||||
image: foo:bar
|
||||
command: ['run2.sh']
|
||||
`,
|
||||
`
|
||||
local: `
|
||||
kind: Deployment
|
||||
containers:
|
||||
- name: foo
|
||||
image: foo:bar
|
||||
`,
|
||||
`
|
||||
expected: `
|
||||
kind: Deployment
|
||||
containers:
|
||||
- name: foo
|
||||
image: foo:bar
|
||||
command: ['run2.sh']
|
||||
`, nil},
|
||||
`},
|
||||
|
||||
//
|
||||
// Test Case
|
||||
//
|
||||
{`Add a field on the elem, element and field present in the dest`,
|
||||
`
|
||||
{description: `Add a field on the elem, element and field present in the dest`,
|
||||
origin: `
|
||||
kind: Deployment
|
||||
containers:
|
||||
- name: foo
|
||||
image: foo:bar
|
||||
`,
|
||||
`
|
||||
update: `
|
||||
kind: Deployment
|
||||
containers:
|
||||
- name: foo
|
||||
image: foo:bar
|
||||
command: ['run2.sh']
|
||||
`,
|
||||
`
|
||||
local: `
|
||||
kind: Deployment
|
||||
containers:
|
||||
- name: foo
|
||||
image: foo:bar
|
||||
command: ['run.sh']
|
||||
`,
|
||||
`
|
||||
expected: `
|
||||
kind: Deployment
|
||||
containers:
|
||||
- name: foo
|
||||
image: foo:bar
|
||||
command: ['run2.sh']
|
||||
`, nil},
|
||||
`},
|
||||
|
||||
//
|
||||
// Test Case
|
||||
//
|
||||
{`Ignore an element`,
|
||||
`
|
||||
{description: `Ignore an element`,
|
||||
origin: `
|
||||
kind: Deployment
|
||||
containers: {}
|
||||
`,
|
||||
`
|
||||
update: `
|
||||
kind: Deployment
|
||||
containers: {}
|
||||
`,
|
||||
`
|
||||
local: `
|
||||
kind: Deployment
|
||||
containers:
|
||||
- name: foo
|
||||
image: foo:bar
|
||||
`,
|
||||
`
|
||||
expected: `
|
||||
kind: Deployment
|
||||
containers:
|
||||
- name: foo
|
||||
image: foo:bar
|
||||
`, nil},
|
||||
`},
|
||||
|
||||
//
|
||||
// Test Case
|
||||
//
|
||||
{`Leave deleted`,
|
||||
`
|
||||
{description: `Leave deleted`,
|
||||
origin: `
|
||||
kind: Deployment
|
||||
containers:
|
||||
- name: foo
|
||||
image: foo:bar
|
||||
`,
|
||||
`
|
||||
update: `
|
||||
kind: Deployment
|
||||
`,
|
||||
`
|
||||
local: `
|
||||
kind: Deployment
|
||||
`,
|
||||
`
|
||||
expected: `
|
||||
kind: Deployment
|
||||
`, nil},
|
||||
`},
|
||||
|
||||
//
|
||||
// Test Case
|
||||
//
|
||||
{`Remove an element -- matching`,
|
||||
`
|
||||
{description: `Remove an element -- matching`,
|
||||
origin: `
|
||||
kind: Deployment
|
||||
containers:
|
||||
- name: foo
|
||||
image: foo:bar
|
||||
`,
|
||||
`
|
||||
update: `
|
||||
kind: Deployment
|
||||
`,
|
||||
`
|
||||
local: `
|
||||
kind: Deployment
|
||||
containers:
|
||||
- name: foo
|
||||
image: foo:bar
|
||||
`,
|
||||
`
|
||||
expected: `
|
||||
kind: Deployment
|
||||
`, nil},
|
||||
`},
|
||||
|
||||
//
|
||||
// Test Case
|
||||
//
|
||||
{`Remove an element -- field missing from update`,
|
||||
`
|
||||
{description: `Remove an element -- field missing from update`,
|
||||
origin: `
|
||||
kind: Deployment
|
||||
containers:
|
||||
- name: foo
|
||||
image: foo:bar
|
||||
`,
|
||||
`
|
||||
update: `
|
||||
kind: Deployment
|
||||
`,
|
||||
`
|
||||
local: `
|
||||
kind: Deployment
|
||||
containers:
|
||||
- name: foo
|
||||
image: foo:bar
|
||||
command: ['run.sh']
|
||||
`,
|
||||
`
|
||||
expected: `
|
||||
kind: Deployment
|
||||
`, nil},
|
||||
`},
|
||||
|
||||
//
|
||||
// Test Case
|
||||
//
|
||||
{`Remove an element -- element missing`,
|
||||
`
|
||||
{description: `Remove an element -- element missing`,
|
||||
origin: `
|
||||
kind: Deployment
|
||||
containers:
|
||||
- name: foo
|
||||
@@ -344,13 +344,13 @@ containers:
|
||||
- name: baz
|
||||
image: baz:bar
|
||||
`,
|
||||
`
|
||||
update: `
|
||||
kind: Deployment
|
||||
containers:
|
||||
- name: foo
|
||||
image: foo:bar
|
||||
`,
|
||||
`
|
||||
local: `
|
||||
kind: Deployment
|
||||
containers:
|
||||
- name: foo
|
||||
@@ -359,60 +359,273 @@ containers:
|
||||
- name: baz
|
||||
image: baz:bar
|
||||
`,
|
||||
`
|
||||
expected: `
|
||||
kind: Deployment
|
||||
containers:
|
||||
- name: foo
|
||||
image: foo:bar
|
||||
command: ['run.sh']
|
||||
`, nil},
|
||||
`},
|
||||
|
||||
//
|
||||
// Test Case
|
||||
//
|
||||
{`Remove an element -- empty containers`,
|
||||
`
|
||||
{description: `Remove an element -- empty containers`,
|
||||
origin: `
|
||||
kind: Deployment
|
||||
containers:
|
||||
- name: foo
|
||||
image: foo:bar
|
||||
`,
|
||||
`
|
||||
update: `
|
||||
kind: Deployment
|
||||
containers: {}
|
||||
`,
|
||||
`
|
||||
local: `
|
||||
kind: Deployment
|
||||
containers:
|
||||
- name: foo
|
||||
image: foo:bar
|
||||
command: ['run.sh']
|
||||
`,
|
||||
`
|
||||
expected: `
|
||||
kind: Deployment
|
||||
`, nil},
|
||||
`},
|
||||
|
||||
//
|
||||
// Test Case
|
||||
//
|
||||
{`Remove an element -- missing list field`,
|
||||
`
|
||||
{description: `Remove an element -- missing list field`,
|
||||
origin: `
|
||||
kind: Deployment
|
||||
containers:
|
||||
- name: foo
|
||||
image: foo:bar
|
||||
`,
|
||||
`
|
||||
update: `
|
||||
kind: Deployment
|
||||
`,
|
||||
`
|
||||
local: `
|
||||
kind: Deployment
|
||||
containers:
|
||||
- name: foo
|
||||
image: foo:bar
|
||||
command: ['run.sh']
|
||||
`,
|
||||
`
|
||||
expected: `
|
||||
kind: Deployment
|
||||
`, nil},
|
||||
`},
|
||||
|
||||
//
|
||||
// Test Case
|
||||
//
|
||||
{description: `no infer merge keys no merge'`,
|
||||
origin: `
|
||||
kind: Deployment
|
||||
containers:
|
||||
- name: foo
|
||||
`,
|
||||
update: `
|
||||
kind: Deployment
|
||||
containers:
|
||||
- name: foo
|
||||
command: ['run2.sh']
|
||||
`,
|
||||
local: `
|
||||
kind: Deployment
|
||||
containers:
|
||||
- name: foo
|
||||
image: foo:bar
|
||||
`,
|
||||
expected: `
|
||||
kind: Deployment
|
||||
containers:
|
||||
- name: foo
|
||||
command: ['run2.sh']
|
||||
`,
|
||||
noInfer: true,
|
||||
},
|
||||
|
||||
//
|
||||
// Test Case
|
||||
//
|
||||
{description: `no infer merge keys merge using schema`,
|
||||
origin: `
|
||||
kind: Deployment
|
||||
apiVersion: apps/v1
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: foo
|
||||
`,
|
||||
update: `
|
||||
kind: Deployment
|
||||
apiVersion: apps/v1
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: foo
|
||||
command: ['run2.sh']
|
||||
`,
|
||||
local: `
|
||||
kind: Deployment
|
||||
apiVersion: apps/v1
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: foo
|
||||
image: foo:bar
|
||||
`,
|
||||
expected: `
|
||||
kind: Deployment
|
||||
apiVersion: apps/v1
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: foo
|
||||
image: foo:bar
|
||||
command: ['run2.sh']
|
||||
`,
|
||||
noInfer: true,
|
||||
},
|
||||
|
||||
//
|
||||
// Test Case
|
||||
//
|
||||
{description: `no infer merge keys merge using explicit schema as line comment'`,
|
||||
origin: `
|
||||
kind: Deployment
|
||||
containers:
|
||||
- name: foo
|
||||
`,
|
||||
update: `
|
||||
kind: Deployment
|
||||
containers:
|
||||
- name: foo
|
||||
command: ['run2.sh']
|
||||
`,
|
||||
local: `
|
||||
kind: Deployment
|
||||
containers: # {"items":{"$ref": "#/definitions/io.k8s.api.core.v1.Container"},"type":"array","x-kubernetes-patch-merge-key":"name","x-kubernetes-patch-strategy": "merge"}
|
||||
- name: foo # hell ow
|
||||
image: foo:bar
|
||||
`,
|
||||
expected: `
|
||||
kind: Deployment
|
||||
containers: # {"items":{"$ref": "#/definitions/io.k8s.api.core.v1.Container"},"type":"array","x-kubernetes-patch-merge-key":"name","x-kubernetes-patch-strategy": "merge"}
|
||||
- name: foo # hell ow
|
||||
image: foo:bar
|
||||
command: ['run2.sh']
|
||||
`,
|
||||
noInfer: true,
|
||||
},
|
||||
|
||||
//
|
||||
// Test Case
|
||||
//
|
||||
{description: `no infer merge keys merge using explicit schema as head comment'`,
|
||||
origin: `
|
||||
kind: Deployment
|
||||
containers:
|
||||
- name: foo
|
||||
`,
|
||||
update: `
|
||||
kind: Deployment
|
||||
containers:
|
||||
- name: foo
|
||||
command: ['run2.sh']
|
||||
`,
|
||||
local: `
|
||||
kind: Deployment
|
||||
# {"items":{"$ref": "#/definitions/io.k8s.api.core.v1.Container"},"type":"array","x-kubernetes-patch-merge-key":"name","x-kubernetes-patch-strategy": "merge"}
|
||||
containers:
|
||||
- name: foo # hell ow
|
||||
image: foo:bar
|
||||
`,
|
||||
expected: `
|
||||
kind: Deployment
|
||||
# {"items":{"$ref": "#/definitions/io.k8s.api.core.v1.Container"},"type":"array","x-kubernetes-patch-merge-key":"name","x-kubernetes-patch-strategy": "merge"}
|
||||
containers:
|
||||
- name: foo # hell ow
|
||||
image: foo:bar
|
||||
command: ['run2.sh']
|
||||
`,
|
||||
noInfer: true,
|
||||
},
|
||||
|
||||
//
|
||||
// Test Case
|
||||
//
|
||||
{description: `no infer merge keys merge using explicit schema to parent field'`,
|
||||
origin: `
|
||||
kind: Deployment
|
||||
spec:
|
||||
containers:
|
||||
- name: foo
|
||||
`,
|
||||
update: `
|
||||
kind: Deployment
|
||||
spec:
|
||||
containers:
|
||||
- name: foo
|
||||
command: ['run2.sh']
|
||||
`,
|
||||
local: `
|
||||
kind: Deployment
|
||||
spec: # {"$ref":"#/definitions/io.k8s.api.core.v1.PodSpec"}
|
||||
containers:
|
||||
- name: foo # hell ow
|
||||
image: foo:bar
|
||||
`,
|
||||
expected: `
|
||||
kind: Deployment
|
||||
spec: # {"$ref":"#/definitions/io.k8s.api.core.v1.PodSpec"}
|
||||
containers:
|
||||
- name: foo # hell ow
|
||||
image: foo:bar
|
||||
command: ['run2.sh']
|
||||
`,
|
||||
noInfer: true,
|
||||
},
|
||||
|
||||
//
|
||||
// Test Case
|
||||
//
|
||||
{description: `no infer merge keys merge using explicit schema to parent field header'`,
|
||||
origin: `
|
||||
kind: Deployment
|
||||
spec:
|
||||
containers:
|
||||
- name: foo
|
||||
`,
|
||||
update: `
|
||||
kind: Deployment
|
||||
spec:
|
||||
containers:
|
||||
- name: foo
|
||||
command: ['run2.sh']
|
||||
`,
|
||||
local: `
|
||||
kind: Deployment
|
||||
# {"$ref":"#/definitions/io.k8s.api.core.v1.PodSpec"}
|
||||
spec:
|
||||
containers:
|
||||
- name: foo # hell ow
|
||||
image: foo:bar
|
||||
`,
|
||||
expected: `
|
||||
kind: Deployment
|
||||
# {"$ref":"#/definitions/io.k8s.api.core.v1.PodSpec"}
|
||||
spec:
|
||||
containers:
|
||||
- name: foo # hell ow
|
||||
image: foo:bar
|
||||
command: ['run2.sh']
|
||||
`,
|
||||
noInfer: true,
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user