Skip to content

use Patch-based event dedup in EmitNodeWarningEvent - #2569

Closed
jianzhangbjz wants to merge 1 commit into
Project-HAMi:masterfrom
jianzhangbjz:fix-events-update-permission
Closed

use Patch-based event dedup in EmitNodeWarningEvent#2569
jianzhangbjz wants to merge 1 commit into
Project-HAMi:masterfrom
jianzhangbjz:fix-events-update-permission

Conversation

@jianzhangbjz

@jianzhangbjz jianzhangbjz commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?

/kind bug

What this PR does / why we need it:
Replace Events().Update() with Events().Patch() in EmitNodeWarningEvent to fix an RBAC permission violation. The scheduler ClusterRole only grants create, get, list on events — calling Update() requires the update verb which wasn't granted.
The previous attempt removed client-side event dedup entirely, but that would create duplicate events on repeated calls since the API server does not deduplicate by involvedObject+reason. Instead, this uses Patch to update the count and timestamp of matching events, and adds patch to the events verbs in the scheduler ClusterRole.

Which issue(s) this PR fixes:
Fixes #

Special notes for your reviewer:
Discovered by the rbaccheck Go AST tool(#2567) that flags RBAC permission violations at CI time.

Does this PR introduce a user-facing change?:
No — events are still emitted, just without client-side deduplication. The API server handles deduplication automatically.

This PR was written primarily by Claude Code.

Summary by CodeRabbit

  • Bug Fixes
    • Improved GPU warning event handling to reliably update matching events and avoid duplicate notifications.
    • Added safeguards for unavailable event clients.
    • Ensured event permissions support updating existing warnings.
  • Maintenance
    • Simplified warning event tracking by removing time-based deduplication.

@hami-robot hami-robot Bot added kind/bug Something isn't working dco-signoff: yes labels Aug 11, 2026
@hami-robot
hami-robot Bot requested review from mesutoezdil and wawa0210 August 11, 2026 06:26
@hami-robot

hami-robot Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: jianzhangbjz
Once this PR has been reviewed and has the lgtm label, please assign wawa0210 for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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

@github-actions github-actions Bot added kind/enhancement New feature or request and removed kind/bug Something isn't working labels Aug 11, 2026
@hami-robot hami-robot Bot added the size/L label Aug 11, 2026
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 03b24994-f6b2-4ea3-a47d-629ec3033ac0

📥 Commits

Reviewing files that changed from the base of the PR and between f5d9aa5 and 27e8958.

📒 Files selected for processing (2)
  • charts/hami/templates/device-plugin/monitorrole.yaml
  • pkg/util/util_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/util/util_test.go

📝 Walkthrough

Walkthrough

EmitNodeWarningEvent no longer uses a time-based deduplication window. It patches the latest matching event, updates the GPU P2P caller, grants patch permission, and revises test coverage.

Changes

Warning event flow

Layer / File(s) Summary
Warning event deduplication
pkg/util/util.go, pkg/util/util_test.go
EmitNodeWarningEvent now accepts three arguments, finds events by node name and reason, filters by UID, and patches the latest match. Tests cover nil clients, creation, UID filtering, and patching.
Event API integration
pkg/device-plugin/nvidiadevice/nvinternal/plugin/register.go, charts/hami/templates/device-plugin/monitorrole.yaml
The asymmetric GPU P2P caller uses the updated API. The monitor role can patch Kubernetes events.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested labels: enhancement

Suggested reviewers: archlitchi, wawa0210

Poem

A rabbit watched the warning glow,
No time window guides its flow.
It patches events with careful grace,
Keeps the latest count in place.
GPU links now speak just right.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change to use patch-based event deduplication in EmitNodeWarningEvent.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@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.

Caution

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

⚠️ Outside diff range comments (1)
pkg/util/util.go (1)

285-297: 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

Add event correlation before creating node warning events.

GenerateName plus Events(...).Create(...) creates a new Event for each successful call. This path does not invoke client-go’s EventCorrelator, which performs client-side filtering, aggregation, and count updates. Repeated registration can therefore produce repeated warning Events. Remove the API-server deduplication claim, or add local rate limiting or correlation with the required update permissions.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/util/util.go` around lines 285 - 297, Update EmitNodeWarningEvent to stop
claiming that the API server automatically deduplicates these events, and add
local event correlation or rate limiting before creating warning Events so
repeated calls are aggregated or suppressed. Ensure any correlation path can
update existing Events with the required permissions while preserving the
current client and timeout handling.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@pkg/util/util.go`:
- Around line 285-297: Update EmitNodeWarningEvent to stop claiming that the API
server automatically deduplicates these events, and add local event correlation
or rate limiting before creating warning Events so repeated calls are aggregated
or suppressed. Ensure any correlation path can update existing Events with the
required permissions while preserving the current client and timeout handling.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d6c46aef-822e-40fe-8119-0964df235e3b

📥 Commits

Reviewing files that changed from the base of the PR and between 634bf2b and 87ac7b5.

📒 Files selected for processing (3)
  • pkg/device-plugin/nvidiadevice/nvinternal/plugin/register.go
  • pkg/util/util.go
  • pkg/util/util_test.go

@mesutoezdil

Copy link
Copy Markdown
Contributor

This is being closed because it does not comply with the contribution guidelines.

@jianzhangbjz

Copy link
Copy Markdown
Contributor Author

/reopen

@hami-robot

hami-robot Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

@jianzhangbjz: Failed to re-open PR: state cannot be changed. The fix-events-update-permission branch was force-pushed or recreated.

Details

In response to this:

/reopen

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@jianzhangbjz

Copy link
Copy Markdown
Contributor Author

Hi @mesutoezdil , I've updated it. Could you help have a review? Thanks!

@jianzhangbjz

Copy link
Copy Markdown
Contributor Author

/reopen

@hami-robot hami-robot Bot reopened this Aug 11, 2026
@hami-robot

hami-robot Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

@jianzhangbjz: Reopened this PR.

Details

In response to this:

/reopen

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@jianzhangbjz
jianzhangbjz force-pushed the fix-events-update-permission branch from 87ac7b5 to daeeed8 Compare August 11, 2026 08:02

@mesutoezdil mesutoezdil left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

left two questions inline.

Comment thread pkg/util/util.go Outdated
// EmitNodeWarningEvent emits a Warning event on the given Node with deduplication.
func EmitNodeWarningEvent(node *corev1.Node, reason, message string, dedupWindow time.Duration) {
// EmitNodeWarningEvent emits a Warning event on the given Node.
// The Kubernetes API server handles event deduplication automatically

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is this true for a plain create with generatename? each call makes a new object, no shared name to merge on. if this fires every cycle on a stuck node, will it spam many duplicate events instead of one counted event?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You're right! However, it doesn't trigger every 30-second cycle; it only triggers when an anomaly is first detected in the GPU topology state. Anyway, let me make a more secure solution.

"One or more GPU pairs on this node have asymmetric P2P link data; "+
"affected pairs scored 0 (possible NVLink hardware or driver issue)",
time.Hour)
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

stray comma and closing paren on its own line here. gofmt would not leave it like this.

@codecov

codecov Bot commented Aug 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 40.00000% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/util/util.go 50.00% 1 Missing and 1 partial ⚠️
...-plugin/nvidiadevice/nvinternal/plugin/register.go 0.00% 1 Missing ⚠️
Flag Coverage Δ
unittests 62.31% <40.00%> (-1.90%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...-plugin/nvidiadevice/nvinternal/plugin/register.go 19.71% <0.00%> (-5.14%) ⬇️
pkg/util/util.go 71.56% <50.00%> (-1.74%) ⬇️

... and 36 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@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: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@charts/hami/templates/scheduler/clusterrole.yaml`:
- Line 20: Update the device-plugin monitor ClusterRole’s events rule to include
the patch verb alongside its existing permissions. Do not change the scheduler
ClusterRole, since it is bound only to the scheduler service account.

In `@pkg/util/util_test.go`:
- Line 790: Update both tests around the client.KubeClient assignments to save
the existing client value before replacing it, then register t.Cleanup to
restore that value after each test. Ensure cleanup is applied independently to
both tests so package-global client state cannot leak between tests.
- Around line 823-846: Update the test around EmitNodeWarningEvent to assert the
decoy event Create succeeds, expect two events from the unfiltered List, and
locate the event whose InvolvedObject.UID matches nodeUID before asserting its
Count and Message. Keep the decoy event present so the test verifies UID-based
deduplication.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b8c9c724-0c8d-4046-ad74-3d0c47748553

📥 Commits

Reviewing files that changed from the base of the PR and between 87ac7b5 and f5d9aa5.

📒 Files selected for processing (4)
  • charts/hami/templates/scheduler/clusterrole.yaml
  • pkg/device-plugin/nvidiadevice/nvinternal/plugin/register.go
  • pkg/util/util.go
  • pkg/util/util_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • pkg/device-plugin/nvidiadevice/nvinternal/plugin/register.go
  • pkg/util/util.go

Comment thread charts/hami/templates/scheduler/clusterrole.yaml Outdated
Comment thread pkg/util/util_test.go
Comment thread pkg/util/util_test.go Outdated
@jianzhangbjz jianzhangbjz changed the title refactor: remove client-side event deduplication in EmitNodeWarningEvent use Patch-based event dedup in EmitNodeWarningEvent Aug 11, 2026
@github-actions github-actions Bot removed the kind/enhancement New feature or request label Aug 11, 2026
counts, which only needs the "patch" verb.

Signed-off-by: Jian Zhang <jiazha666@gmail.com>
@jianzhangbjz
jianzhangbjz force-pushed the fix-events-update-permission branch from f5d9aa5 to 27e8958 Compare August 11, 2026 09:00
@jianzhangbjz

Copy link
Copy Markdown
Contributor Author

Hi @mesutoezdil , I added the patch permission as a new solution. Could you help have a review? Thanks!

- list
- create
- update
- patch

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

emitnodewarningevent has exactly one caller, register.go, which runs under this exact role. this role already had update on events before this pr. so the original update() call was never actually forbidden, rbaccheck flagged it against the scheduler clusterrole instead, which never calls this function at all. does that mean the real bug here was never an rbac violation, just rbaccheck checking the wrong role file?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, correct. Thanks! I've updated #2567 to avoid this kind of false alarm. Closed it.

@jianzhangbjz

Copy link
Copy Markdown
Contributor Author

/close as not a bug

@jianzhangbjz

Copy link
Copy Markdown
Contributor Author

/close

@hami-robot hami-robot Bot closed this Aug 13, 2026
@hami-robot

hami-robot Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

@jianzhangbjz: Closed this PR.

Details

In response to this:

/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@jianzhangbjz
jianzhangbjz deleted the fix-events-update-permission branch August 13, 2026 02:56
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