✨ Add NewWorkApplierWithRuntimeClient constructor - #227
Conversation
WalkthroughAdds NewWorkApplierWithRuntimeClient to back WorkApplier with a controller-runtime client; implements get/create/patch/delete via runtime client calls and includes tests covering create vs patch, annotation reconciliation, cache-hit/no-write behavior, generation-based drift correction, and delete semantics. ChangesRuntime Client Constructor and Tests
🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
a69abfb to
63571e2
Compare
The README documents a NewWorkApplierWithRuntimeClient implementation using sigs.k8s.io/controller-runtime/pkg/client, but users cannot implement it externally because all WorkApplier fields are unexported. Promote it to an exported constructor. Closes open-cluster-management-io#226 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Mike Kolesnik <mkolesni@redhat.com>
63571e2 to
aa513d7
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
pkg/apis/work/v1/applier/workapplier.go (1)
75-82: ⚡ Quick winPost-patch
Getis likely redundant and weakens cache update semantics.
controller-runtime'sPatchdecodes the server response back into the passed object, soworkshould already hold the updatedManifestWorkafter thePatchcall succeeds. The extraGetadds an API round-trip on the apply hot path, and—more importantly—introduces a failure mode: if thisGeterrors transiently after thePatchalready succeeded,patchWorkreturns an error, soApplyskipsw.cache.updateCache(...)(lines 151-154) even though the write landed. That defeats the cache and forces a redundant re-patch on the next reconcile.♻️ Drop the redundant Get
patchWork: func(ctx context.Context, namespace, name string, pt types.PatchType, data []byte) (*workapiv1.ManifestWork, error) { work := &workapiv1.ManifestWork{ ObjectMeta: metav1.ObjectMeta{ Name: name, Namespace: namespace, }, } if err := workClient.Patch(ctx, work, client.RawPatch(pt, data)); err != nil { return nil, err } - if err := workClient.Get(ctx, types.NamespacedName{Namespace: namespace, Name: name}, work); err != nil { - return nil, err - } return work, nil },Does sigs.k8s.io/controller-runtime client.Patch (v0.23.1) decode the server response back into the passed object, so the object holds the updated state after Patch returns?🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@pkg/apis/work/v1/applier/workapplier.go` around lines 75 - 82, The post-patch fetch in patchWork is redundant because workClient.Patch already updates the passed ManifestWork object with the server response. Remove the follow-up workClient.Get call in patchWork and return the patched work directly after a successful Patch. Keep the existing error handling for Patch itself, and ensure Apply still reaches w.cache.updateCache(...) using the already-updated work object.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@pkg/apis/work/v1/applier/workapplier.go`:
- Around line 75-82: The post-patch fetch in patchWork is redundant because
workClient.Patch already updates the passed ManifestWork object with the server
response. Remove the follow-up workClient.Get call in patchWork and return the
patched work directly after a successful Patch. Keep the existing error handling
for Patch itself, and ensure Apply still reaches w.cache.updateCache(...) using
the already-updated work object.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 3f0d3df9-3bea-4062-b116-d39c6c7930e6
📒 Files selected for processing (3)
pkg/apis/work/v1/README.mdpkg/apis/work/v1/applier/workapplier.gopkg/apis/work/v1/applier/workapplier_test.go
✅ Files skipped from review due to trivial changes (1)
- pkg/apis/work/v1/README.md
🚧 Files skipped from review as they are similar to previous changes (1)
- pkg/apis/work/v1/applier/workapplier_test.go
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: mikeshng, mkolesnik The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
The README documents a
NewWorkApplierWithRuntimeClientimplementation usingsigs.k8s.io/controller-runtime/pkg/client, but users cannot implement it externally because allWorkApplierfields are unexported.Promote it to an exported constructor.
Closes #226
Summary by CodeRabbit
New Features
Tests
Documentation