Skip to content

🌱 Add default namespace support to AgentInstallNamespaceFromDeploymentConfigFunc#349

Open
zhujian7 wants to merge 1 commit intoopen-cluster-management-io:mainfrom
zhujian7:add-default-namespace-support
Open

🌱 Add default namespace support to AgentInstallNamespaceFromDeploymentConfigFunc#349
zhujian7 wants to merge 1 commit intoopen-cluster-management-io:mainfrom
zhujian7:add-default-namespace-support

Conversation

@zhujian7
Copy link
Member

@zhujian7 zhujian7 commented Dec 1, 2025

Summary

This enhancement adds optional default namespace support to AgentInstallNamespaceFromDeploymentConfigFunc. When the addon deployment config doesn't specify an AgentInstallNamespace, callers can now provide a fallback default namespace.

Changes

  • Updated AgentInstallNamespaceFromDeploymentConfigFunc signature to accept optional defaultNs ...string parameter
  • Added logic to return the default namespace when config.Spec.AgentInstallNamespace is empty and a default is provided

Test plan

  • Verify function works with no default namespace (existing behavior)
  • Verify function returns default namespace when config's AgentInstallNamespace is empty
  • Verify function still respects config's AgentInstallNamespace when set

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added support for optional default namespace fallback in addon deployment configuration. If the deployment config lacks a namespace specification, the provided default will be used.

✏️ Tip: You can customize this high-level summary in your review settings.

…onfigFunc

This enhancement allows callers to specify a fallback namespace when the addon
deployment config doesn't specify an agent install namespace. The function now
accepts an optional defaultNs parameter that will be returned when
config.Spec.AgentInstallNamespace is empty.

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

Co-Authored-By: Claude <[email protected]>
Signed-off-by: zhujian <[email protected]>
@openshift-ci openshift-ci bot requested review from deads2k and qiujian16 December 1, 2025 07:55
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Dec 1, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: zhujian7

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

The pull request process is described here

Details 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-ci openshift-ci bot added the approved label Dec 1, 2025
@coderabbitai
Copy link

coderabbitai bot commented Dec 1, 2025

Walkthrough

The PR updates the AgentInstallNamespaceFromDeploymentConfigFunc function signature in pkg/utils/addon_config.go to accept an optional variadic parameter for default namespaces. When the addon deployment config lacks an explicit AgentInstallNamespace, the function now falls back to the first provided default value.

Changes

Cohort / File(s) Summary
Function Signature Update
pkg/utils/addon_config.go
Added optional defaultNs ...string variadic parameter to AgentInstallNamespaceFromDeploymentConfigFunc with fallback logic to return the first default namespace when config-based namespace is unavailable

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Verify that the variadic parameter implementation correctly returns the first default namespace when appropriate
  • Check for any existing callers of AgentInstallNamespaceFromDeploymentConfigFunc that may be affected by the signature change
  • Confirm the fallback behavior integrates correctly with the existing namespace resolution logic

Possibly related PRs

Suggested labels

lgtm

Suggested reviewers

  • zhiweiyin318
  • haoqing0110

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The description includes a clear summary of changes and a test plan checklist. However, it lacks the 'Related issue(s)' section specified in the repository template, and the test plan is incomplete with unchecked items.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Title check ✅ Passed The title clearly and specifically describes the main change: adding default namespace support to AgentInstallNamespaceFromDeploymentConfigFunc, which aligns perfectly with the changeset.
✨ 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
Copy link
Member Author

zhujian7 commented Dec 1, 2025

/hold

@zhujian7 zhujian7 changed the title Add default namespace support to AgentInstallNamespaceFromDeploymentConfigFunc 🌱 Add default namespace support to AgentInstallNamespaceFromDeploymentConfigFunc Dec 1, 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: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
pkg/utils/addon_config.go (1)

55-59: Missing default namespace fallback when config is nil.

When config == nil, the function returns an empty string without checking the defaultNs parameter. However, the comment at lines 50-54 states: "we can use the default namespace" when the addon deployment config is not configured. This creates inconsistent behavior:

  • When config is nil → returns empty string (ignores default)
  • When config exists but AgentInstallNamespace is empty → returns default (lines 61-63)

Both cases should likely use the default namespace fallback.

Apply this diff to add the missing fallback:

 	if config == nil {
 		klog.V(4).InfoS("Addon deployment config is nil, return an empty string for agent install namespace",
 			"addonNamespace", addon.Namespace, "addonName", addon.Name)
+		if len(defaultNs) > 0 {
+			return defaultNs[0], nil
+		}
 		return "", nil
 	}
🧹 Nitpick comments (1)
pkg/utils/addon_config.go (1)

61-63: LGTM with documentation update needed.

The logic correctly returns the first default namespace when config.Spec.AgentInstallNamespace is empty and a default is provided.

Consider updating the function documentation (lines 34-36) to describe the new default namespace behavior:

 // AgentInstallNamespaceFromDeploymentConfigFunc returns an agent install namespace helper function which will get the
 // namespace from the addon deployment config. If the addon does not support addon deployment config or there is no
-// matched addon deployment config, it will return an empty string.
+// matched addon deployment config, it will return an empty string. If a default namespace is provided via defaultNs
+// and the config's AgentInstallNamespace is empty, it will return the default namespace.
 func AgentInstallNamespaceFromDeploymentConfigFunc(

Optional API clarity improvement:

The variadic parameter accepts multiple strings but only uses the first. Consider using a more explicit signature:

func AgentInstallNamespaceFromDeploymentConfigFunc(
	adcgetter AddOnDeploymentConfigGetter, defaultNs string,
) func(*addonapiv1alpha1.ManagedClusterAddOn) (string, error)

Or if you want to keep the optional nature without variadic:

func AgentInstallNamespaceFromDeploymentConfigFunc(
	adcgetter AddOnDeploymentConfigGetter, opts ...Option,
) func(*addonapiv1alpha1.ManagedClusterAddOn) (string, error)

where Option is a functional option pattern. However, the current variadic approach is acceptable if simplicity is preferred.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1a0a9be and a5f33ef.

📒 Files selected for processing (1)
  • pkg/utils/addon_config.go (2 hunks)
⏰ 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: unit
  • GitHub Check: e2e-cloudevents
  • GitHub Check: e2e
  • GitHub Check: integration
  • GitHub Check: e2e-hosted
  • GitHub Check: build
  • GitHub Check: verify

Comment on lines 37 to 39
func AgentInstallNamespaceFromDeploymentConfigFunc(
adcgetter AddOnDeploymentConfigGetter,
adcgetter AddOnDeploymentConfigGetter, defaultNs ...string,
) func(*addonapiv1alpha1.ManagedClusterAddOn) (string, error) {
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

rg -nP -C3 '\bAgentInstallNamespaceFromDeploymentConfigFunc\s*\(' --type=go

Repository: open-cluster-management-io/addon-framework

Length of output: 228


Address inconsistent nil config handling and update documentation.

Lines 55-59 return an empty string when config == nil without checking defaultNs, while lines 61-63 correctly apply the default namespace when config != nil but AgentInstallNamespace is empty. This inconsistency violates the function's intent. Additionally, the function documentation (lines 34-36) doesn't mention the new default namespace behavior.

Fix the nil config case to also check defaultNs (e.g., return first element if available), and update the function comment to document the fallback behavior.

🤖 Prompt for AI Agents
In pkg/utils/addon_config.go around lines 34 to 63, the function comment and
nil-config branch are inconsistent: update the function comment to state that if
the AddOnDeploymentConfig is nil or its AgentInstallNamespace is empty, the
function will fall back to the first element of the optional defaultNs (if
provided); then change the nil-config handling so it returns defaultNs[0] (when
defaultNs is non-empty) instead of an empty string, preserving the existing
behavior for when no defaultNs is provided and keeping the existing error return
path unchanged.

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.

1 participant