Skip to content

Conversation

@zhujian7
Copy link
Member

@zhujian7 zhujian7 commented Oct 17, 2025

Description

This PR sets an explicit default namespace for addon registration to ensure consistent behavior when InstallNamespace is deprecated and agentInstallNamespace is empty.

Changes

  • Set default Status.Namespace to "open-cluster-management-agent-addon"
  • Clarify namespace priority order with explicit default value
  • Add test case for default namespace behavior
  • Improve test error messages to show actual vs expected values

Namespace Priority Order

  1. Default: "open-cluster-management-agent-addon"
  2. Override with registrationOption.Namespace if set
  3. Override with deprecated Spec.InstallNamespace if set
  4. Override with AgentInstallNamespace callback result if set and non-empty

Testing

Added new test case "default namespace when no namespace is specified" to verify the default namespace is correctly set.

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Improved namespace resolution for addon registration with a consistent priority order: defaults to open-cluster-management-agent-addon, then applies overrides from registration options, installation specifications, and agent namespace settings with proper fallback handling.
  • Tests

    • Added test coverage to verify default namespace assignment when no explicit namespace is specified.

- Set default Status.Namespace to "open-cluster-management-agent-addon"
- Clarify namespace priority order with explicit default value
- Add test case for default namespace behavior
- Improve test error messages to show actual vs expected values

This ensures a consistent default namespace even when InstallNamespace
is deprecated and agentInstallNamespace is empty.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Signed-off-by: zhujian <[email protected]>
@coderabbitai
Copy link

coderabbitai bot commented Oct 17, 2025

Walkthrough

The change reworks namespace resolution logic in addon registration synchronization, establishing a priority-based namespace determination flow with defaults, explicit overrides, and conditional AgentInstallNamespace handling.

Changes

Cohort / File(s) Summary
Namespace resolution refactoring
pkg/addonmanager/controllers/registration/controller.go
Consolidates ManagedClusterAddon namespace determination logic with priority-based overrides: defaults to open-cluster-management-agent-addon, then applies registrationOption.Namespace, managedClusterAddonCopy.Spec.InstallNamespace, and AgentInstallNamespace (if non-empty). Removes separate agentInstallNamespace variable.
Test coverage updates
pkg/addonmanager/controllers/registration/controller_test.go
Adds test case for default namespace when no InstallNamespace specified; updates two existing assertion messages to include Namespace values.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Reasoning: The controller change introduces a priority-based namespace resolution flow requiring careful verification of the override sequence and edge case handling. The test additions validate default behavior but are straightforward. Mixed complexity with single affected file demands deliberate review of logic correctness rather than high file heterogeneity.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed The PR description provides comprehensive information including a clear purpose statement, detailed changes, explicit namespace priority ordering, and testing information. While the template specifies a "Summary" section heading and a "Related issue(s)" section, the description fulfills these functions with "Description" and detailed context instead. The only clearly missing element is a reference to any related issue (no "Fixes #" link), but this may not be applicable to this particular PR. The description is substantially complete with all critical information needed to understand the change and its rationale.
Title Check ✅ Passed The pull request title "Set explicit default namespace for addon registration" directly summarizes the primary change in the changeset. The code modifications rework namespace resolution logic to establish an explicit default namespace ("open-cluster-management-agent-addon") for addon registration, and the title accurately reflects this core objective. The title is concise, specific, and clearly conveys the main purpose without vague terminology. A teammate reviewing commit history would understand this PR's intent from the title alone.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@zhujian7 zhujian7 changed the title Set explicit default namespace for addon registration 🌱 Set explicit default namespace for addon registration Oct 17, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (4)
pkg/addonmanager/controllers/registration/controller.go (3)

188-191: Use a named constant and fix typos in the comment.

Good default. Recommend a package-level const to avoid string drift, and correct “deprceated”/grammar.

Apply within this block:

-	// explicitly set the default namespace value, since the mca.spec.installNamespace is deprceated and
-	//  the addonDeploymentConfig.spec.agentInstallNamespace could be empty
-	managedClusterAddonCopy.Status.Namespace = "open-cluster-management-agent-addon"
+	// Set explicit default namespace. Spec.installNamespace is deprecated and
+	// addonDeploymentConfig.spec.agentInstallNamespace may be empty.
+	managedClusterAddonCopy.Status.Namespace = defaultAddonAgentNamespace

Add near the top of this file (after imports):

+const defaultAddonAgentNamespace = "open-cluster-management-agent-addon"

192-199: Clarify comment to reflect override semantics.

Comment implies defaulting to registrationOption.Namespace. It’s actually an override when set. Update for accuracy.

-	// Set the default namespace to registrationOption.Namespace
+	// Override with registrationOption.Namespace if provided

201-209: Tighten comment; consider status condition on error.

  • Comment mentions InstallNamespace here, but this block only handles AgentInstallNamespace; adjust wording.
  • Optional: when AgentInstallNamespace returns an error, mirror the earlier PermissionConfig failure path by setting RegistrationApplied=False with a specific reason before returning, improving observability.
-		// Override if agentInstallNamespace or InstallNamespace is specified
+		// Override with AgentInstallNamespace if it returns a non-empty value

Optionally set a condition on error (pattern already used above):

// On err, set a ManagedClusterAddOnRegistrationApplied=False condition
// with a dedicated Reason (e.g., RegistrationAppliedResolveNamespaceFailed)
// and PatchStatus before returning.
pkg/addonmanager/controllers/registration/controller_test.go (1)

220-252: LGTM: covers defaulting path; add one more edge test.

Test correctly verifies default namespace when nothing is specified. Suggest adding a case where AgentInstallNamespace returns an empty string to confirm it does not clobber the default.

Example case to add to cases[]:

{
  name: "agentInstallNamespace returns empty -> keep default",
  cluster: []runtime.Object{addontesting.NewManagedCluster("cluster1")},
  addon: []runtime.Object{
    func() *addonapiv1alpha1.ManagedClusterAddOn {
      addon := addontesting.NewAddon("test", "cluster1", metav1.OwnerReference{Kind: "ClusterManagementAddOn", Name: "test"})
      return addon
    }(),
  },
  validateAddonActions: func(t *testing.T, actions []clienttesting.Action) {
    addontesting.AssertActions(t, actions, "patch")
    actual := actions[0].(clienttesting.PatchActionImpl).Patch
    addOn := &addonapiv1alpha1.ManagedClusterAddOn{}
    if err := json.Unmarshal(actual, addOn); err != nil { t.Fatal(err) }
    if addOn.Status.Namespace != "open-cluster-management-agent-addon" {
      t.Errorf("Namespace %s in status is not correct, expected open-cluster-management-agent-addon", addOn.Status.Namespace)
    }
  },
  testaddon: &testAgent{
    name: "test",
    registrations: []addonapiv1alpha1.RegistrationConfig{{SignerName: "test"}},
    agentInstallNamespace: func(addon *addonapiv1alpha1.ManagedClusterAddOn) (string, error) { return "", nil },
  },
},
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cbcc715 and c7af199.

📒 Files selected for processing (2)
  • pkg/addonmanager/controllers/registration/controller.go (1 hunks)
  • pkg/addonmanager/controllers/registration/controller_test.go (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
pkg/addonmanager/controllers/registration/controller_test.go (2)
pkg/addonmanager/addontesting/helpers.go (3)
  • NewManagedCluster (208-214)
  • NewAddon (81-89)
  • AssertActions (292-301)
vendor/open-cluster-management.io/api/addon/v1alpha1/types_managedclusteraddon.go (2)
  • ManagedClusterAddOn (19-32)
  • RegistrationConfig (56-74)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: e2e-hosted
  • GitHub Check: e2e-cloudevents
  • GitHub Check: integration
  • GitHub Check: e2e
  • GitHub Check: unit
  • GitHub Check: build
  • GitHub Check: verify
🔇 Additional comments (2)
pkg/addonmanager/controllers/registration/controller_test.go (2)

172-177: LGTM: clearer assertion message.

Including actual Namespace improves failure diagnostics.


206-211: LGTM: clearer assertion message.

Better error context with the actual value.

@zhujian7
Copy link
Member Author

/cc @qiujian16 @haoqing0110

@openshift-ci openshift-ci bot requested a review from haoqing0110 October 17, 2025 03:17
Copy link
Member

@qiujian16 qiujian16 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/approve
/lgtm

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Oct 20, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: qiujian16, zhujian7

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-bot openshift-merge-bot bot merged commit c18f49f into open-cluster-management-io:main Oct 20, 2025
15 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants