mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-21 01:26:28 +00:00
Fix strategic merge patch $deleteFromPrimitiveList bug
If the $deleteFromPrimitiveList directive is used in a strategic merge patch and the field being deleted from does not have a patch strategy of merge, strategic merge patch would not perform the deletion and instead would replace the contents of the field with the values attempting to be deleted. This commit changes strategic merge patch to always perform a deletion when the $deleteFromPrimitiveList directive is used, regardless of what the patch strategy of the field is.
This commit is contained in:
parent
526650fc13
commit
95fe0a158c
@ -1425,7 +1425,8 @@ func mergeSliceHandler(original, patch interface{}, schema LookupPatchMeta,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if fieldPatchStrategy == mergeDirective {
|
||||
// Delete lists are handled the same way regardless of what the field's patch strategy is
|
||||
if fieldPatchStrategy == mergeDirective || isDeleteList {
|
||||
return mergeSlice(typedOriginal, typedPatch, schema, fieldPatchMergeKey, mergeOptions, isDeleteList)
|
||||
} else {
|
||||
return typedPatch, nil
|
||||
|
@ -717,6 +717,46 @@ $deleteFromPrimitiveList/mergingIntList:
|
||||
Modified: []byte(`
|
||||
foo:
|
||||
- bar
|
||||
`),
|
||||
},
|
||||
},
|
||||
{
|
||||
Description: "$deleteFromPrimitiveList should delete item from a list with merge patch strategy",
|
||||
StrategicMergePatchRawTestCaseData: StrategicMergePatchRawTestCaseData{
|
||||
Original: []byte(`
|
||||
mergingIntList:
|
||||
- 1
|
||||
- 2
|
||||
- 3
|
||||
`),
|
||||
TwoWay: []byte(`
|
||||
$deleteFromPrimitiveList/mergingIntList:
|
||||
- 2
|
||||
`),
|
||||
Modified: []byte(`
|
||||
mergingIntList:
|
||||
- 1
|
||||
- 3
|
||||
`),
|
||||
},
|
||||
},
|
||||
{
|
||||
Description: "$deleteFromPrimitiveList should delete item from a list without merge patch strategy",
|
||||
StrategicMergePatchRawTestCaseData: StrategicMergePatchRawTestCaseData{
|
||||
Original: []byte(`
|
||||
nonMergingIntList:
|
||||
- 1
|
||||
- 2
|
||||
- 3
|
||||
`),
|
||||
TwoWay: []byte(`
|
||||
$deleteFromPrimitiveList/nonMergingIntList:
|
||||
- 2
|
||||
`),
|
||||
Modified: []byte(`
|
||||
nonMergingIntList:
|
||||
- 1
|
||||
- 3
|
||||
`),
|
||||
},
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user