Skip to content

Conversation

@zhujian7
Copy link
Member

@zhujian7 zhujian7 commented Oct 15, 2025

Summary

This PR implements the API repository changes for ocm#1209, allowing template-type addons to use the namespace defined in their addonTemplate by setting agentInstallNamespace to an empty string.

Changes

1. API Type Changes

  • Updated AgentInstallNamespace validation pattern in types_addondeploymentconfig.go from ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$ to ^([a-z0-9]([-a-z0-9]*[a-z0-9])?)?$ to allow empty strings
  • Added documentation clarifying the behavior difference between template-type and non-template addons

2. CRD Updates

  • Regenerated CRD manifests with the updated validation pattern and documentation

3. Integration Tests

  • Added comprehensive test coverage for AgentInstallNamespace validation:
    • Valid: empty string (for template namespaces)
    • Valid: custom namespace name
    • Invalid: starts with hyphen
    • Invalid: contains uppercase
    • Invalid: exceeds max length (63 chars)

Behavior

For template-type addons:

  • Set agentInstallNamespace: "" to use the namespace defined in the addonTemplate
  • Set to a specific value to override the template namespace

For non-template addons:

  • Defaults to "open-cluster-management-agent-addon" if not specified
  • Maintains existing behavior

Backward Compatibility

✅ Fully backward compatible - existing configs continue to work with the default namespace

Related issue(s)

open-cluster-management-io/ocm#1209

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Agent install namespace is now optional. Leaving it empty will use the add-on template’s namespace for template-based add-ons, or default to the standard agent add-on namespace for non-template add-ons.
  • Documentation

    • Expanded description clarifying behavior and defaults for the agent install namespace across template and non-template add-ons.
  • Tests

    • Added integration tests covering empty, valid, and invalid agent install namespace scenarios, including length and character constraints.

…spaces

This change updates the AgentInstallNamespace field validation pattern
to allow empty strings, enabling template-type addons to use the namespace
defined in their addonTemplate.

Key changes:
- Updated validation pattern from ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$ to
  ^([a-z0-9]([-a-z0-9]*[a-z0-9])?)?$ to allow empty strings
- Added documentation clarifying behavior for template vs non-template addons
- Regenerated CRD manifests
- Added comprehensive integration tests for validation

This allows users to explicitly set agentInstallNamespace to "" to use
their template's namespace, while maintaining backward compatibility with
the default "open-cluster-management-agent-addon" namespace.

🤖 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 mdelder and qiujian16 October 15, 2025 08:50
@coderabbitai
Copy link

coderabbitai bot commented Oct 15, 2025

Walkthrough

Makes agentInstallNamespace optional by updating validation to allow empty string, removes implicit defaulting behavior in API comments, expands CRD field description, and adds integration tests covering valid, invalid, and empty namespace cases.

Changes

Cohort / File(s) Summary
CRD schema update
addon/v1alpha1/0000_02_addon.open-cluster-management.io_addondeploymentconfigs.crd.yaml
Expanded description for AgentInstallNamespace; relaxed pattern to allow empty string.
API type validation
addon/v1alpha1/types_addondeploymentconfig.go
Changed regex to make AgentInstallNamespace optional; added comments clarifying template vs non-template behavior.
Integration tests
test/integration/api/addondeploymentconfig_test.go
Added tests for empty, valid, and invalid agentInstallNamespace values, including uppercase, leading hyphen, and overlength cases.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

Suggested labels

lgtm, approved

Suggested reviewers

  • mdelder
  • deads2k

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title Check ✅ Passed The title clearly summarizes the primary change of allowing an empty string for AgentInstallNamespace to support template namespaces and uses a relevant bug-fix emoji, making it concise and directly reflective of the pull request's intent.
Linked Issues Check ✅ Passed The PR addresses the API-focused objectives of linked issue #1209 by removing the non-empty validation constraint on AgentInstallNamespace, updating CRD validation and documentation to allow empty strings, and adding integration tests to verify valid and invalid values; it correctly implements the minimum coding change for Option 2/3 of the proposed solutions without overreaching into framework logic changes.
Out of Scope Changes Check ✅ Passed All modifications in API types, CRD manifest, and integration tests are directly related to relaxing and documenting the AgentInstallNamespace validation requirement from issue #1209, and no unrelated or extraneous code changes were introduced.
Description Check ✅ Passed The pull request description follows the repository template by providing a clear Summary and listing the Related issue(s), and includes detailed Changes, Behavior, and Backward Compatibility sections without omitting any required fields.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ 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

/cc @qiujian16

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 (2)
test/integration/api/addondeploymentconfig_test.go (2)

163-256: Excellent test coverage for the new validation behavior.

The integration tests comprehensively validate the updated agentInstallNamespace field:

  • Empty string acceptance (lines 163-180): validates template namespace support
  • Valid namespace (lines 182-199): confirms standard namespace format works
  • Invalid formats (lines 201-237): correctly reject leading hyphens and uppercase
  • Length constraint (lines 239-256): validates 63-char maximum

Optional: Make the max-length test more precise.

At line 246, rand.String(64) generates a random 64-character string that may contain non-lowercase characters, potentially causing the test to fail for pattern mismatch rather than length. Consider generating a valid but too-long namespace string for clearer test intent:

-				AgentInstallNamespace: rand.String(64), // max is 63
+				AgentInstallNamespace: "a" + rand.String(62) + "b", // 64 chars total, max is 63

This ensures the test fails specifically due to length violation. However, since the test already validates that invalid configs are rejected (regardless of the specific reason), the current implementation is acceptable.


163-180: Consider adding an explicit test for default behavior.

While existing tests at lines 31-89 implicitly verify the default namespace behavior (by omitting agentInstallNamespace), consider adding a dedicated test that explicitly verifies the default value is applied when the field is omitted. This would make the test coverage more obvious and document the default behavior more clearly.

Example test:

ginkgo.It("Should apply default agentInstallNamespace when field is omitted", func() {
	addOnDeploymentConfig := &addonv1alpha1.AddOnDeploymentConfig{
		ObjectMeta: metav1.ObjectMeta{
			Name:      addOnDeploymentConfigName,
			Namespace: testNamespace,
		},
		Spec: addonv1alpha1.AddOnDeploymentConfigSpec{
			// AgentInstallNamespace intentionally omitted
		},
	}

	created, err := hubAddonClient.AddonV1alpha1().AddOnDeploymentConfigs(testNamespace).Create(
		context.TODO(),
		addOnDeploymentConfig,
		metav1.CreateOptions{},
	)
	gomega.Expect(err).ToNot(gomega.HaveOccurred())
	gomega.Expect(created.Spec.AgentInstallNamespace).To(gomega.Equal("open-cluster-management-agent-addon"))
})

This test would explicitly document and verify that the default namespace is applied when the field is omitted, distinguishing it from the empty string case.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 87a44af and d2a6c8c.

📒 Files selected for processing (3)
  • addon/v1alpha1/0000_02_addon.open-cluster-management.io_addondeploymentconfigs.crd.yaml (1 hunks)
  • addon/v1alpha1/types_addondeploymentconfig.go (1 hunks)
  • test/integration/api/addondeploymentconfig_test.go (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
test/integration/api/addondeploymentconfig_test.go (1)
addon/v1alpha1/types_addondeploymentconfig.go (2)
  • AddOnDeploymentConfig (14-21)
  • AddOnDeploymentConfigSpec (23-72)
⏰ 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). (1)
  • GitHub Check: verify
🔇 Additional comments (2)
addon/v1alpha1/0000_02_addon.open-cluster-management.io_addondeploymentconfigs.crd.yaml (1)

44-50: LGTM! Validation pattern and documentation correctly support empty string for template namespaces.

The pattern change from ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$ to ^([a-z0-9]([-a-z0-9]*[a-z0-9])?)?$ correctly makes the field optional by wrapping the entire expression in an outer optional group. This allows:

  • Empty string: for template-type addons to use addonTemplate namespace
  • Valid namespace strings: lowercase alphanumeric, hyphens (not leading/trailing), up to 63 chars
  • Default behavior: preserved for backward compatibility when field is omitted

The expanded description clearly documents the intended behavior for both template-type and non-template addons.

addon/v1alpha1/types_addondeploymentconfig.go (1)

56-63: LGTM! Type definition changes are consistent with CRD updates.

The validation pattern and documentation comments correctly reflect the API change to support empty string for template-type addons. The +kubebuilder:default marker ensures backward compatibility by applying the default namespace when the field is omitted, while allowing explicit empty string values to pass through for template namespace resolution.

@qiujian16
Copy link
Member

/approve
/lgtm

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Oct 16, 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 f042545 into open-cluster-management-io:main Oct 16, 2025
13 checks passed
zhujian7 added a commit to zhujian7/addon-framework that referenced this pull request Oct 16, 2025
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]>
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