Skip to content

Optimize the alarm tenant matching mechanism#303

Merged
wanjunlei merged 2 commits into
kubesphere:release-2.6from
wanjunlei:release-2.6
Mar 20, 2026
Merged

Optimize the alarm tenant matching mechanism#303
wanjunlei merged 2 commits into
kubesphere:release-2.6from
wanjunlei:release-2.6

Conversation

@wanjunlei
Copy link
Copy Markdown
Collaborator

No description provided.

Signed-off-by: wanjunlei <wanjunlei@kubesphere.io>
* Escape the special characters

Signed-off-by: wanjunlei <wanjunlei@kubesphere.io>

* Optimize the alarm tenant matching mechanism

Signed-off-by: wanjunlei <wanjunlei@kubesphere.io>

---------

Signed-off-by: wanjunlei <wanjunlei@kubesphere.io>
@wanjunlei wanjunlei merged commit c91ff21 into kubesphere:release-2.6 Mar 20, 2026
4 checks passed
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, 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 significantly optimizes the alarm tenant matching mechanism by introducing explicit rule levels (global, cluster, namespace) into the alert processing pipeline. This allows for more precise routing of alerts based on their defined scope. Additionally, it enhances the robustness of notification templates by escaping potentially problematic values and updates the sidecar's authorization checks for better alignment with Kubernetes resource permissions.

Highlights

  • Enhanced Alarm Tenant Matching: Introduced new constants (RuleLevel, RuleLevelGlobal, RuleLevelCluster, RuleLevelNamespace) and refactored the alert routing logic to leverage these rule levels, enabling more granular and optimized tenant matching for alarms.
  • Improved Template Robustness: Modified alert message templates in config/samples/template.yaml and helm/templates/template.yaml to include an escape function for {{ .Value }}, preventing potential rendering issues with special characters.
  • Updated Sidecar Authorization Logic: Adjusted the sidecar's authorization checks in sidecar/kubesphere/4.0.0/backend.go to use v1/pods resource attributes instead of notification.kubesphere.io/v2beta2/receivenotification, potentially streamlining permission validation.
  • Refined Routing Policies: Removed the RouterPolicyAll constant and introduced RouterOnly in pkg/route/router.go, indicating a shift in how routing policies are defined and applied.
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.

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 optimizes the alarm tenant matching mechanism. It introduces a rule_level to differentiate alerts and groups them for more efficient processing. The logic for fetching tenant receivers is refactored to be more performant and robust, fixing a potential panic. A new RouterOnly policy is added. Additionally, templates are updated for better security by escaping values, and the tenant-finding logic in the sidecar is updated to use a more standard permission check (get pods). The test data has been significantly expanded to cover these new scenarios. The changes appear correct and improve the performance and reliability of the notification routing.

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.

1 participant