refactor: Optimize FleetMode checks and improve code clarity#239
refactor: Optimize FleetMode checks and improve code clarity#239TheUndeadKing wants to merge 1 commit intoopenshift:masterfrom
Conversation
WalkthroughCluster version fetch and cluster ID usage were made conditional on OCM Agent FleetMode: when FleetMode is true, cluster version is not fetched and ConfigMap is built with an empty cluster ID. Deployment arg logic was changed to if/else for mutually exclusive flags. NetworkPolicy namespace selection was extracted to a helper; tests updated. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 8 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (8 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 |
|
/retest |
c1a2c45 to
b5ed3b7
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #239 +/- ##
==========================================
+ Coverage 66.25% 66.49% +0.23%
==========================================
Files 23 23
Lines 1544 1543 -1
==========================================
+ Hits 1023 1026 +3
+ Misses 445 442 -3
+ Partials 76 75 -1
🚀 New features to boost your workflow:
|
e05ba33 to
d0aa2f8
Compare
d0aa2f8 to
1274d91
Compare
|
@TheUndeadKing: Failed to re-open PR: state cannot be changed. There are no new commits on the TheUndeadKing:code-review branch. DetailsIn response to this:
Instructions 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. |
|
@TheUndeadKing: Failed to re-open PR: state cannot be changed. There are no new commits on the TheUndeadKing:code-review branch. DetailsIn response to this:
Instructions 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. |
|
/reopen |
|
@TheUndeadKing: Reopened this PR. DetailsIn response to this:
Instructions 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. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: TheUndeadKing 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 |
1 similar comment
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: TheUndeadKing 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 |
|
/retest |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@pkg/ocmagenthandler/ocmagenthandler_configmap_test.go`:
- Around line 279-283: The test uses
mockClient.EXPECT().Get(...).Return(...).Times(2) and
mockClient.EXPECT().Create(...).Return(nil).Times(2) with gomock.Any(), which
only verifies call counts and can miss wrong resources; update the expectations
to assert the actual ConfigMap objects created by ensureAllConfigMaps: replace
gomock.Any() for the object arg with a matcher like
gomock.AssignableToTypeOf(&corev1.ConfigMap{}) and/or capture the created
argument using gomock.Do or a custom gomock.Matcher, then assert the ConfigMap
metadata (Name, Namespace) and Data keys/values for the OCM Agent ConfigMap and
the Trusted CA ConfigMap; keep ctx param as gomock.Any() but verify the second
argument (the object) against expected names and contents when setting up
mockClient.EXPECT().Create and similarly tighten Get expectations to match the
correct names.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 381606b4-3cd1-4967-bf77-663b992b3319
📒 Files selected for processing (6)
build/Dockerfilebuild/Dockerfile.olm-registrypkg/ocmagenthandler/ocmagenthandler_configmap.gopkg/ocmagenthandler/ocmagenthandler_configmap_test.gopkg/ocmagenthandler/ocmagenthandler_deployment.gopkg/ocmagenthandler/ocmagenthandler_networkpolicy.go
✅ Files skipped from review due to trivial changes (3)
- build/Dockerfile.olm-registry
- build/Dockerfile
- pkg/ocmagenthandler/ocmagenthandler_deployment.go
🚧 Files skipped from review as they are similar to previous changes (1)
- pkg/ocmagenthandler/ocmagenthandler_configmap.go
| // FleetMode creates: OCM Agent ConfigMap + Trusted CA ConfigMap (not CAMO) | ||
| mockClient.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any()).Return(k8serrs.NewNotFound(schema.GroupResource{}, "")).Times(2) | ||
| mockClient.EXPECT().Create(gomock.Any(), gomock.Any()).Return(nil).Times(2) | ||
| err := testOcmAgentHandler.ensureAllConfigMaps(testOcmAgent) | ||
| Expect(err).ToNot(HaveOccurred()) |
There was a problem hiding this comment.
Fleet-mode test is under-asserted for created resources.
Line 280-Line 281 only check call counts with gomock.Any(). This can miss regressions where the wrong ConfigMaps are created (or expected data is wrong) while counts still equal 2.
Proposed assertion-tightening diff
It("ensureAllConfigMaps handles fleet mode and errors", func() {
// Test fleet mode (no cluster version fetch, no CAMO, no cluster ID)
testOcmAgent.Spec.FleetMode = true
// FleetMode creates: OCM Agent ConfigMap + Trusted CA ConfigMap (not CAMO)
- mockClient.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any()).Return(k8serrs.NewNotFound(schema.GroupResource{}, "")).Times(2)
- mockClient.EXPECT().Create(gomock.Any(), gomock.Any()).Return(nil).Times(2)
+ notFound := k8serrs.NewNotFound(schema.GroupResource{}, "")
+ created := map[string]*corev1.ConfigMap{}
+ mockClient.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any()).Return(notFound).Times(2)
+ mockClient.EXPECT().Create(gomock.Any(), gomock.Any()).DoAndReturn(
+ func(_ context.Context, d *corev1.ConfigMap, _ ...client.CreateOptions) error {
+ created[d.Name] = d
+ return nil
+ }).Times(2)
err := testOcmAgentHandler.ensureAllConfigMaps(testOcmAgent)
Expect(err).ToNot(HaveOccurred())
+ Expect(created).To(HaveKey(testOcmAgent.Name + testconst.TestConfigMapSuffix))
+ Expect(created).To(HaveKey("trusted-ca-bundle"))
+ Expect(created).ToNot(HaveKey(oahconst.CAMOConfigMapNamespacedName.Name))
+ Expect(created[testOcmAgent.Name+testconst.TestConfigMapSuffix].Data).ToNot(HaveKey(oahconst.OCMAgentConfigClusterID))🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@pkg/ocmagenthandler/ocmagenthandler_configmap_test.go` around lines 279 -
283, The test uses mockClient.EXPECT().Get(...).Return(...).Times(2) and
mockClient.EXPECT().Create(...).Return(nil).Times(2) with gomock.Any(), which
only verifies call counts and can miss wrong resources; update the expectations
to assert the actual ConfigMap objects created by ensureAllConfigMaps: replace
gomock.Any() for the object arg with a matcher like
gomock.AssignableToTypeOf(&corev1.ConfigMap{}) and/or capture the created
argument using gomock.Do or a custom gomock.Matcher, then assert the ConfigMap
metadata (Name, Namespace) and Data keys/values for the OCM Agent ConfigMap and
the Trusted CA ConfigMap; keep ctx param as gomock.Any() but verify the second
argument (the object) against expected names and contents when setting up
mockClient.EXPECT().Create and similarly tighten Get expectations to match the
correct names.
|
@TheUndeadKing: all tests passed! Full PR test history. Your PR dashboard. 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. I understand the commands that are listed here. |
What type of PR is this?
(bug/feature/cleanup/documentation/test/refactor)
What this PR does / why we need it?
Minor optimizations and code clarity improvements in OCM Agent handler.
ocmagenthandler_configmap.go)Which Jira/Github issue(s) this PR fixes?
Fixes # N/A
Special notes for your reviewer:
Pre-checks (if applicable):
make generatecommand locally to validate code changesSummary by CodeRabbit