Skip to content

🌱 Update cloudevent client with addon v1beta1 api - #176

Merged
openshift-merge-bot[bot] merged 1 commit into
open-cluster-management-io:mainfrom
qiujian16:addon-v1beta1
Dec 15, 2025
Merged

🌱 Update cloudevent client with addon v1beta1 api#176
openshift-merge-bot[bot] merged 1 commit into
open-cluster-management-io:mainfrom
qiujian16:addon-v1beta1

Conversation

@qiujian16

@qiujian16 qiujian16 commented Dec 15, 2025

Copy link
Copy Markdown
Member

Summary

Related issue(s)

Fixes #

Summary by CodeRabbit

  • New Features
    • Added v1beta1 Managed Cluster Add-On CloudEvents client with support for Get, List, Watch and status Patch, plus a codec for encoding/decoding add-on events.
  • Tests
    • Added tests validating status patch behavior via CloudEvents.
  • Refactor
    • Reworked client wrapping to support both v1alpha1 and v1beta1 pathways and simplified alpha wiring.
  • Chores
    • Bumped dependency versions and reorganized package imports.

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

@openshift-ci
openshift-ci Bot requested a review from deads2k December 15, 2025 07:14
@openshift-ci

openshift-ci Bot commented Dec 15, 2025

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: qiujian16

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

@coderabbitai

coderabbitai Bot commented Dec 15, 2025

Copy link
Copy Markdown

Walkthrough

Adds a v1beta1 CloudEvents addon client, codec, and tests; refactors and renames v1alpha1 addon client components and wrappers to support alpha/beta paths; updates wrapper usage and imports; and bumps the open-cluster-management.io/api dependency.

Changes

Cohort / File(s) Change Summary
Dependency Update
go.mod
Bumped open-cluster-management.io/api dependency version.
v1alpha1 addon client & tests
pkg/cloudevents/clients/addon/v1alpha1/client.go, pkg/cloudevents/clients/addon/v1alpha1/client_test.go, pkg/cloudevents/clients/addon/v1alpha1/codec.go
Package renamed to v1alpha1; introduced ManagedClusterAddOnClient behavior tweaks and an AddonClientWrapper; logging adjusted to use contextual klog; tests updated to use the new wrapper and direct client calls.
v1beta1 addon client, codec & tests
pkg/cloudevents/clients/addon/v1beta1/client.go, pkg/cloudevents/clients/addon/v1beta1/codec.go, pkg/cloudevents/clients/addon/v1beta1/client_test.go
New v1beta1 implementation: ManagedClusterAddOnClient (watcher-store backed Get/List/Watch, CloudEvents-backed Patch for status), new ManagedClusterAddOnCodec for encode/decode, and tests exercising MergePatch status flow.
Wrapper reshaping
pkg/cloudevents/clients/addon/wrapper.go
Replaced prior single alpha wrapper with AddonClientSetWrapper holding alphaClient and betaClient; added AddonV1beta1() accessor; adjusted construction to wire v1alpha1 and placeholder beta wiring.
Import/usage update
pkg/cloudevents/server/grpc/authz/kube/sar.go
Switched import/usage from the old addon package to v1alpha1.ManagedClusterAddOnEventDataType for SAR event-type handling.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

  • Review focus:
    • pkg/cloudevents/clients/addon/v1beta1/client.go — Patch implementation, CloudEvents publish/error translation, watcher-store interactions, and status-subresource handling.
    • pkg/cloudevents/clients/addon/wrapper.go — API surface changes, correct wiring between alpha/beta wrappers, and public interface compatibility.
    • Tests in pkg/cloudevents/clients/addon/v1beta1 — validate test setup, codec usage, and patch assertions.

Possibly related PRs

Suggested labels

lgtm

Suggested reviewers

  • deads2k

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is largely empty, containing only the template structure without meaningful content in the required Summary and Related issue(s) sections. Fill in the Summary section with a concise explanation of the changes and the motivation behind supporting v1beta1. Optionally, reference any related GitHub issues in the Related issue(s) section.
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: updating the CloudEvents client to support the addon v1beta1 API, which aligns with the substantial additions of v1beta1 client implementations and wrapper refactoring throughout 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 6

Caution

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

⚠️ Outside diff range comments (2)
pkg/cloudevents/server/grpc/authz/kube/sar.go (1)

198-204: Missing v1beta1 addon event data type in authorization switch.

The switch only handles v1alpha1.ManagedClusterAddOnEventDataType. With the introduction of v1beta1 addon clients, events using v1beta1.ManagedClusterAddOnEventDataType will fall through to the default case and be rejected as "unsupported event type".

Consider adding v1beta1 support:

+	addonv1beta1 "open-cluster-management.io/sdk-go/pkg/cloudevents/clients/addon/v1beta1"
 	case v1alpha1.ManagedClusterAddOnEventDataType,
+		addonv1beta1.ManagedClusterAddOnEventDataType,
 		csr.CSREventDataType,
 		event.EventEventDataType,
 		lease.LeaseEventDataType:

If v1beta1 addon events are not expected to go through this authorization path, please clarify the intended design.

pkg/cloudevents/clients/addon/v1alpha1/client.go (1)

44-47: Namespace method mutates receiver, risking shared state issues.

The Namespace method modifies c.namespace in place and returns the same pointer. If the same ManagedClusterAddOnClient instance is used concurrently with different namespaces, this could lead to race conditions.

Consider returning a new instance to avoid shared state:

 func (c *ManagedClusterAddOnClient) Namespace(namespace string) *ManagedClusterAddOnClient {
-	c.namespace = namespace
-	return c
+	return &ManagedClusterAddOnClient{
+		cloudEventsClient: c.cloudEventsClient,
+		watcherStore:      c.watcherStore,
+		namespace:         namespace,
+	}
 }
🧹 Nitpick comments (7)
pkg/cloudevents/server/grpc/authz/kube/sar.go (1)

6-7: Import ordering: standard library imports should be grouped together.

The new import breaks the conventional Go import grouping. Consider moving it to the appropriate group.

 import (
 	"context"
 	"fmt"
-	"open-cluster-management.io/sdk-go/pkg/cloudevents/clients/addon/v1alpha1"
 	"sync"
 
 	"google.golang.org/grpc"

Then add it to the open-cluster-management.io import group:

	"open-cluster-management.io/sdk-go/pkg/cloudevents/clients/addon/v1alpha1"
	"open-cluster-management.io/sdk-go/pkg/cloudevents/clients/cluster"
pkg/cloudevents/clients/addon/v1alpha1/client_test.go (2)

74-80: Consider using t.Fatal for setup errors.

Using t.Error in setup code (lines 75, 79) allows the test to continue executing even when critical setup fails, which can lead to confusing nil-pointer panics or misleading error messages.

 		if err != nil {
-			t.Error(err)
+			t.Fatal(err)
 		}
 		addonClient := NewAddonClientWrapper(NewManagedClusterAddOnClient(ceClient, watcherStore))
 		if err := watcherStore.Store.Add(c.addon); err != nil {
-			t.Error(err)
+			t.Fatal(err)
 		}

82-91: Test only verifies no error; consider asserting patch result.

The test verifies that Patch doesn't return an error but doesn't validate that the addon was actually patched with the expected status. Consider retrieving the addon after patching and asserting the status was updated.

pkg/cloudevents/clients/addon/v1beta1/client_test.go (1)

75-81: Consider using t.Fatal for setup errors.

Same as v1alpha1 test: using t.Error in setup code allows the test to continue even when critical setup fails.

 		if err != nil {
-			t.Error(err)
+			t.Fatal(err)
 		}
 		addonClient := NewAddonClientWrapper(NewManagedClusterAddOnClient(ceClient, watcherStore))
 		if err := watcherStore.Store.Add(c.addon); err != nil {
-			t.Error(err)
+			t.Fatal(err)
 		}
pkg/cloudevents/clients/addon/v1beta1/codec.go (2)

3-10: Consider grouping imports by origin.

The imports mix standard library, k8s, and external packages without clear grouping. Standard Go convention groups imports as: standard library, external packages, and local packages.

 import (
 	"fmt"
+
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
-	addonapiv1beta1 "open-cluster-management.io/api/addon/v1beta1"
 
 	cloudevents "github.com/cloudevents/sdk-go/v2"
+
+	addonapiv1beta1 "open-cluster-management.io/api/addon/v1beta1"
 	"open-cluster-management.io/sdk-go/pkg/cloudevents/generic/types"
 )

58-65: Consider validating event data type in Decode for consistency.

Encode validates that the event type matches ManagedClusterAddOnEventDataType, but Decode does not perform similar validation. While this may be acceptable if events are pre-filtered, adding validation would make the codec more robust against misuse.

 func (c *ManagedClusterAddOnCodec) Decode(evt *cloudevents.Event) (*addonapiv1beta1.ManagedClusterAddOn, error) {
+	eventType, err := types.ParseCloudEventsType(evt.Type())
+	if err != nil {
+		return nil, fmt.Errorf("failed to parse cloud event type %s, %v", evt.Type(), err)
+	}
+	if eventType.CloudEventsDataType != ManagedClusterAddOnEventDataType {
+		return nil, fmt.Errorf("unsupported cloudevents data type %s", eventType.CloudEventsDataType)
+	}
+
 	addon := &addonapiv1beta1.ManagedClusterAddOn{}
 	if err := evt.DataAs(addon); err != nil {
 		return nil, fmt.Errorf("failed to unmarshal event data %s, %v", string(evt.Data()), err)
 	}
 
 	return addon, nil
 }
pkg/cloudevents/clients/addon/wrapper.go (1)

44-47: Consider documenting the incomplete v1beta1 initialization.

The TODO indicates this is intentional, but consumers calling AddonV1beta1() will get a nil pointer. Consider adding a comment to the AddonClientSetWrapper struct or AddonV1beta1() method indicating the current limitation.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 62521c9 and 8222fd1.

⛔ Files ignored due to path filters (22)
  • go.sum is excluded by !**/*.sum
  • vendor/modules.txt is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/addon/v1alpha1/0000_00_addon.open-cluster-management.io_clustermanagementaddons.crd.yaml is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/addon/v1alpha1/0000_01_addon.open-cluster-management.io_managedclusteraddons.crd.yaml is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/addon/v1alpha1/types_clustermanagementaddon.go is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/addon/v1alpha1/types_managedclusteraddon.go is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/addon/v1beta1/0000_00_addon.open-cluster-management.io_clustermanagementaddons.crd.yaml is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/addon/v1beta1/0000_01_addon.open-cluster-management.io_managedclusteraddons.crd.yaml is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/addon/v1beta1/doc.go is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/addon/v1beta1/register.go is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/addon/v1beta1/types_clustermanagementaddon.go is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/addon/v1beta1/types_managedclusteraddon.go is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/addon/v1beta1/zz_generated.deepcopy.go is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/client/addon/clientset/versioned/clientset.go is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/client/addon/clientset/versioned/scheme/register.go is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/client/addon/clientset/versioned/typed/addon/v1beta1/addon_client.go is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/client/addon/clientset/versioned/typed/addon/v1beta1/clustermanagementaddon.go is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/client/addon/clientset/versioned/typed/addon/v1beta1/doc.go is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/client/addon/clientset/versioned/typed/addon/v1beta1/generated_expansion.go is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/client/addon/clientset/versioned/typed/addon/v1beta1/managedclusteraddon.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 (9)
  • go.mod (1 hunks)
  • pkg/cloudevents/clients/addon/v1alpha1/client.go (2 hunks)
  • pkg/cloudevents/clients/addon/v1alpha1/client_test.go (2 hunks)
  • pkg/cloudevents/clients/addon/v1alpha1/codec.go (1 hunks)
  • pkg/cloudevents/clients/addon/v1beta1/client.go (1 hunks)
  • pkg/cloudevents/clients/addon/v1beta1/client_test.go (1 hunks)
  • pkg/cloudevents/clients/addon/v1beta1/codec.go (1 hunks)
  • pkg/cloudevents/clients/addon/wrapper.go (3 hunks)
  • pkg/cloudevents/server/grpc/authz/kube/sar.go (2 hunks)
🧰 Additional context used
🧠 Learnings (3)
📚 Learning: 2025-07-07T12:29:10.858Z
Learnt from: skeeey
Repo: open-cluster-management-io/sdk-go PR: 129
File: go.mod:3-3
Timestamp: 2025-07-07T12:29:10.858Z
Learning: Starting with Go 1.18, the `go` directive in `go.mod` files supports patch versions (e.g., `go 1.23.6`). This is valid syntax and will work correctly with Go tooling.

Applied to files:

  • go.mod
📚 Learning: 2025-11-11T13:27:36.331Z
Learnt from: morvencao
Repo: open-cluster-management-io/sdk-go PR: 162
File: pkg/cloudevents/generic/options/pubsub/options.go:157-174
Timestamp: 2025-11-11T13:27:36.331Z
Learning: For open-cluster-management PubSub transport in pkg/cloudevents/generic/options/pubsub: broadcast topics (SourceBroadcast, AgentBroadcast) and their corresponding subscriptions are always required, not optional. The omitempty tags on types.Topics broadcast fields exist because the struct is shared with MQTT (where broadcasts are optional), but PubSub requires all broadcast channels for resync functionality.

Applied to files:

  • pkg/cloudevents/server/grpc/authz/kube/sar.go
📚 Learning: 2025-09-01T03:34:05.141Z
Learnt from: morvencao
Repo: open-cluster-management-io/sdk-go PR: 138
File: pkg/cloudevents/server/grpc/metrics/metrics.go:231-254
Timestamp: 2025-09-01T03:34:05.141Z
Learning: In open-cluster-management.io/sdk-go gRPC CloudEvents metrics, processing duration metrics should only be recorded for unary RPCs, not stream RPCs. Stream RPCs can be long-lived connections that persist as long as the gRPC server runs, making duration metrics confusing and less useful for operators debugging issues.

Applied to files:

  • pkg/cloudevents/server/grpc/authz/kube/sar.go
🧬 Code graph analysis (3)
pkg/cloudevents/server/grpc/authz/kube/sar.go (2)
pkg/cloudevents/clients/addon/v1alpha1/codec.go (1)
  • ManagedClusterAddOnEventDataType (13-17)
pkg/cloudevents/clients/addon/v1beta1/codec.go (1)
  • ManagedClusterAddOnEventDataType (12-16)
pkg/cloudevents/clients/addon/v1alpha1/client_test.go (3)
pkg/cloudevents/clients/addon/v1alpha1/client.go (2)
  • NewAddonClientWrapper (153-155)
  • NewManagedClusterAddOnClient (34-42)
pkg/cloudevents/clients/addon/v1beta1/client.go (2)
  • NewAddonClientWrapper (155-157)
  • NewManagedClusterAddOnClient (32-40)
pkg/cloudevents/clients/utils/utils.go (1)
  • Patch (44-82)
pkg/cloudevents/clients/addon/wrapper.go (2)
pkg/cloudevents/clients/addon/v1alpha1/client.go (3)
  • AddonClientWrapper (147-149)
  • NewManagedClusterAddOnClient (34-42)
  • NewAddonClientWrapper (153-155)
pkg/cloudevents/clients/addon/v1beta1/client.go (3)
  • AddonClientWrapper (149-151)
  • NewManagedClusterAddOnClient (32-40)
  • NewAddonClientWrapper (155-157)
⏰ 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: verify
  • GitHub Check: unit
  • GitHub Check: integration
🔇 Additional comments (3)
pkg/cloudevents/clients/addon/v1alpha1/codec.go (1)

1-67: LGTM!

The package rename to v1alpha1 properly organizes the versioned addon client code. The codec correctly uses addonapiv1alpha1.GroupVersion for the event data type definition and handles encoding/decoding appropriately.

pkg/cloudevents/clients/addon/v1alpha1/client.go (1)

146-175: AddonClientWrapper implementation looks good.

The wrapper correctly implements AddonV1alpha1Interface, delegating to the underlying client for ManagedClusterAddOns and panicking for unsupported methods. This is consistent with the v1beta1 wrapper approach.

pkg/cloudevents/clients/addon/v1beta1/client.go (1)

109-146: Patch implementation looks correct.

The Patch method properly validates that only status subresource patches are allowed, applies the patch, and publishes the update via CloudEvents. The error handling and event type construction are appropriate.

Comment thread go.mod
k8s.io/klog/v2 v2.130.1
k8s.io/utils v0.0.0-20250604170112-4c0f3b243397
open-cluster-management.io/api v1.1.1-0.20251124092621-2337d27c3b7f
open-cluster-management.io/api v1.1.1-0.20251215032811-ee922fbb996c

Copy link
Copy Markdown

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:

cat -n go.mod | sed -n '35,45p'

Repository: open-cluster-management-io/sdk-go

Length of output: 457


🏁 Script executed:

rg "v1beta1" --type go -A 2 -B 2 | head -50

Repository: open-cluster-management-io/sdk-go

Length of output: 3635


🏁 Script executed:

rg "open-cluster-management.io/api" --type go | head -20

Repository: open-cluster-management-io/sdk-go

Length of output: 2566


Dependency update provides v1beta1 addon types, but implementation remains incomplete.

The pseudo-version includes the required v1beta1 addon API types from open-cluster-management.io/api. However, the addon client wrapper still has a TODO comment and only initializes the alpha client; the betaClient field is not yet populated in NewAddonClientSetWrapper. The dependency change is correct, but complete the switch to v1beta1 in pkg/cloudevents/clients/addon/wrapper.go.

Comment thread pkg/cloudevents/clients/addon/v1beta1/client_test.go
Comment thread pkg/cloudevents/clients/addon/v1beta1/client.go
Comment thread pkg/cloudevents/clients/addon/v1beta1/client.go
Comment thread pkg/cloudevents/clients/addon/v1beta1/client.go Outdated
Comment thread pkg/cloudevents/clients/addon/wrapper.go

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
pkg/cloudevents/clients/addon/wrapper.go (1)

33-38: Nil-check added but betaClient is never initialized.

The nil-check panic (addressing the previous review comment) provides a clear error message when AddonV1beta1() is called. However, since betaClient is never initialized in ManagedClusterAddOnInterface, any call to AddonV1beta1() will always panic.

This appears intentional given the TODO on line 49. Consider documenting this limitation in the struct or method comment.

🧹 Nitpick comments (2)
pkg/cloudevents/clients/addon/v1beta1/client_test.go (2)

36-54: Consider using t.Fatal for setup errors that should abort the test.

Errors during patch data generation (lines 38, 48, 53) will allow the test to continue with invalid/nil data. Using t.Fatal would immediately stop the test on setup failures.

 				oldData, err := json.Marshal(old)
 				if err != nil {
-					t.Error(err)
+					t.Fatal(err)
 				}

 				new := old.DeepCopy()
 				new.Status = addonapiv1beta1.ManagedClusterAddOnStatus{
 					Namespace: "install",
 				}

 				newData, err := json.Marshal(new)
 				if err != nil {
-					t.Error(err)
+					t.Fatal(err)
 				}

 				patchBytes, err := jsonpatch.CreateMergePatch(oldData, newData)
 				if err != nil {
-					t.Error(err)
+					t.Fatal(err)
 				}

74-80: Use t.Fatal for setup errors in test body.

Errors creating the CloudEvent client (line 75) or adding to the watcher store (line 79) are setup failures that should stop the test immediately rather than continuing with a nil client or missing data.

 			if err != nil {
-				t.Error(err)
+				t.Fatal(err)
 			}
 			addonClient := NewAddonClientWrapper(NewManagedClusterAddOnClient(ceClient, watcherStore))
 			if err := watcherStore.Store.Add(c.addon); err != nil {
-				t.Error(err)
+				t.Fatal(err)
 			}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8222fd1 and a5bbc6a.

⛔ Files ignored due to path filters (22)
  • go.sum is excluded by !**/*.sum
  • vendor/modules.txt is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/addon/v1alpha1/0000_00_addon.open-cluster-management.io_clustermanagementaddons.crd.yaml is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/addon/v1alpha1/0000_01_addon.open-cluster-management.io_managedclusteraddons.crd.yaml is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/addon/v1alpha1/types_clustermanagementaddon.go is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/addon/v1alpha1/types_managedclusteraddon.go is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/addon/v1beta1/0000_00_addon.open-cluster-management.io_clustermanagementaddons.crd.yaml is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/addon/v1beta1/0000_01_addon.open-cluster-management.io_managedclusteraddons.crd.yaml is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/addon/v1beta1/doc.go is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/addon/v1beta1/register.go is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/addon/v1beta1/types_clustermanagementaddon.go is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/addon/v1beta1/types_managedclusteraddon.go is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/addon/v1beta1/zz_generated.deepcopy.go is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/client/addon/clientset/versioned/clientset.go is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/client/addon/clientset/versioned/scheme/register.go is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/client/addon/clientset/versioned/typed/addon/v1beta1/addon_client.go is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/client/addon/clientset/versioned/typed/addon/v1beta1/clustermanagementaddon.go is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/client/addon/clientset/versioned/typed/addon/v1beta1/doc.go is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/client/addon/clientset/versioned/typed/addon/v1beta1/generated_expansion.go is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/client/addon/clientset/versioned/typed/addon/v1beta1/managedclusteraddon.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 (9)
  • go.mod (1 hunks)
  • pkg/cloudevents/clients/addon/v1alpha1/client.go (4 hunks)
  • pkg/cloudevents/clients/addon/v1alpha1/client_test.go (2 hunks)
  • pkg/cloudevents/clients/addon/v1alpha1/codec.go (1 hunks)
  • pkg/cloudevents/clients/addon/v1beta1/client.go (1 hunks)
  • pkg/cloudevents/clients/addon/v1beta1/client_test.go (1 hunks)
  • pkg/cloudevents/clients/addon/v1beta1/codec.go (1 hunks)
  • pkg/cloudevents/clients/addon/wrapper.go (3 hunks)
  • pkg/cloudevents/server/grpc/authz/kube/sar.go (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • pkg/cloudevents/server/grpc/authz/kube/sar.go
  • pkg/cloudevents/clients/addon/v1beta1/codec.go
  • pkg/cloudevents/clients/addon/v1alpha1/client_test.go
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-07-07T12:29:10.858Z
Learnt from: skeeey
Repo: open-cluster-management-io/sdk-go PR: 129
File: go.mod:3-3
Timestamp: 2025-07-07T12:29:10.858Z
Learning: Starting with Go 1.18, the `go` directive in `go.mod` files supports patch versions (e.g., `go 1.23.6`). This is valid syntax and will work correctly with Go tooling.

Applied to files:

  • go.mod
🧬 Code graph analysis (4)
pkg/cloudevents/clients/addon/v1beta1/client_test.go (4)
pkg/cloudevents/generic/options/fake/fakeoptions.go (1)
  • NewEventChan (35-40)
pkg/cloudevents/clients/store/lister.go (1)
  • NewAgentWatcherStoreLister (15-19)
pkg/cloudevents/clients/addon/v1beta1/codec.go (1)
  • NewManagedClusterAddOnCodec (21-23)
pkg/cloudevents/clients/addon/v1beta1/client.go (2)
  • NewAddonClientWrapper (158-160)
  • NewManagedClusterAddOnClient (32-40)
pkg/cloudevents/clients/addon/wrapper.go (2)
pkg/cloudevents/clients/addon/v1alpha1/client.go (3)
  • AddonClientWrapper (150-152)
  • NewManagedClusterAddOnClient (34-42)
  • NewAddonClientWrapper (156-158)
pkg/cloudevents/clients/addon/v1beta1/client.go (3)
  • AddonClientWrapper (152-154)
  • NewManagedClusterAddOnClient (32-40)
  • NewAddonClientWrapper (158-160)
pkg/cloudevents/clients/addon/v1alpha1/client.go (2)
pkg/cloudevents/clients/addon/v1beta1/client.go (3)
  • ManagedClusterAddOnClient (24-28)
  • AddonClientWrapper (152-154)
  • NewAddonClientWrapper (158-160)
pkg/cloudevents/clients/addon/wrapper.go (1)
  • ManagedClusterAddOnInterface (41-51)
pkg/cloudevents/clients/addon/v1beta1/client.go (6)
pkg/cloudevents/clients/store/interface.go (1)
  • ClientWatcherStore (32-63)
pkg/cloudevents/clients/addon/wrapper.go (1)
  • ManagedClusterAddOnInterface (41-51)
pkg/cloudevents/clients/common/common.go (1)
  • ManagedClusterAddOnGR (43-43)
pkg/patcher/patcher.go (1)
  • PatchOptions (34-37)
pkg/cloudevents/clients/addon/v1beta1/codec.go (1)
  • ManagedClusterAddOnEventDataType (12-16)
pkg/cloudevents/clients/errors/errors.go (1)
  • ToStatusError (18-30)
⏰ 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: unit
  • GitHub Check: verify
  • GitHub Check: integration
🔇 Additional comments (9)
go.mod (1)

40-40: Verify that implementation in wrapper.go has been completed.

The dependency version bump appears valid, but a previous review flagged that the addon client wrapper had incomplete initialization—specifically, the betaClient field in NewAddonClientSetWrapper was not populated despite the dependency providing v1beta1 types. Confirm that pkg/cloudevents/clients/addon/wrapper.go has been fully updated to initialize both alpha and beta clients.

pkg/cloudevents/clients/addon/v1alpha1/codec.go (1)

1-1: LGTM - Package rename aligns with version separation.

The package rename from addon to v1alpha1 correctly organizes the code to support both v1alpha1 and v1beta1 API versions in separate packages.

pkg/cloudevents/clients/addon/v1alpha1/client.go (2)

44-50: Good refactor - Namespace now returns a new instance.

This immutable pattern avoids shared-state issues when the same client is used concurrently.


148-178: LGTM - AddonClientWrapper properly bridges to the interface.

The wrapper correctly implements AddonV1alpha1Interface with panic stubs for unsupported methods and delegates ManagedClusterAddOns to the underlying client.

pkg/cloudevents/clients/addon/wrapper.go (1)

47-50: LGTM - v1alpha1 client wiring is correct.

The alpha client is properly initialized. The TODO comment clarifies that v1beta1 support will be added later.

pkg/cloudevents/clients/addon/v1beta1/client.go (4)

42-48: Good - Namespace returns a new instance avoiding shared state.

This addresses the concurrency concern from the previous review.


71-83: Structured logging is correctly implemented.

The logging now properly uses key-value pairs with klog.FromContext(ctx).


112-149: Patch implementation looks correct.

The method properly:

  • Validates status subresource is present
  • Fetches current state from watcher store
  • Applies the patch
  • Publishes CloudEvents update request
  • Handles errors appropriately

151-172: LGTM - AddonClientWrapper correctly implements AddonV1beta1Interface.

The comment is now correct (references v1beta1), and the wrapper properly delegates to the underlying client.

Comment thread pkg/cloudevents/clients/addon/v1alpha1/client.go Outdated
Signed-off-by: Jian Qiu <jqiu@redhat.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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/cloudevents/clients/addon/v1beta1/client_test.go (1)

19-94: LGTM! Solid test coverage for v1beta1 client.

The test correctly validates the Patch operation for v1beta1 ManagedClusterAddOn, using v1beta1 types consistently throughout. The structure mirrors the proven v1alpha1 test pattern.

The v1alpha1 and v1beta1 tests share significant structure. Consider extracting a shared test helper function in a future refactor to reduce duplication:

// Future optional refactor
func testPatchHelper[T any](t *testing.T, codec Codec[T], wrapper func(*Client[T]) Interface) {
    // shared test logic
}

This is entirely optional and can be deferred to a future cleanup PR.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a5bbc6a and 5d18af6.

⛔ Files ignored due to path filters (22)
  • go.sum is excluded by !**/*.sum
  • vendor/modules.txt is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/addon/v1alpha1/0000_00_addon.open-cluster-management.io_clustermanagementaddons.crd.yaml is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/addon/v1alpha1/0000_01_addon.open-cluster-management.io_managedclusteraddons.crd.yaml is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/addon/v1alpha1/types_clustermanagementaddon.go is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/addon/v1alpha1/types_managedclusteraddon.go is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/addon/v1beta1/0000_00_addon.open-cluster-management.io_clustermanagementaddons.crd.yaml is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/addon/v1beta1/0000_01_addon.open-cluster-management.io_managedclusteraddons.crd.yaml is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/addon/v1beta1/doc.go is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/addon/v1beta1/register.go is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/addon/v1beta1/types_clustermanagementaddon.go is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/addon/v1beta1/types_managedclusteraddon.go is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/addon/v1beta1/zz_generated.deepcopy.go is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/client/addon/clientset/versioned/clientset.go is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/client/addon/clientset/versioned/scheme/register.go is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/client/addon/clientset/versioned/typed/addon/v1beta1/addon_client.go is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/client/addon/clientset/versioned/typed/addon/v1beta1/clustermanagementaddon.go is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/client/addon/clientset/versioned/typed/addon/v1beta1/doc.go is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/client/addon/clientset/versioned/typed/addon/v1beta1/generated_expansion.go is excluded by !vendor/**
  • vendor/open-cluster-management.io/api/client/addon/clientset/versioned/typed/addon/v1beta1/managedclusteraddon.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 (9)
  • go.mod (1 hunks)
  • pkg/cloudevents/clients/addon/v1alpha1/client.go (7 hunks)
  • pkg/cloudevents/clients/addon/v1alpha1/client_test.go (2 hunks)
  • pkg/cloudevents/clients/addon/v1alpha1/codec.go (1 hunks)
  • pkg/cloudevents/clients/addon/v1beta1/client.go (1 hunks)
  • pkg/cloudevents/clients/addon/v1beta1/client_test.go (1 hunks)
  • pkg/cloudevents/clients/addon/v1beta1/codec.go (1 hunks)
  • pkg/cloudevents/clients/addon/wrapper.go (3 hunks)
  • pkg/cloudevents/server/grpc/authz/kube/sar.go (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • pkg/cloudevents/server/grpc/authz/kube/sar.go
  • go.mod
  • pkg/cloudevents/clients/addon/v1beta1/client.go
🧰 Additional context used
🧬 Code graph analysis (3)
pkg/cloudevents/clients/addon/v1alpha1/client.go (2)
pkg/cloudevents/clients/addon/v1beta1/client.go (3)
  • ManagedClusterAddOnClient (24-28)
  • AddonClientWrapper (152-154)
  • NewAddonClientWrapper (158-160)
pkg/cloudevents/clients/addon/wrapper.go (1)
  • ManagedClusterAddOnInterface (41-51)
pkg/cloudevents/clients/addon/v1beta1/codec.go (2)
pkg/cloudevents/generic/types/types.go (4)
  • CloudEventsDataType (210-214)
  • CloudEventsType (221-230)
  • NewEventBuilder (288-293)
  • ExtensionResourceVersion (64-64)
pkg/cloudevents/clients/addon/v1alpha1/codec.go (3)
  • NewManagedClusterAddOnCodec (22-24)
  • ManagedClusterAddOnCodec (20-20)
  • ManagedClusterAddOnEventDataType (13-17)
pkg/cloudevents/clients/addon/wrapper.go (2)
pkg/cloudevents/clients/addon/v1alpha1/client.go (3)
  • AddonClientWrapper (154-156)
  • NewManagedClusterAddOnClient (34-42)
  • NewAddonClientWrapper (160-162)
pkg/cloudevents/clients/addon/v1beta1/client.go (3)
  • AddonClientWrapper (152-154)
  • NewManagedClusterAddOnClient (32-40)
  • NewAddonClientWrapper (158-160)
⏰ 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: integration
  • GitHub Check: verify
  • GitHub Check: unit
🔇 Additional comments (8)
pkg/cloudevents/clients/addon/v1alpha1/codec.go (1)

1-1: LGTM! Clean package reorganization.

The package rename to v1alpha1 properly aligns with the version-based directory structure and enables clean separation between alpha and beta API versions.

pkg/cloudevents/clients/addon/v1alpha1/client_test.go (1)

77-82: LGTM! Test correctly adapted to new wrapper architecture.

The test now properly exercises the new AddonClientWrapper pattern, using ManagedClusterAddOns(namespace) to access the namespace-scoped client interface.

pkg/cloudevents/clients/addon/v1alpha1/client.go (3)

44-50: LGTM! Namespace method correctly preserves immutability.

The updated implementation returns a new ManagedClusterAddOnClient instance with the namespace set, rather than mutating the receiver. This is a good practice that prevents unexpected side effects when the same client is used for multiple namespaces.


74-75: LGTM! Structured logging properly implemented.

The switch to klog.FromContext(ctx) with structured key-value pairs provides better observability and log parsing capabilities. The context-aware logging also enables correlation with distributed tracing when configured.

Also applies to: 88-89, 104-105, 116-117


153-182: LGTM! Clean adapter pattern for version-specific interface.

The AddonClientWrapper provides a clean bridge between the CloudEvents-based client and the legacy AddonV1alpha1Interface. The panic stubs for unsupported operations are acceptable since this client is specifically designed for CloudEvents-based agent communication, not general-purpose REST operations.

pkg/cloudevents/clients/addon/wrapper.go (2)

17-38: LGTM! Clean dual-version wrapper structure.

The refactored AddonClientSetWrapper properly supports both v1alpha1 and v1beta1 interfaces. The nil check on betaClient (lines 34-36) appropriately guards against premature access before v1beta1 is initialized.


47-50: TODO is appropriate for gradual v1beta1 migration.

The TODO comment clearly documents the planned migration path. The current alpha-only initialization is correct for this transitional phase, allowing beta support to be added incrementally.

pkg/cloudevents/clients/addon/v1beta1/codec.go (1)

1-66: LGTM! Solid v1beta1 codec implementation.

The codec correctly implements CloudEvents encoding/decoding for v1beta1 ManagedClusterAddOn resources. The implementation appropriately mirrors the proven v1alpha1 pattern while using v1beta1 types throughout:

  • Event data type properly references v1beta1 GroupVersion
  • Encode validates data type and embeds resource metadata
  • ResourceVersion extension handling preserves version information
  • TypeMeta stamping ensures proper API version/kind in events
  • Error handling provides clear diagnostics

The code duplication between v1alpha1 and v1beta1 codecs is expected and acceptable for version-specific CloudEvents encoding.

@haoqing0110

Copy link
Copy Markdown
Member

/lgtm

@openshift-ci openshift-ci Bot added the lgtm label Dec 15, 2025
@openshift-merge-bot
openshift-merge-bot Bot merged commit 72dfdeb into open-cluster-management-io:main Dec 15, 2025
12 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