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

@@ -8,128 +8,128 @@ var scalarTestCases = []testCase{
//
// Test Case
//
{`Set and updated a field`,
`kind: Deployment`,
`kind: StatefulSet`,
`kind: Deployment`,
`kind: StatefulSet`, nil},
{description: `Set and updated a field`,
origin: `kind: Deployment`,
update: `kind: StatefulSet`,
local: `kind: Deployment`,
expected: `kind: StatefulSet`},
{`Add an updated field`,
`
{description: `Add an updated field`,
origin: `
apiVersion: apps/v1
kind: Deployment # old value`,
`
update: `
apiVersion: apps/v1
kind: StatefulSet # new value`,
`
local: `
apiVersion: apps/v1`,
`
expected: `
apiVersion: apps/v1
kind: StatefulSet # new value`, nil},
kind: StatefulSet # new value`},
{`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
spec: foo # field not present in source
`,
`
expected: `
apiVersion: apps/v1
spec: foo # field not present in source
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
kind: Deployment # old value`,
`
update: `
apiVersion: apps/v1
kind: StatefulSet # new value`,
`
local: `
apiVersion: apps/v1
kind: Service # conflicting value`,
`
expected: `
apiVersion: apps/v1
kind: StatefulSet # new value`, nil},
kind: StatefulSet # new value`},
{`Ignore a field`,
`
{description: `Ignore a field`,
origin: `
apiVersion: apps/v1
kind: Deployment # ignore this field`,
`
update: `
apiVersion: apps/v1
kind: Deployment # ignore this field`,
`
local: `
apiVersion: apps/v1`,
`
apiVersion: apps/v1`, nil},
expected: `
apiVersion: apps/v1`},
{`Explicitly clear a field`,
`
{description: `Explicitly clear a field`,
origin: `
apiVersion: apps/v1`,
`
update: `
apiVersion: apps/v1
kind: null # clear this value`,
`
local: `
apiVersion: apps/v1
kind: Deployment # value to be cleared`,
`
apiVersion: apps/v1`, nil},
expected: `
apiVersion: apps/v1`},
{`Implicitly clear a field`,
`
{description: `Implicitly clear a field`,
origin: `
apiVersion: apps/v1
kind: Deployment # clear this field`,
`
update: `
apiVersion: apps/v1`,
`
local: `
apiVersion: apps/v1
kind: Deployment # clear this field`,
`
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
kind: Deployment`,
`
update: `
apiVersion: apps/v1`,
`
local: `
apiVersion: apps/v1
kind: StatefulSet`,
`
apiVersion: apps/v1`, nil},
expected: `
apiVersion: apps/v1`},
//
// Test Case
//
{`Merge an empty scalar value`,
`
{description: `Merge an empty scalar value`,
origin: `
apiVersion: apps/v1
`,
`
update: `
apiVersion: apps/v1
kind: {}
`,
`
local: `
apiVersion: apps/v1
`,
`
expected: `
apiVersion: apps/v1
kind: {}
`, nil},
`},
}