Skip to content

Conversation

@arturshadnik
Copy link
Member

@arturshadnik arturshadnik commented Aug 27, 2025

Description

  • Switch to using clusteradm --labels flag for addon create and enable, remove custom labeling code
  • Remove custom argocd namespace creation code, now that clusteradm supports it via --create-namespace flag
  • Add BaseArgs to all addon related clusteradm invokations
  • Update image version in helm chart

Regression testing

  • Confirmed all addon create and addon enable resources still have the addon.open-cluster-management.io/managedBy: fleetconfig-controller label
  • Confirmed argocd addon can be installed without creating the namespace out of band

Summary by CodeRabbit

  • New Features

    • Automatically apply global labels when creating or enabling add-ons for easier management and selection.
  • Bug Fixes

    • Disabling non-existent add-ons no longer reports misleading errors, improving reliability.
  • Documentation

    • Updated Helm chart README to reflect the latest default image tag.
  • Chores

    • Bumped Helm chart default image to v0.0.13.

Signed-off-by: Artur Shad Nik <arturshadnik@gmail.com>
Signed-off-by: Artur Shad Nik <arturshadnik@gmail.com>
@coderabbitai
Copy link

coderabbitai bot commented Aug 27, 2025

Walkthrough

Bumps Helm chart image tag to v0.0.13. Refactors addon handling by removing addon client propagation, threading FleetConfig through hub/spoke addon flows, updating function signatures, adding labels to addon create/enable commands, and adjusting hub handling to call the revised handleHubAddons.

Changes

Cohort / File(s) Summary
Helm chart version bump
fleetconfig-controller/charts/fleetconfig-controller/README.md, fleetconfig-controller/charts/fleetconfig-controller/values.yaml
Update default image tag from v0.0.12 to v0.0.13; no other chart changes.
Controller addon flow refactor
fleetconfig-controller/internal/controller/v1alpha1/addon.go, fleetconfig-controller/internal/controller/v1alpha1/hub.go, fleetconfig-controller/internal/controller/v1alpha1/spoke.go
Remove addon client threading; pass FleetConfig through addon/hub/spoke handlers; adjust function signatures; add --labels to addon create/enable commands; minor import cleanups; update hub invocation to new handleHubAddons signature.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested labels

approved, lgtm

Suggested reviewers

  • ahmad-ibra
  • TylerGillson
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • 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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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)
fleetconfig-controller/internal/controller/v1alpha1/addon.go (1)

186-205: Nil dereference risk when AddOnTemplate is NotFound

If Get() returns NotFound, addon is nil; dereferencing addon.Spec.AddonName will panic.

-        // delete the addon template
-        if addon != nil {
-            err = addonC.AddonV1alpha1().AddOnTemplates().Delete(ctx, addonName, metav1.DeleteOptions{})
-            if err != nil && !kerrs.IsNotFound(err) {
-                errs = append(errs, fmt.Errorf("failed to delete addon %s: %v", addonName, err))
-                continue
-            }
-        }
-
-        baseAddonName := addon.Spec.AddonName
-        // get the addon name without a version suffix, add it to purge list
-        purgeList = append(purgeList, baseAddonName)
+        // delete the addon template
+        if addon != nil {
+            err = addonC.AddonV1alpha1().AddOnTemplates().Delete(ctx, addonName, metav1.DeleteOptions{})
+            if err != nil && !kerrs.IsNotFound(err) {
+                errs = append(errs, fmt.Errorf("failed to delete addon %s: %v", addonName, err))
+                continue
+            }
+            // get the addon name without a version suffix, add it to purge list
+            purgeList = append(purgeList, addon.Spec.AddonName)
+        } else {
+            // Template missing; skip purge to avoid accidental CMA deletion for out-of-band templates
+            logger.V(3).Info("addon template not found, skipping purge candidate", "AddOnTemplate", addonName)
+        }
🧹 Nitpick comments (3)
fleetconfig-controller/internal/controller/v1alpha1/addon.go (3)

115-123: Use %s for formatting labels (minor)

Prefer %s over %v for clarity since ManagedBySelector.String() returns a string.

-            fmt.Sprintf("--labels=%v", v1alpha1.ManagedBySelector.String()),
+            fmt.Sprintf("--labels=%s", v1alpha1.ManagedBySelector.String()),

374-401: Skip-paths on disable: consider one more benign case (optional)

Some clusteradm versions return “No resources found” on disable; consider treating that as success as well.

-        if strings.Contains(outStr, "add-on not found") {
+        if strings.Contains(outStr, "add-on not found") || strings.Contains(outStr, "No resources found") {
             logger.V(5).Info("addon already disabled (not found)", "managedcluster", spokeName, "addons", addons, "output", outStr)
             return nil
         }

316-364: Add minimal unit coverage for args construction (optional)

Recommend tests that validate:

  • baseArgs includes labels and kubeconfig/timeout from fc.BaseArgs
  • --clusters used instead of --cluster
  • --annotate omitted when no annotations

I can add table-driven tests for handleAddonEnable/handleAddonDisable to assert arg slices.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 27523d6 and 0e99074.

📒 Files selected for processing (5)
  • fleetconfig-controller/charts/fleetconfig-controller/README.md (1 hunks)
  • fleetconfig-controller/charts/fleetconfig-controller/values.yaml (1 hunks)
  • fleetconfig-controller/internal/controller/v1alpha1/addon.go (13 hunks)
  • fleetconfig-controller/internal/controller/v1alpha1/hub.go (1 hunks)
  • fleetconfig-controller/internal/controller/v1alpha1/spoke.go (2 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-08-22T17:55:52.159Z
Learnt from: TylerGillson
PR: open-cluster-management-io/lab#51
File: fleetconfig-controller/charts/fleetconfig-controller/README.md:155-155
Timestamp: 2025-08-22T17:55:52.159Z
Learning: In the open-cluster-management-io/lab repository, chart versioning for fleetconfig-controller is handled automatically via GitHub release workflows, not through manual version bumps in Chart.yaml during regular PRs.

Applied to files:

  • fleetconfig-controller/charts/fleetconfig-controller/README.md
  • fleetconfig-controller/charts/fleetconfig-controller/values.yaml
📚 Learning: 2025-08-22T19:38:49.769Z
Learnt from: arturshadnik
PR: open-cluster-management-io/lab#52
File: fleetconfig-controller/internal/controller/v1beta1/spoke_controller_test.go:49-56
Timestamp: 2025-08-22T19:38:49.769Z
Learning: In the fleetconfig-controller project, the SpokeSpec and HubSpec structs in v1beta1 contain only optional fields (like Foo *string with omitempty tags), so creating these resources without populating the Spec field does not cause validation failures in tests.

Applied to files:

  • fleetconfig-controller/internal/controller/v1alpha1/spoke.go
🧬 Code graph analysis (1)
fleetconfig-controller/internal/controller/v1alpha1/addon.go (2)
fleetconfig-controller/api/v1alpha1/fleetconfig_types.go (5)
  • AddOnConfig (701-724)
  • Spoke (349-391)
  • AddOn (429-441)
  • InstalledHubAddOn (504-513)
  • HubAddOn (799-813)
fleetconfig-controller/api/v1alpha1/constants.go (1)
  • ManagedBySelector (98-98)
⏰ 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). (3)
  • GitHub Check: test (fleetconfig-controller) / Run Helm Chart Tests
  • GitHub Check: test (fleetconfig-controller) / Ensure PR is reviewable & run tests
  • GitHub Check: e2e (fleetconfig-controller) / e2e
🔇 Additional comments (10)
fleetconfig-controller/charts/fleetconfig-controller/values.yaml (1)

279-281: Image tag updated to v0.0.13 — LGTM

In sync with README. Nothing else to change.

fleetconfig-controller/internal/controller/v1alpha1/addon.go (5)

89-92: Signature change to handleAddonCreate — OK

Call site updated to pass fc; aligns with moving to fc.BaseArgs()/clusteradm flags.


411-469: HubAddOns logic assumes ClusterManager bundleVersion; verify singleton path

If hub.singletonControlPlane is used (no ClusterManager), accessing fc.Spec.Hub.ClusterManager.Source.BundleVersion can nil-deref. Confirm singleton isn’t supported yet, or guard accordingly.


481-486: Uninstall hub-addon now uses fc.BaseArgs — LGTM


529-536: Install hub-addon with --create-namespace and BaseArgs — LGTM

Matches PR goal to rely on clusteradm flags.


324-330: Correct syntax for clusteradm addon enable

  • The command uses the --clusters flag (plural) to specify one or more managed cluster names, not --cluster (github.com, open-cluster-management.io)
  • Supported flags for this subcommand are:
    • --names <addon-name>
    • --namespace <namespace>
    • --clusters <cluster1>,<cluster2>,…
    • Optional: --annotate <key=value> (only include when non-empty)
    • Optional: --context <kubeconfig-context>
  • There is no documented --labels flag for addon enable; remove any --labels usage or replace it with one of the supported flags above (github.com)

Example:

clusteradm addon enable \
  --names my-addon \
  --namespace open-cluster-management-agent-addon \
  --clusters cluster1,cluster2 \
  [--annotate addon.open-cluster-management.io/on-multicluster-hub=true] \
  [--context my-hub-context]

Likely an incorrect or invalid review comment.

fleetconfig-controller/internal/controller/v1alpha1/spoke.go (3)

178-201: Switched to handleSpokeAddons(ctx, spoke, fc) — LGTM

Uses fc-threaded flow; conditions updated correctly.


632-636: Passing fc to handleAddonDisable in deregister — LGTM

Ensures BaseArgs are applied during cleanup.


546-565: All checks passed: No stale --cluster= flags or mismatched addon handler signatures

The repository-wide grep confirmed:

  • No occurrences of the singular --cluster= flag in any addon enable paths.
  • Every call to handleAddonEnable matches the signature (ctx, spokeName string, []v1alpha1.AddOn, *FleetConfig).
  • Every call to handleAddonDisable matches the signature (ctx, spokeName string, []string, *FleetConfig).

No further changes are necessary.

fleetconfig-controller/internal/controller/v1alpha1/hub.go (1)

97-103: Updated call to handleHubAddons(ctx, addonC, fc) — LGTM

@arturshadnik arturshadnik changed the title feat: use clusteradm instead of custom code for labeling, ns creation ✨ use clusteradm instead of custom code for labeling, ns creation Aug 27, 2025
@openshift-ci
Copy link

openshift-ci bot commented Aug 27, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: arturshadnik, TylerGillson

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 fa19db2 into open-cluster-management-io:main Aug 27, 2025
8 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