Skip to content

Conversation

@zhujian7
Copy link
Member

@zhujian7 zhujian7 commented Oct 16, 2025

Description

This PR adds support for template-type addons to use the namespace defined in their template manifest by setting agentInstallNamespace: "" in the AddonDeploymentConfig.

Changes

1. API Upgrade

2. New Function

Added AgentInstallNamespaceFromDeploymentConfigRawFunc that:

  • Returns the raw AgentInstallNamespace value including empty strings
  • Enables template-type addons to signal "use template namespace" with agentInstallNamespace: ""
  • Will be used by template-type addon controllers in the OCM repo

3. Backward Compatibility

Updated existing AgentInstallNamespaceFromDeploymentConfigFunc to:

  • Explicitly return "open-cluster-management-agent-addon" when AgentInstallNamespace is empty
  • Ensures existing addons continue to work without any changes
  • Added documentation clarifying the behavior difference

4. Tests

  • Added test for empty AgentInstallNamespace returning default namespace
  • Added comprehensive tests for the new raw function
  • All existing tests continue to pass

Related Issues

open-cluster-management-io/ocm#1209

Testing

All unit tests pass:
```
go test ./pkg/utils/... -v -run TestAgentInstallNamespace
```

Backward Compatibility

✅ This change is fully backward compatible. Existing addons using AgentInstallNamespaceFromDeploymentConfigFunc will continue to receive the default namespace when AgentInstallNamespace is empty or unset.

Template-type addons that want the new behavior should migrate to use AgentInstallNamespaceFromDeploymentConfigRawFunc.

Summary by CodeRabbit

  • New Features

    • Enhanced addon deployment namespace configuration handling with improved backward compatibility. When namespace configuration is empty, the system now defaults to standard namespace instead of failing.
  • Chores

    • Updated dependencies for improved stability.
  • Tests

    • Added comprehensive test coverage for addon namespace configuration scenarios.

Updates open-cluster-management.io/api to include changes from
open-cluster-management-io/api#400 which allows
empty string for AgentInstallNamespace to support template-type addons.

Signed-off-by: zhujian <[email protected]>
…e addons

This commit adds a new function AgentInstallNamespaceFromDeploymentConfigRawFunc
that returns the raw AgentInstallNamespace value from AddonDeploymentConfig,
including empty string. This enables template-type addons to signal "use template
namespace" by setting agentInstallNamespace: "".

For backward compatibility, the existing AgentInstallNamespaceFromDeploymentConfigFunc
now explicitly returns "open-cluster-management-agent-addon" when the config exists
but AgentInstallNamespace is empty. This ensures existing addons continue to work
as before.

Changes:
- Add AgentInstallNamespaceFromDeploymentConfigRawFunc for raw value access
- Update AgentInstallNamespaceFromDeploymentConfigFunc to return default namespace
  when AgentInstallNamespace is empty (backward compatible)
- Add comprehensive tests for both functions
- Update documentation to clarify the behavior differences

Fixes: open-cluster-management-io/ocm#1209
Signed-off-by: zhujian <[email protected]>
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Oct 16, 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

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

@coderabbitai
Copy link

coderabbitai bot commented Oct 16, 2025

Walkthrough

The PR updates the addon-framework dependency version and introduces a new AgentInstallNamespaceFromDeploymentConfigRawFunc helper to retrieve raw agent install namespace values from addon deployment configs. It extends the existing function to provide default namespace behavior when deployment config exists but namespace is empty, enabling callers to choose between raw or default-applied values.

Changes

Cohort / File(s) Summary
Dependency Update
go.mod
Updated open-cluster-management.io/api dependency version from v1.0.1-0.20251009064814-48b723491429 to v1.0.1-0.20251016015403-f042545132a3
Namespace Resolution Helpers
pkg/utils/addon_config.go
Introduced AgentInstallNamespaceFromDeploymentConfigRawFunc to return raw, possibly empty agent install namespace; extended AgentInstallNamespaceFromDeploymentConfigFunc with backward-compatible default namespace "open-cluster-management-agent-addon" when config exists but namespace is empty
Test Coverage
pkg/utils/addon_config_test.go
Added test case for empty AgentInstallNamespace expecting default namespace; introduced TestAgentInstallNamespaceFromDeploymentConfigRawFunc with table-driven tests covering nil addon, missing config, empty namespace, and populated namespace scenarios

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

The changes are well-focused with straightforward logic. A single new function variant is introduced alongside the existing function modification, with comprehensive test coverage. The nil checks and conditional returns are clear and maintainable. No complex control flow or architectural changes.

Possibly related issues

  • #1209: The new AgentInstallNamespaceFromDeploymentConfigRawFunc and the extended behavior of AgentInstallNamespaceFromDeploymentConfigFunc directly address the namespace resolution issue where addonDeploymentConfig silently overrides template namespaces when agentInstallNamespace is not explicitly set; the raw variant enables callers to implement custom override logic.

Suggested labels

lgtm

Suggested reviewers

  • zhiweiyin318

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues Check ✅ Passed The code changes directly address all primary objectives from linked issue #1209. The API upgrade enables support for empty AgentInstallNamespace values, the new AgentInstallNamespaceFromDeploymentConfigRawFunc function provides template-type addons with raw namespace values (including empty strings) to signal "use template namespace," and the updated AgentInstallNamespaceFromDeploymentConfigFunc maintains backward compatibility by defaulting to "open-cluster-management-agent-addon" when the field is empty. The comprehensive test additions validate both the new raw function and the updated backward-compatible function, ensuring the solution fully implements the fix for the reported issue.
Out of Scope Changes Check ✅ Passed All changes in the pull request are directly aligned with the objectives outlined in issue #1209. The go.mod dependency update is necessary to support empty AgentInstallNamespace in the API, the addon_config.go modifications implement the solution (new raw function and backward-compatible update), and the test file additions validate the implementation. No extraneous changes or unrelated modifications have been introduced outside the scope of enabling empty AgentInstallNamespace support and maintaining backward compatibility.
Title Check ✅ Passed The pull request title "Support empty AgentInstallNamespace for template-type addons" is fully related to the main objective of the changeset. The PR introduces a new function AgentInstallNamespaceFromDeploymentConfigRawFunc and updates existing behavior to explicitly support empty agentInstallNamespace values for template-type addons, which allows them to use their template-defined namespaces. The title accurately summarizes this primary change and would give a teammate scanning the history a clear understanding of the PR's purpose. The title does include an emoji (🐛), which slightly deviates from the guidance to avoid unnecessary noise, but this is a minor stylistic consideration that does not undermine the clarity and specificity of the title.
Description Check ✅ Passed The pull request description is comprehensive and well-structured, providing clear explanations of the changes, their purpose, and impact. It includes detailed information about the API upgrade, new functions, backward compatibility measures, testing approach, and a link to the related GitHub issue. However, it deviates slightly from the template format by using "Description" as the main section heading rather than "Summary," referencing the issue via a full GitHub URL instead of the "Fixes #" format, and including additional sections like "Testing" and "Backward Compatibility" that aren't specified in the template. These are minor formatting variations that do not detract from the overall quality and completeness of the description. The description provides sufficient context for reviewers to understand the PR's objectives and scope.
✨ 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.

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 (1)
pkg/utils/addon_config.go (1)

75-104: Consider extracting common logic to reduce duplication.

The new function duplicates most of the logic from AgentInstallNamespaceFromDeploymentConfigFunc (lines 84-98 mirror lines 44-62). Consider extracting the common retrieval logic into a private helper function and have both public functions call it with a flag indicating whether to apply the default.

Example refactor:

func getAgentInstallNamespaceFromDeploymentConfig(
	addon *addonapiv1alpha1.ManagedClusterAddOn,
	adcgetter AddOnDeploymentConfigGetter,
	applyDefault bool,
) (string, error) {
	if addon == nil {
		return "", fmt.Errorf("failed to get addon install namespace, addon is nil")
	}

	config, err := GetDesiredAddOnDeploymentConfig(addon, adcgetter)
	if err != nil {
		return "", fmt.Errorf("failed to get deployment config for addon %s: %v", addon.Name, err)
	}

	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)
		return "", nil
	}

	namespace := config.Spec.AgentInstallNamespace
	if applyDefault && len(namespace) == 0 {
		return "open-cluster-management-agent-addon", nil
	}
	return namespace, nil
}

func AgentInstallNamespaceFromDeploymentConfigFunc(
	adcgetter AddOnDeploymentConfigGetter,
) func(*addonapiv1alpha1.ManagedClusterAddOn) (string, error) {
	return func(addon *addonapiv1alpha1.ManagedClusterAddOn) (string, error) {
		return getAgentInstallNamespaceFromDeploymentConfig(addon, adcgetter, true)
	}
}

func AgentInstallNamespaceFromDeploymentConfigRawFunc(
	adcgetter AddOnDeploymentConfigGetter,
) func(*addonapiv1alpha1.ManagedClusterAddOn) (string, error) {
	return func(addon *addonapiv1alpha1.ManagedClusterAddOn) (string, error) {
		return getAgentInstallNamespaceFromDeploymentConfig(addon, adcgetter, false)
	}
}

This would improve maintainability by consolidating the retrieval logic in one place.

📜 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 08e718d.

⛔ Files ignored due to path filters (7)
  • go.sum is excluded by !**/*.sum
  • vendor/modules.txt is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/addon/v1alpha1/0000_02_addon.open-cluster-management.io_addondeploymentconfigs.crd.yaml is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/addon/v1alpha1/types_addondeploymentconfig.go is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/work/v1/types.go is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/work/v1alpha1/0000_00_work.open-cluster-management.io_manifestworkreplicasets.crd.yaml is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/work/v1alpha1/types_manifestworkreplicaset.go is excluded by !vendor/**
📒 Files selected for processing (3)
  • go.mod (1 hunks)
  • pkg/utils/addon_config.go (2 hunks)
  • pkg/utils/addon_config_test.go (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
pkg/utils/addon_config.go (2)
vendor/open-cluster-management.io/api/addon/v1alpha1/types_managedclusteraddon.go (1)
  • ManagedClusterAddOn (19-32)
vendor/k8s.io/klog/v2/klog.go (2)
  • V (1353-1355)
  • InfoS (1530-1532)
pkg/utils/addon_config_test.go (4)
vendor/open-cluster-management.io/api/addon/v1alpha1/types_addondeploymentconfig.go (2)
  • AddOnDeploymentConfig (14-21)
  • AddOnDeploymentConfigSpec (23-72)
vendor/open-cluster-management.io/api/addon/v1alpha1/types_managedclusteraddon.go (3)
  • ManagedClusterAddOn (19-32)
  • ManagedClusterAddOnStatus (100-161)
  • ConfigReference (184-205)
vendor/open-cluster-management.io/api/addon/v1alpha1/types_clustermanagementaddon.go (3)
  • ConfigGroupResource (104-115)
  • ConfigReferent (118-129)
  • ConfigSpecHash (132-138)
pkg/utils/addon_config.go (2)
  • AddOnDeploymentConfigGetter (16-18)
  • AgentInstallNamespaceFromDeploymentConfigRawFunc (81-104)
⏰ 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: verify
  • GitHub Check: e2e-hosted
  • GitHub Check: build
  • GitHub Check: unit
  • GitHub Check: e2e
  • GitHub Check: e2e-cloudevents
  • GitHub Check: integration
🔇 Additional comments (5)
go.mod (1)

25-25: LGTM! Dependency update aligns with PR objectives.

The update to open-cluster-management.io/api enables support for empty AgentInstallNamespace field, which is required for the template-type addon functionality introduced in this PR.

pkg/utils/addon_config.go (2)

37-39: Clear documentation of backward compatibility.

The added documentation effectively explains the behavioral difference between the two functions, making it clear when developers should use each variant.


64-69: LGTM! Backward compatibility preserved.

The logic correctly returns the default namespace when AgentInstallNamespace is empty, ensuring existing addons continue to work without modification.

pkg/utils/addon_config_test.go (2)

131-165: LGTM! Test case validates backward compatibility.

The test case correctly verifies that when AgentInstallNamespace is empty, the function returns the default namespace "open-cluster-management-agent-addon". The spec hash 44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a appears to be the SHA256 hash of an empty AddOnDeploymentConfigSpec with only the AgentInstallNamespace field set to empty string.


212-331: LGTM! Comprehensive test coverage for the raw function.

The test function thoroughly validates the new raw variant's behavior:

  • Nil addon handling
  • Missing config reference handling
  • Empty AgentInstallNamespace returning empty string (key difference from the non-raw function)
  • Non-empty AgentInstallNamespace returning the configured value

The test cases correctly verify that the raw function preserves empty strings instead of applying defaults, which is the intended behavior for template-type addons.

@zhujian7 zhujian7 changed the title Support empty AgentInstallNamespace for template-type addons 🐛 Support empty AgentInstallNamespace for template-type addons Oct 16, 2025
@zhujian7
Copy link
Member Author

/cc @qiujian16

@openshift-ci openshift-ci bot requested a review from qiujian16 October 16, 2025 08:22
// defined in the template manifest itself, rather than applying a default namespace.
// If the addon does not support addon deployment config or there is no matched addon deployment config,
// it will return an empty string.
func AgentInstallNamespaceFromDeploymentConfigRawFunc(
Copy link
Member

Choose a reason for hiding this comment

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

should this be defined in ocm given it is only used for addonTemplate?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not 100% sure if this could be used by other cases.

Copy link
Member

Choose a reason for hiding this comment

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

AgentInstallNamespaceFromDeploymentConfigRawFunc the name is a big confused. Why RawFunc?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is compared with AgentInstallNamespaceFromDeploymentConfigFunc, AgentInstallNamespaceFromDeploymentConfigFunc returns the default open-cluster-management-agent-addon if the addondeploymentconfig.spec.installnamespace is empty, AgentInstallNamespaceFromDeploymentConfigRawFunc returns empty directly.

@zhujian7
Copy link
Member Author

/hold

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