Skip to content

🌱 handle resource in informer - #178

Merged
openshift-merge-bot[bot] merged 1 commit into
open-cluster-management-io:mainfrom
skeeey:informer
Dec 18, 2025
Merged

🌱 handle resource in informer#178
openshift-merge-bot[bot] merged 1 commit into
open-cluster-management-io:mainfrom
skeeey:informer

Conversation

@skeeey

@skeeey skeeey commented Dec 17, 2025

Copy link
Copy Markdown
Member

Summary

the generic agent client only send its received resource to handle, it will not preprocess the resource, each handler will determine how to handle the resource

Related issue(s)

Fixes #

Summary by CodeRabbit

  • Refactor
    • Unified resource processing: handlers now receive only the resource object and the system infers add/update/delete from its state.
  • Breaking Changes
    • Handler and store APIs updated to remove the explicit action parameter — update integrations accordingly.

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

@coderabbitai

coderabbitai Bot commented Dec 17, 2025

Copy link
Copy Markdown

Walkthrough

This PR removes the ResourceAction parameter and the ResourceAction type/constants across CloudEvents handler and store code, updating interfaces, store implementations, clients, and tests so handlers and store entry points accept only the resource object (context + resource).

Changes

Cohort / File(s) Summary
Core types & interfaces
pkg/cloudevents/generic/interface.go, pkg/cloudevents/generic/types/types.go, pkg/cloudevents/clients/store/interface.go
Removed ResourceAction type and constants; updated ResourceHandler and ClientWatcherStore.HandleReceivedResource signatures to accept only (ctx context.Context, obj T) error.
Store implementations
pkg/cloudevents/clients/store/informer.go, pkg/cloudevents/clients/store/simplestore.go, pkg/cloudevents/clients/work/store/base.go, pkg/cloudevents/clients/work/store/informer.go
Dropped action param from HandleReceivedResource; unified single-path resource handling (add/update/delete) using metadata/UID; added UID-based helpers in work informer and adjusted deletion/finalizer/generation handling.
Client implementations
pkg/cloudevents/generic/clients/agentclient.go, pkg/cloudevents/generic/clients/sourceclient.go
Removed specAction computation and action-driven branches; invoke handlers with only the decoded resource object.
Store tests
pkg/cloudevents/clients/store/informer_test.go, pkg/cloudevents/clients/store/simplestore_test.go, pkg/cloudevents/clients/work/store/informer_test.go
Updated test call sites and expectations to remove action argument; adjusted setup/expectations for unified handling.
Client tests & metrics
pkg/cloudevents/generic/clients/agentclient_test.go, pkg/cloudevents/generic/clients/clients_metrics_test.go, pkg/cloudevents/generic/clients/sourceclient_test.go
Updated handler/test callbacks to remove action parameter and refactored validations to assert on resource objects rather than action values.
Integration test
test/integration/cloudevents/source/client.go
Updated subscription callback to accept only the resource parameter; removed types import usage.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Pay special attention to:
    • pkg/cloudevents/clients/work/store/informer.go — UID-based lookup, findWorksByUID / getWork, and correct preservation of local fields (Finalizers, Status, Generation).
    • pkg/cloudevents/clients/store/informer.go and simplestore.go — deletion handling (DeletionTimestamp, finalizers) and consistent Add/Update/Delete operations against the local store.
    • Interface/type removals in pkg/cloudevents/generic/types/types.go and cascade updates across clients/tests.

Possibly related PRs

Suggested labels

approved, lgtm

Suggested reviewers

  • deads2k
  • qiujian16

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 2 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title check ❓ Inconclusive The title is vague and generic, using non-descriptive phrasing that doesn't clearly convey what the changeset accomplishes. Replace with a more specific title that describes the main change, such as 'Remove action parameter from resource handlers' or 'Refactor resource handling to skip preprocessing'.
Description check ❓ Inconclusive The description provides some context about the change but lacks detail on the scope and impact of removing the action parameter from the public API. Expand the summary to explain that the action parameter has been removed from ResourceHandler and all implementations, making this a breaking API change that affects handler signatures across multiple components.
✨ 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.

@skeeey
skeeey force-pushed the informer branch 3 times, most recently from 1be7def to dcd8347 Compare December 17, 2025 07:26
@skeeey
skeeey marked this pull request as ready for review December 17, 2025 09:25
@openshift-ci
openshift-ci Bot requested review from deads2k and qiujian16 December 17, 2025 09:25

@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

🧹 Nitpick comments (3)
pkg/cloudevents/clients/store/simplestore_test.go (1)

33-37: Remove unused action field from test cases.

The action field is defined in the test case struct but never used after line 111 changed to call HandleReceivedResource with only the resource. This creates dead code that may confuse future readers.

 	cases := []struct {
 		name     string
-		action   watch.EventType
 		received *coordv1.Lease
 		validate func(t *testing.T, namespace, name string)
 	}{

And remove the action field assignments from each test case (lines 41, 61, 88).

pkg/cloudevents/clients/store/informer.go (1)

80-85: Variable runtimeObj is shadowed inside the if block.

The variable runtimeObj declared on line 80 with := shadows the outer runtimeObj from line 51. While this appears intentional (converting deletingObj to a runtime object), it may cause confusion during maintenance.

Consider using a different variable name for clarity:

-			runtimeObj, err := utils.ToRuntimeObject(deletingObj)
+			deletingRuntimeObj, err := utils.ToRuntimeObject(deletingObj)
 			if err != nil {
 				return err
 			}
 
-			return s.Update(runtimeObj)
+			return s.Update(deletingRuntimeObj)
pkg/cloudevents/clients/work/store/informer.go (1)

221-234: Consider performance implications of full store scan for UID lookup.

findWorksByUID iterates over all works in the store via ListAll() to find works by UID. This is O(n) per received resource and may become a bottleneck with large work counts.

The TODO comment on line 170 acknowledges this is for compatibility. Consider adding an index on UID for efficient lookups if this code path is frequently exercised:

// Consider using cache.Indexers with a UID indexer:
// cache.NewIndexer(cache.MetaNamespaceKeyFunc, cache.Indexers{
//     "uid": func(obj interface{}) ([]string, error) { ... },
// })
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7e7c96b and dcd8347.

📒 Files selected for processing (16)
  • pkg/cloudevents/clients/store/informer.go (1 hunks)
  • pkg/cloudevents/clients/store/informer_test.go (2 hunks)
  • pkg/cloudevents/clients/store/interface.go (1 hunks)
  • pkg/cloudevents/clients/store/simplestore.go (1 hunks)
  • pkg/cloudevents/clients/store/simplestore_test.go (5 hunks)
  • pkg/cloudevents/clients/work/store/base.go (1 hunks)
  • pkg/cloudevents/clients/work/store/informer.go (2 hunks)
  • pkg/cloudevents/clients/work/store/informer_test.go (2 hunks)
  • pkg/cloudevents/generic/clients/agentclient.go (1 hunks)
  • pkg/cloudevents/generic/clients/agentclient_test.go (5 hunks)
  • pkg/cloudevents/generic/clients/clients_metrics_test.go (1 hunks)
  • pkg/cloudevents/generic/clients/sourceclient.go (1 hunks)
  • pkg/cloudevents/generic/clients/sourceclient_test.go (5 hunks)
  • pkg/cloudevents/generic/interface.go (1 hunks)
  • pkg/cloudevents/generic/types/types.go (0 hunks)
  • test/integration/cloudevents/source/client.go (1 hunks)
💤 Files with no reviewable changes (1)
  • pkg/cloudevents/generic/types/types.go
🧰 Additional context used
🧠 Learnings (2)
📚 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/generic/clients/agentclient_test.go
  • pkg/cloudevents/generic/clients/clients_metrics_test.go
  • pkg/cloudevents/clients/work/store/base.go
  • pkg/cloudevents/clients/store/interface.go
  • test/integration/cloudevents/source/client.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/clients/store/interface.go
🧬 Code graph analysis (6)
pkg/cloudevents/generic/clients/agentclient_test.go (1)
pkg/cloudevents/generic/testing/resource.go (1)
  • MockResource (23-31)
pkg/cloudevents/clients/store/informer.go (2)
pkg/cloudevents/clients/work/store/informer.go (1)
  • AgentInformerWatcherStore (91-95)
pkg/cloudevents/clients/utils/utils.go (1)
  • ToRuntimeObject (183-190)
pkg/cloudevents/generic/clients/clients_metrics_test.go (1)
pkg/cloudevents/generic/testing/resource.go (1)
  • MockResource (23-31)
pkg/cloudevents/generic/clients/sourceclient_test.go (1)
pkg/cloudevents/generic/testing/resource.go (1)
  • MockResource (23-31)
pkg/cloudevents/clients/store/simplestore.go (1)
pkg/cloudevents/clients/utils/utils.go (1)
  • ToRuntimeObject (183-190)
pkg/cloudevents/clients/work/store/informer.go (2)
pkg/cloudevents/clients/store/informer.go (1)
  • AgentInformerWatcherStore (21-24)
pkg/cloudevents/clients/utils/utils.go (1)
  • UID (222-225)
🔇 Additional comments (17)
pkg/cloudevents/generic/clients/clients_metrics_test.go (1)

102-105: LGTM!

The callback signature correctly aligns with the updated ResourceHandler[T] type that no longer includes the action parameter. The test's focus on metrics validation remains intact.

pkg/cloudevents/generic/interface.go (1)

14-15: Breaking API change - verify external consumers.

The signature change removes the action parameter, shifting responsibility for determining resource handling semantics to the handler implementations. Handlers can infer actions from resource state (e.g., DeletionTimestamp for deletions, presence in store for adds vs updates).

Ensure this breaking change is documented in release notes for any external consumers of this SDK.

pkg/cloudevents/generic/clients/sourceclient.go (1)

205-214: LGTM!

The handler invocation correctly passes only the decoded resource object, eliminating the previously hardcoded types.StatusModified action. Handlers can now determine the appropriate action based on resource state.

test/integration/cloudevents/source/client.go (1)

39-41: LGTM!

The callback correctly uses the simplified signature. The UpdateStatus call appropriately handles the resource without needing an explicit action parameter.

pkg/cloudevents/clients/store/interface.go (1)

35-36: LGTM!

The interface change correctly removes the action parameter. Implementations can determine the appropriate action from resource state:

  • Deletion: resource.GetDeletionTimestamp() != nil
  • Add vs Update: check store existence
pkg/cloudevents/clients/store/simplestore_test.go (1)

109-117: LGTM!

The test correctly invokes HandleReceivedResource with only the context and resource, matching the updated interface signature. The validation logic properly verifies store state after each operation.

pkg/cloudevents/generic/clients/agentclient.go (1)

201-210: LGTM! Handler invocation simplified correctly.

The handler is now invoked with just the context and resource object. Each handler can determine the appropriate action by inspecting the resource state (e.g., checking DeletionTimestamp for deletions). The error handling with conditional verbose logging is appropriate.

pkg/cloudevents/clients/work/store/base.go (1)

29-32: LGTM! Clean separation of concerns.

The HandleReceivedResource method now simply enqueues the work for later processing by handleWork, which determines the appropriate action (add/update/delete) based on the resource state. This aligns with the PR's goal of having handlers determine actions from the resource itself.

pkg/cloudevents/clients/work/store/informer_test.go (2)

545-577: LGTM! Test correctly updated for new API.

The HandleReceivedResource calls are properly updated to use the new signature. The test expectation change from Deleted to Modified is correct—as noted in the comment, HandleReceivedResource with a deletion timestamp calls Update (not Delete), which emits a Modified watch event. This is consistent with how the informer store handles soft deletes.


8-9: Import cleanup is correct.

The types package import was removed since ResourceAction is no longer used in this test file.

pkg/cloudevents/generic/clients/sourceclient_test.go (3)

363-363: Validate signature correctly updated.

The validate function signature properly reflects the removal of the ResourceAction parameter, now taking only the resource.


378-382: Validation logic correctly uses nil checks.

For cases where the handler should not be invoked ("unsupported sub resource" and "no registered codec"), checking resource != nil is the correct approach to verify no handler invocation occurred.

Also applies to: 396-400


426-430: Handler and validation calls properly updated.

The inline handler now correctly accepts only context and resource. The validation call passes the resource directly without the action parameter.

Also applies to: 451-457

pkg/cloudevents/clients/store/informer_test.go (1)

176-199: LGTM! Test correctly demonstrates all resource handling scenarios.

The three HandleReceivedResource calls properly show:

  1. Add (line 176): New resource with just a name
  2. Modify (lines 179-187): Existing resource with updated status
  3. Delete (lines 188-195): Resource with DeletionTimestamp set

The test correctly validates that all three watch event types (Added, Modified, Deleted) are received, confirming the store correctly interprets resource state to determine the appropriate action.

pkg/cloudevents/generic/clients/agentclient_test.go (1)

350-448: LGTM! Test updates correctly reflect the API change.

The test modifications properly align with the removal of ResourceAction from handler signatures. The validation functions now correctly focus on resource-centric checks, and the renamed test case "receive a resource" better describes the new behavior where handlers receive resources without explicit action parameters.

pkg/cloudevents/clients/store/simplestore.go (1)

70-75: Behavioral difference from AgentInformerWatcherStore when handling deleting resources with finalizers.

When a resource is deleting but has finalizers, this implementation returns nil (no-op), while AgentInformerWatcherStore.HandleReceivedResource (in informer.go) updates the stored object with the deletion timestamp, finalizers, and generation.

This may be intentional since SimpleStore doesn't have watchers, but please verify this is the expected behavior. If the store should reflect the deletion state for consistency:

 	if !metaObj.GetDeletionTimestamp().IsZero() {
 		if len(metaObj.GetFinalizers()) != 0 {
-			return nil
+			return s.Update(runtimeObj)
 		}
 		return s.Delete(runtimeObj)
 	}
pkg/cloudevents/clients/store/informer.go (1)

69-89: No type mismatch with meta.Accessor(lastResource) at line 73.

meta.Accessor accepts an arbitrary object pointer, which means it takes interface{} and can work with any type, including T (constrained to generic.ResourceObject). No explicit type assertion or conversion is necessary—the current code is safe and correct. The pattern used here (line 73) appropriately differs from the utils.ToRuntimeObject conversion at lines 51 and 80 because meta.Accessor is explicitly designed to handle arbitrary types.

Likely an incorrect or invalid review comment.

Comment thread pkg/cloudevents/clients/work/store/informer.go
Signed-off-by: Wei Liu <liuweixa@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: 1

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dcd8347 and 2e83789.

📒 Files selected for processing (16)
  • pkg/cloudevents/clients/store/informer.go (1 hunks)
  • pkg/cloudevents/clients/store/informer_test.go (2 hunks)
  • pkg/cloudevents/clients/store/interface.go (1 hunks)
  • pkg/cloudevents/clients/store/simplestore.go (1 hunks)
  • pkg/cloudevents/clients/store/simplestore_test.go (5 hunks)
  • pkg/cloudevents/clients/work/store/base.go (1 hunks)
  • pkg/cloudevents/clients/work/store/informer.go (2 hunks)
  • pkg/cloudevents/clients/work/store/informer_test.go (2 hunks)
  • pkg/cloudevents/generic/clients/agentclient.go (1 hunks)
  • pkg/cloudevents/generic/clients/agentclient_test.go (5 hunks)
  • pkg/cloudevents/generic/clients/clients_metrics_test.go (1 hunks)
  • pkg/cloudevents/generic/clients/sourceclient.go (1 hunks)
  • pkg/cloudevents/generic/clients/sourceclient_test.go (5 hunks)
  • pkg/cloudevents/generic/interface.go (1 hunks)
  • pkg/cloudevents/generic/types/types.go (0 hunks)
  • test/integration/cloudevents/source/client.go (1 hunks)
💤 Files with no reviewable changes (1)
  • pkg/cloudevents/generic/types/types.go
🚧 Files skipped from review as they are similar to previous changes (3)
  • pkg/cloudevents/generic/interface.go
  • pkg/cloudevents/generic/clients/sourceclient.go
  • pkg/cloudevents/clients/work/store/informer_test.go
🧰 Additional context used
🧠 Learnings (2)
📚 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/generic/clients/clients_metrics_test.go
  • pkg/cloudevents/clients/work/store/base.go
  • pkg/cloudevents/generic/clients/agentclient_test.go
  • pkg/cloudevents/clients/store/interface.go
  • test/integration/cloudevents/source/client.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/clients/store/interface.go
🧬 Code graph analysis (6)
pkg/cloudevents/generic/clients/clients_metrics_test.go (1)
pkg/cloudevents/generic/testing/resource.go (1)
  • MockResource (23-31)
pkg/cloudevents/clients/work/store/informer.go (2)
pkg/cloudevents/clients/store/informer.go (1)
  • AgentInformerWatcherStore (21-24)
pkg/cloudevents/clients/utils/utils.go (1)
  • UID (222-225)
pkg/cloudevents/generic/clients/sourceclient_test.go (1)
pkg/cloudevents/generic/testing/resource.go (1)
  • MockResource (23-31)
pkg/cloudevents/generic/clients/agentclient_test.go (1)
pkg/cloudevents/generic/testing/resource.go (1)
  • MockResource (23-31)
pkg/cloudevents/clients/store/informer.go (2)
pkg/cloudevents/clients/work/store/informer.go (1)
  • AgentInformerWatcherStore (91-95)
pkg/cloudevents/clients/utils/utils.go (1)
  • ToRuntimeObject (183-190)
test/integration/cloudevents/source/client.go (1)
test/integration/cloudevents/store/resource.go (1)
  • Resource (18-26)
⏰ 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: integration
  • GitHub Check: verify
🔇 Additional comments (18)
pkg/cloudevents/generic/clients/clients_metrics_test.go (1)

102-105: LGTM!

The callback signature correctly updated to remove the ResourceAction parameter, aligning with the PR's objective of unified resource handling.

pkg/cloudevents/clients/store/interface.go (1)

35-36: LGTM!

The interface signature correctly updated to remove the ResourceAction parameter. All implementations across the codebase appear to have been updated accordingly.

test/integration/cloudevents/source/client.go (1)

39-41: LGTM!

The callback signature correctly updated to remove the ResourceAction parameter while preserving the status update functionality.

pkg/cloudevents/generic/clients/agentclient.go (1)

201-210: LGTM!

The handler invocation correctly simplified to pass only the resource object, removing action-based logic. This aligns with the PR's objective of unified resource handling.

pkg/cloudevents/clients/work/store/informer.go (3)

168-221: LGTM!

The UID-based resource handling logic is well-structured and correctly addresses the past review concern by including an explicit return statement at line 194 after handling the name-change case. The generation checking, deletion handling, and local field preservation all look correct.


223-236: LGTM!

The helper method correctly finds works by UID and returns deep copies to prevent unintended mutations.


238-247: LGTM!

The helper method correctly identifies the work by namespace and name from the provided list.

pkg/cloudevents/clients/store/simplestore_test.go (1)

35-111: LGTM!

The test correctly updated to use watch.EventType and the HandleReceivedResource call properly reflects the new signature without the action parameter. Test coverage remains comprehensive.

pkg/cloudevents/generic/clients/sourceclient_test.go (1)

363-457: LGTM!

The test correctly updated to remove ResourceAction from validation and handler signatures. The validation logic now appropriately focuses on the resource object, with nil checks for non-invocation cases and UID checks for update cases.

pkg/cloudevents/clients/work/store/base.go (1)

29-32: LGTM!

The method correctly simplified to unconditionally enqueue the received work without action-based branching. This aligns with the PR's objective of unified resource handling.

pkg/cloudevents/generic/clients/agentclient_test.go (4)

356-376: LGTM! Test validation simplified correctly.

The validation function signature change from func(event types.ResourceAction, resource *generictesting.MockResource) to func(resource *generictesting.MockResource) aligns with the PR objective of removing ResourceAction. The nil-check logic correctly validates that the handler should not be invoked for unsupported sub-resources.


391-395: Validation logic is consistent.

The same pattern is applied for the "no registered codec" case - checking resource != nil to ensure the handler is not invoked when decoding fails.


398-422: Test case renamed and validation updated appropriately.

The rename from "create a resource" to "receive a resource" better reflects the new semantics where the handler receives a resource without action context. The validation correctly checks the resource UID.


442-447: Handler signature and invocation updated correctly.

The callback now receives only (context.Context, resource) instead of (context.Context, action, resource), and c.validate(actualRes) correctly validates just the resource. This is consistent with the API change.

pkg/cloudevents/clients/store/simplestore.go (1)

51-78: Clean implementation of resource-centric handling.

The logic correctly:

  1. Converts the resource to runtime.Object and extracts metadata
  2. Adds new resources that don't exist in the store
  3. Handles deletion properly - only deletes when DeletionTimestamp is set AND no finalizers remain (lines 70-74)
  4. Updates existing resources otherwise

This follows Kubernetes semantics where a resource with finalizers should be updated (to reflect the deleting state) rather than immediately deleted.

pkg/cloudevents/clients/store/informer_test.go (1)

176-195: Test correctly exercises the new API with all three event types.

The test validates:

  1. Add (line 176): New resource "test0" triggers watch.Added
  2. Update (lines 179-187): Existing "test1" with status change triggers watch.Modified
  3. Delete (lines 188-195): Resource with DeletionTimestamp set and no finalizers triggers watch.Deleted

The test structure properly verifies that the single-path HandleReceivedResource correctly dispatches to Add/Update/Delete internally based on resource state.

pkg/cloudevents/clients/store/informer.go (2)

50-68: Single-path resource handling implemented correctly.

The new implementation correctly:

  1. Converts the resource to runtime.Object and extracts metadata
  2. Checks for existence in the store
  3. Adds new resources directly

This is a clean simplification from the previous action-based dispatch.


88-91: Deletion and update paths are correct.

The logic correctly deletes when DeletionTimestamp is set with no finalizers (line 88), and updates otherwise (line 91).

Comment thread pkg/cloudevents/clients/store/informer.go
@qiujian16

Copy link
Copy Markdown
Member

/approve
/lgtm

@openshift-ci

openshift-ci Bot commented Dec 18, 2025

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: qiujian16, skeeey

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-merge-bot
openshift-merge-bot Bot merged commit 08bb1ca into open-cluster-management-io:main Dec 18, 2025
12 checks passed
@skeeey
skeeey deleted the informer branch December 24, 2025 06:34
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