Merge pull request #110472 from brianpursley/k-110407

Fix strategic merge patch $deleteFromPrimitiveList bug
This commit is contained in:
Kubernetes Prow Robot 2023-05-01 12:30:12 -07:00 committed by GitHub
commit 312bfa5505
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 1 deletions

View File

@ -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

View File

@ -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
`),
},
},