diff --git a/staging/src/k8s.io/apimachinery/pkg/util/strategicpatch/patch.go b/staging/src/k8s.io/apimachinery/pkg/util/strategicpatch/patch.go index 3ee683b9970..341a092f86d 100644 --- a/staging/src/k8s.io/apimachinery/pkg/util/strategicpatch/patch.go +++ b/staging/src/k8s.io/apimachinery/pkg/util/strategicpatch/patch.go @@ -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 diff --git a/staging/src/k8s.io/apimachinery/pkg/util/strategicpatch/patch_test.go b/staging/src/k8s.io/apimachinery/pkg/util/strategicpatch/patch_test.go index 88692ad0612..864cbdf5edf 100644 --- a/staging/src/k8s.io/apimachinery/pkg/util/strategicpatch/patch_test.go +++ b/staging/src/k8s.io/apimachinery/pkg/util/strategicpatch/patch_test.go @@ -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 `), }, },