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:
Phillip Wittrock
2020-02-27 10:08:40 -08:00
parent 8991b193c6
commit 5d1a0346b5
24 changed files with 991 additions and 507 deletions

View File

@@ -9,224 +9,226 @@ var listTestCases = []testCase{
//
// Test Case
//
{`Replace list`,
`
{description: `Replace list`,
origin: `
list:
- 1
- 2
- 3`,
`
update: `
list:
- 2
- 3
- 4`,
`
local: `
list:
- 1
- 2
- 3`,
`
expected: `
list:
- 2
- 3
- 4`, nil},
- 4`},
//
// Test Case
//
{`Add an updated list`,
`
{description: `Add an updated list`,
origin: `
apiVersion: apps/v1
list: # old value
- 1
- 2
- 3
`,
`
update: `
apiVersion: apps/v1
list: # new value
- 2
- 3
- 4
`,
`
local: `
apiVersion: apps/v1`,
`
expected: `
apiVersion: apps/v1
list:
- 2
- 3
- 4
`, nil},
`},
//
// Test Case
//
{`Add keep an omitted field`,
`
{description: `Add keep an omitted field`,
origin: `
apiVersion: apps/v1
kind: Deployment`,
`
update: `
apiVersion: apps/v1
kind: StatefulSet`,
`
local: `
apiVersion: apps/v1
list: # not present in sources
- 2
- 3
- 4
`,
`
expected: `
apiVersion: apps/v1
list: # not present in sources
- 2
- 3
- 4
kind: StatefulSet
`, nil},
`},
//
// Test Case
//
// TODO(#36): consider making this an error
{`Change an updated field`,
`
{description: `Change an updated field`,
origin: `
apiVersion: apps/v1
list: # old value
- 1
- 2
- 3`,
`
update: `
apiVersion: apps/v1
list: # new value
- 2
- 3
- 4`,
`
local: `
apiVersion: apps/v1
list: # conflicting value
- a
- b
- c`,
`
expected: `
apiVersion: apps/v1
list: # conflicting value
- 2
- 3
- 4
`, nil},
`},
//
// Test Case
//
{`Ignore a field -- set`,
`
{description: `Ignore a field -- set`,
origin: `
apiVersion: apps/v1
list: # ignore value
- 1
- 2
- 3
`,
`
update: `
apiVersion: apps/v1
list: # ignore value
- 1
- 2
- 3`, `
- 3`,
local: `
apiVersion: apps/v1
list:
- 2
- 3
- 4
`, `
`,
expected: `
apiVersion: apps/v1
list:
- 2
- 3
- 4
`, nil},
`},
//
// Test Case
//
{`Ignore a field -- empty`,
`
{description: `Ignore a field -- empty`,
origin: `
apiVersion: apps/v1
list: # ignore value
- 1
- 2
- 3`,
`
update: `
apiVersion: apps/v1
list: # ignore value
- 1
- 2
- 3`,
`
local: `
apiVersion: apps/v1
`,
`
expected: `
apiVersion: apps/v1
`, nil},
`},
//
// Test Case
//
{`Explicitly clear a field`,
`
{description: `Explicitly clear a field`,
origin: `
apiVersion: apps/v1`,
`
update: `
apiVersion: apps/v1
list: null # clear`,
`
local: `
apiVersion: apps/v1
list: # value to clear
- 1
- 2
- 3`,
`
apiVersion: apps/v1`, nil},
expected: `
apiVersion: apps/v1`},
//
// Test Case
//
{`Implicitly clear a field`,
`
{description: `Implicitly clear a field`,
origin: `
apiVersion: apps/v1
list: # clear value
- 1
- 2
- 3`,
`
update: `
apiVersion: apps/v1`,
`
local: `
apiVersion: apps/v1
list: # old value
- 1
- 2
- 3`,
`
apiVersion: apps/v1`, nil},
expected: `
apiVersion: apps/v1`},
//
// Test Case
//
// TODO(#36): consider making this an error
{`Implicitly clear a changed field`,
`
{description: `Implicitly clear a changed field`,
origin: `
apiVersion: apps/v1
list: # old value
- 1
- 2
- 3`,
`
update: `
apiVersion: apps/v1`,
`
local: `
apiVersion: apps/v1
list: # old value
- a
- b
- c`,
`
apiVersion: apps/v1`, nil},
expected: `
apiVersion: apps/v1`},
}