Skip to content

fix(rbg): use structured logging instead of event recorder in Get fai…#137

Merged
Syspretor merged 2 commits intosgl-project:mainfrom
jackyzzy:main
Jan 9, 2026
Merged

fix(rbg): use structured logging instead of event recorder in Get fai…#137
Syspretor merged 2 commits intosgl-project:mainfrom
jackyzzy:main

Conversation

@jackyzzy
Copy link
Copy Markdown
Contributor

@jackyzzy jackyzzy commented Jan 8, 2026

…lure case

This commit fixes an issue where the controller attempted to record an event on a potentially incomplete RBG object when Get() fails.

Changes:

  • Initialize logger at the beginning of Reconcile function
  • Replace event recorder with structured logging when Get fails
  • Use logger.Error() with name and namespace fields for better traceability
  • Optimize logger initialization to avoid duplication
  • Use IsZero() instead of nil check for DeletionTimestamp (linter improvement)

Rationale:
When r.client.Get() fails, the rbg object may be empty or incomplete, lacking necessary metadata (Name, Namespace, UID). Recording an event on such an object could fail or create events that cannot be properly associated with the resource. Using structured logging is more appropriate for this error scenario and aligns with other controllers in the codebase (e.g., RoleBasedGroupSet controller).

🤖 Generated with Claude Code

Ⅰ. Motivation

Ⅱ. Modifications

Ⅲ. Does this pull request fix one issue?

fixes #XXXX

Ⅳ. List the added test cases (unit test/integration test) if any, please explain if no tests are needed.

Ⅴ. Describe how to verify it

VI. Special notes for reviews

Checklist

  • Format your code make fmt.
  • Add unit tests or integration tests.
  • Update the documentation related to the change.

…lure case

This commit fixes an issue where the controller attempted to record
an event on a potentially incomplete RBG object when Get() fails.

Changes:
- Initialize logger at the beginning of Reconcile function
- Replace event recorder with structured logging when Get fails
- Use logger.Error() with name and namespace fields for better traceability
- Optimize logger initialization to avoid duplication
- Use IsZero() instead of nil check for DeletionTimestamp (linter improvement)

Rationale:
When r.client.Get() fails, the rbg object may be empty or incomplete,
lacking necessary metadata (Name, Namespace, UID). Recording an event
on such an object could fail or create events that cannot be properly
associated with the resource. Using structured logging is more
appropriate for this error scenario and aligns with other controllers
in the codebase (e.g., RoleBasedGroupSet controller).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @jackyzzy, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refines the error handling and logging mechanisms within the RoleBasedGroupReconciler. The primary goal is to prevent issues that arise when attempting to record events on potentially incomplete RoleBasedGroup objects during a Get() failure. By transitioning to structured logging in such scenarios, the controller gains improved traceability and aligns with common practices for Kubernetes controllers. Additionally, a minor code style improvement was made for checking DeletionTimestamp.

Highlights

  • Improved Error Logging: Replaced event recording with structured logging for RoleBasedGroup Get() failures, providing more robust error handling when the object might be incomplete.
  • Enhanced Traceability: Error logs now include name and namespace fields, making it easier to trace issues related to specific RoleBasedGroup instances.
  • Optimized Logger Initialization: The logger is now initialized once at the beginning of the Reconcile function, avoiding redundant initialization and improving code clarity.
  • Linter Improvement: Updated the DeletionTimestamp check from nil to IsZero() for better idiomatic Go and consistency.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly replaces the event recorder with structured logging for handling Get failures, which is a more robust approach when the resource object might be incomplete. The change to use IsZero() for DeletionTimestamp checks is also a good improvement. The overall changes enhance the controller's reliability and logging clarity. I have one suggestion to further refine the error logging to differentiate NotFound errors from other failures, which is a common best practice in Kubernetes controllers.

Comment thread internal/controller/workloads/rolebasedgroup_controller.go Outdated
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

- Distinguish between NotFound errors and actual errors (network, permissions)
- Log NotFound as Info level since object might be deleted
- Log actual errors as Error level and return them for retry
- Remove client.IgnoreNotFound() to properly handle different error types

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
@Syspretor
Copy link
Copy Markdown
Collaborator

/lgtm
/approve

@Syspretor Syspretor merged commit a8b1743 into sgl-project:main Jan 9, 2026
6 checks passed
@Syspretor
Copy link
Copy Markdown
Collaborator

@jackyzzy Thanks for this contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants