Add support for Server-Side Apply finalizer management#3275
Add support for Server-Side Apply finalizer management#3275knative-prow[bot] merged 1 commit intoknative:mainfrom
Conversation
|
|
|
Welcome @enarha! It looks like this is your first PR to knative/pkg 🎉 |
|
Hi @enarha. Thanks for your PR. I'm waiting for a github.com member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
/assign @dprotaso |
|
/ok-to-test |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3275 +/- ##
==========================================
- Coverage 74.93% 74.58% -0.36%
==========================================
Files 188 188
Lines 10263 8184 -2079
==========================================
- Hits 7691 6104 -1587
+ Misses 2332 1840 -492
Partials 240 240 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
5dc1f6b to
363a01d
Compare
|
/hold pkg release-1.20 branch was cut today. Let's revisit this after the 1.20 release next week |
|
Can this PR get some attention please. I'll be happy to elaborate if you have any questions. Thank you. |
nader-ziada
left a comment
There was a problem hiding this comment.
added some comments in the updateFinalizersFilteredServerSideApply func which is repeated in a bunch of places as far as I can see
| updated, err := patcher.Patch(ctx, resource.Name, types.ApplyPatchType, patch, patchOpts) | ||
| if err != nil { | ||
| r.Recorder.Eventf(resource, corev1.EventTypeWarning, "FinalizerUpdateFailed", | ||
| "Failed to remove finalizer for %q via server-side apply: %v", resource.Name, err) |
There was a problem hiding this comment.
Should use %w for error wrapping
There was a problem hiding this comment.
Here we do not return the error, just print it, so the simpler %v makes more sense and it is also consistent with the original code (merge patch). I updated the case where we return the error to use %w which allows unwrapping. If you still think I should update this one, I'll do.
| // This effectively removes our finalizer while preserving others. | ||
| gvks, _, err := scheme.Scheme.ObjectKinds(resource) | ||
| if err != nil || len(gvks) == 0 { | ||
| return resource, fmt.Errorf("failed to determine GVK for resource: %v", err) |
There was a problem hiding this comment.
Should use %w for error wrapping
| return resource, nil | ||
| } | ||
| // Apply configuration with only our finalizer to add it. | ||
| gvks, _, err := scheme.Scheme.ObjectKinds(resource) |
There was a problem hiding this comment.
This GVK lookup logic is duplicated below in the else condition
There was a problem hiding this comment.
Indeed it has. It could be called before the if clause, but then it should be called on each reconciliation cycle. Instead we call it just twice in the lifetime of the object, once to set it and once to remove it, while the reconciliation loop is called 10-20 or even more times, at least on the controllers I work on. That's why I think less calls is worth the duplication, but I'll be happy to change it you think otherwise.
There was a problem hiding this comment.
Nevermind, I moved it after the else block.
| // Apply configuration with only our finalizer to add it. | ||
| gvks, _, err := scheme.Scheme.ObjectKinds(resource) | ||
| if err != nil || len(gvks) == 0 { | ||
| return resource, fmt.Errorf("failed to determine GVK for resource: %v", err) |
There was a problem hiding this comment.
Should use %w for error wrapping
There was a problem hiding this comment.
Agree, that makes sense as we return error.
| }, | ||
| } | ||
|
|
||
| patch, err := json.Marshal(applyConfig) |
There was a problem hiding this comment.
This patch operation logic is duplicated below as well
There was a problem hiding this comment.
Indeed. It could be moved after the else clause with the only penalty of having less accurate log message "failed to add/remove finalizer" and "Added/removed finalizer" compared to "failed to update finalizer" and "updated finalizer". Personally I prefer the former, but I'll update so it's also inline with the merge patch method.
There was a problem hiding this comment.
Updated. Much cleaner now.
|
|
||
| patchOpts := metav1.PatchOptions{ | ||
| FieldManager: r.finalizerFieldManager, | ||
| Force: &r.forceApplyFinalizers, |
There was a problem hiding this comment.
By default it's not set as the value is set to false. We expose the ForceApplyFinalizers controller option though, so the controller implementation can set that to true. Force apply is often discussed in the context of server-side apply, so I decided to provide that flexibility to the controller implementation.
|
/hold cancel |
|
Testing this downstream with - knative/serving#16217 |
|
Downstream test ran successfully. I'm good to merge once Nader's feedback is addressed. |
This improves performance and load on the k8s API by decreasing the number of re-tries, especially on objects managed by multiple controllers. The feature is opt-in and the current use of merge patch is still the default behavior. We introduce three controller options: - UseServerSideApplyForFinalizers used to enable that functionality. - FinalizerFieldManager to specify finalizer field manager, required when SSA is enabled. - ForceApplyFinalizers to set the force option on the apply patch (default disabled).
363a01d to
0e36a17
Compare
|
/lgtm |
|
/approve |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: dprotaso, enarha The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Leverages functionality added here: knative/pkg#3275 Options documented here: https://github.com/knative/pkg/blob/main/controller/options.go#L31-L40
Leverages functionality added here: knative/pkg#3275 Options documented here: https://github.com/knative/pkg/blob/main/controller/options.go#L31-L40
This improves performance and load on the k8s API by decreasing the number of re-tries, especially on objects managed by multiple controllers. The feature is opt-in and the current use of merge patch is still the default behavior.
We introduce three controller options:
Changes
This improves performance and load on the k8s API by decreasing the number of re-tries, especially on objects managed by multiple controllers. The feature is opt-in and the current use of merge patch is still the default behavior.
We introduce three controller options:
/kind api-change
Fixes #2128
Release Note
Docs