mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Fix bug where attempting to use patch with deleteFromPrimitiveList on an empty or nonexistent list incorrectly adds the item to be removed.
This commit is contained in:
parent
0ac956ff2b
commit
8a72a54d7c
@ -1328,15 +1328,19 @@ func mergeMap(original, patch map[string]interface{}, schema LookupPatchMeta, me
|
||||
|
||||
_, ok := original[k]
|
||||
if !ok {
|
||||
if !isDeleteList {
|
||||
// If it's not in the original document, just take the patch value.
|
||||
original[k] = patchV
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
originalType := reflect.TypeOf(original[k])
|
||||
patchType := reflect.TypeOf(patchV)
|
||||
if originalType != patchType {
|
||||
if !isDeleteList {
|
||||
original[k] = patchV
|
||||
}
|
||||
continue
|
||||
}
|
||||
// If they're both maps or lists, recurse into the value.
|
||||
|
@ -669,6 +669,57 @@ mergingList:
|
||||
ExpectedError: "does not contain declared merge key",
|
||||
},
|
||||
},
|
||||
{
|
||||
Description: "$deleteFromPrimitiveList of nonexistent item in primitive list should not add the item to the list",
|
||||
StrategicMergePatchRawTestCaseData: StrategicMergePatchRawTestCaseData{
|
||||
Original: []byte(`
|
||||
mergingIntList:
|
||||
- 1
|
||||
- 2
|
||||
`),
|
||||
TwoWay: []byte(`
|
||||
$deleteFromPrimitiveList/mergingIntList:
|
||||
- 3
|
||||
`),
|
||||
Modified: []byte(`
|
||||
mergingIntList:
|
||||
- 1
|
||||
- 2
|
||||
`),
|
||||
},
|
||||
},
|
||||
{
|
||||
Description: "$deleteFromPrimitiveList on empty primitive list should not add the item to the list",
|
||||
StrategicMergePatchRawTestCaseData: StrategicMergePatchRawTestCaseData{
|
||||
Original: []byte(`
|
||||
mergingIntList:
|
||||
`),
|
||||
TwoWay: []byte(`
|
||||
$deleteFromPrimitiveList/mergingIntList:
|
||||
- 3
|
||||
`),
|
||||
Modified: []byte(`
|
||||
mergingIntList:
|
||||
`),
|
||||
},
|
||||
},
|
||||
{
|
||||
Description: "$deleteFromPrimitiveList on nonexistent primitive list should not add the primitive list",
|
||||
StrategicMergePatchRawTestCaseData: StrategicMergePatchRawTestCaseData{
|
||||
Original: []byte(`
|
||||
foo:
|
||||
- bar
|
||||
`),
|
||||
TwoWay: []byte(`
|
||||
$deleteFromPrimitiveList/mergingIntList:
|
||||
- 3
|
||||
`),
|
||||
Modified: []byte(`
|
||||
foo:
|
||||
- bar
|
||||
`),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func TestCustomStrategicMergePatch(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user