mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Merge pull request #105421 from brianpursley/kubernetes-105146
Fix bug where using kubectl patch with $deleteFromPrimitiveList on an empty or nonexistent list adds the item to be removed
This commit is contained in:
commit
0b0007ae68
@ -1328,15 +1328,19 @@ func mergeMap(original, patch map[string]interface{}, schema LookupPatchMeta, me
|
|||||||
|
|
||||||
_, ok := original[k]
|
_, ok := original[k]
|
||||||
if !ok {
|
if !ok {
|
||||||
// If it's not in the original document, just take the patch value.
|
if !isDeleteList {
|
||||||
original[k] = patchV
|
// If it's not in the original document, just take the patch value.
|
||||||
|
original[k] = patchV
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
originalType := reflect.TypeOf(original[k])
|
originalType := reflect.TypeOf(original[k])
|
||||||
patchType := reflect.TypeOf(patchV)
|
patchType := reflect.TypeOf(patchV)
|
||||||
if originalType != patchType {
|
if originalType != patchType {
|
||||||
original[k] = patchV
|
if !isDeleteList {
|
||||||
|
original[k] = patchV
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// If they're both maps or lists, recurse into the value.
|
// If they're both maps or lists, recurse into the value.
|
||||||
|
@ -669,6 +669,57 @@ mergingList:
|
|||||||
ExpectedError: "does not contain declared merge key",
|
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) {
|
func TestCustomStrategicMergePatch(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user