Skip to content

Commit

Permalink
Merge pull request kubernetes#18331 from mfojtik/pick-57854
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue (batch tested with PRs 18225, 18351, 18331, 18340, 18326).

UPSTREAM: 57854: fix bug of swallowing missing merge key error

fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1529659

Origin-commit: db03c4980ab2a7c4d1cd85ca0cf9bb1b3e5411d7
  • Loading branch information
k8s-publishing-bot committed Jan 31, 2018
2 parents 0002f41 + 481d78a commit 9cba812
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
24 changes: 12 additions & 12 deletions staging/src/k8s.io/apimachinery/pkg/util/strategicpatch/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -1322,23 +1322,23 @@ func mergeMap(original, patch map[string]interface{}, schema LookupPatchMeta, me
// If they're both maps or lists, recurse into the value.
switch originalType.Kind() {
case reflect.Map:
subschema, patchMeta, err := schema.LookupPatchMetadataForStruct(k)
if err != nil {
return nil, err
subschema, patchMeta, err2 := schema.LookupPatchMetadataForStruct(k)
if err2 != nil {
return nil, err2
}
_, patchStrategy, err := extractRetainKeysPatchStrategy(patchMeta.GetPatchStrategies())
if err != nil {
return nil, err
_, patchStrategy, err2 := extractRetainKeysPatchStrategy(patchMeta.GetPatchStrategies())
if err2 != nil {
return nil, err2
}
original[k], err = mergeMapHandler(original[k], patchV, subschema, patchStrategy, mergeOptions)
case reflect.Slice:
subschema, patchMeta, err := schema.LookupPatchMetadataForSlice(k)
if err != nil {
return nil, err
subschema, patchMeta, err2 := schema.LookupPatchMetadataForSlice(k)
if err2 != nil {
return nil, err2
}
_, patchStrategy, err := extractRetainKeysPatchStrategy(patchMeta.GetPatchStrategies())
if err != nil {
return nil, err
_, patchStrategy, err2 := extractRetainKeysPatchStrategy(patchMeta.GetPatchStrategies())
if err2 != nil {
return nil, err2
}
original[k], err = mergeSliceHandler(original[k], patchV, subschema, patchStrategy, patchMeta.GetPatchMergeKey(), isDeleteList, mergeOptions)
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,21 @@ mergingIntList:
ExpectedError: "doesn't match",
},
},
{
Description: "missing merge key should error out",
StrategicMergePatchRawTestCaseData: StrategicMergePatchRawTestCaseData{
Original: []byte(`
mergingList:
- name: 1
value: a
`),
TwoWay: []byte(`
mergingList:
- value: b
`),
ExpectedError: "does not contain declared merge key",
},
},
}

func TestCustomStrategicMergePatch(t *testing.T) {
Expand Down

0 comments on commit 9cba812

Please sign in to comment.