Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(helm-operator): do not send empty patch requests to kube apiserver #4957

Merged
merged 3 commits into from
Jun 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog/fragments/empty-patch-requests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
entries:
- description: >
For helm-based operators, empty patch requests generated from the 3-way merge are filtered to avoid unnecessary requests to the kube apiserver.
kind: bugfix
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