Skip to content

Commit

Permalink
Adding a check to filter out empty patch requests from an empty map o…
Browse files Browse the repository at this point in the history
…ut of the 3-way merge.
  • Loading branch information
chlam4 committed May 28, 2021
1 parent f855bd6 commit 03f4495
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 9 additions & 1 deletion internal/helm/release/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,15 @@ func createPatch(existing runtime.Object, expected *resource.Info) ([]byte, apit
}

patch, err := strategicpatch.CreateThreeWayMergePatch(expectedJSON, expectedJSON, existingJSON, patchMeta, true)
return patch, apitypes.StrategicMergePatchType, err
if err != nil {
return nil, apitypes.StrategicMergePatchType, err
}
// An empty patch could be in the form of "{}" which represents an empty map out of the 3-way merge;
// filter them out here too to avoid sending the apiserver empty patch requests.
if len(patch) == 0 || bytes.Equal(patch, []byte("{}")) {
return nil, apitypes.StrategicMergePatchType, nil
}
return patch, apitypes.StrategicMergePatchType, nil
}

func createJSONMergePatch(existingJSON, expectedJSON []byte) ([]byte, error) {
Expand Down
4 changes: 2 additions & 2 deletions internal/helm/release/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func TestManagerGenerateStrategicMergePatch(t *testing.T) {
o2: newTestDeployment([]v1.Container{
{Name: "test1", LivenessProbe: nil},
}),
patch: `{}`,
patch: ``,
patchType: apitypes.StrategicMergePatchType,
},
{
Expand Down Expand Up @@ -196,7 +196,7 @@ func TestManagerGenerateStrategicMergePatch(t *testing.T) {
},
Spec: appsv1.DeploymentSpec{},
},
patch: `{}`,
patch: ``,
patchType: apitypes.StrategicMergePatchType,
},
}
Expand Down

0 comments on commit 03f4495

Please sign in to comment.