operator: avoid unnecessary reconcile
What type of PR is this? /kind cleanup
What this PR does / why we need it: Currently, default values for Karmada CRs are set during the operator’s reconcile loop. This introduces two issues:
-
Unnecessary reconciliation: When a Karmada CR is updated but becomes identical to its previous state after applying defaults, the controller still performs a full reconcile twice—once for the original change and again due to the update caused by setting defaults.
-
Unstable CR status: The operator sets the
Readycondition of the Karmada CR toFalseat the start of each reconcile and updates it toTrueupon successful completion. For example, during initial deployment, the first reconcile succeeds and setsReady=True. However, because the reconcile process itself updates the CR (by filling in default values), it triggers another reconcile, which resetsReady=False, causing flickering in the status. This also causes occasional flakiness in the operator's e2e tests.
To address this, I propose filtering out such "no-op" updates in the UpdateEvent handler—skipping reconciliation if the change is solely due to defaulting and results in no semantic difference.
Note that #6819 would also resolve this problem by moving defaulting logic into an admission controller. Therefore, I’ve left a TODO: once admission-based defaulting is implemented, this workaround can be removed.
Which issue(s) this PR fixes:
Part of #6841
Special notes for your reviewer:
Does this PR introduce a user-facing change?:
Summary of Changes
Hello @zhzhuang-zju, I'm Gemini Code Assist[^1]! 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 optimizes the Karmada operator's reconciliation process by preventing redundant reconciliations triggered solely by the application of default values to Custom Resources. By applying defaults before comparing the old and new states of a CR, the operator can now accurately identify and skip updates that do not introduce semantic changes, thereby improving performance and eliminating the flickering Ready status observed in Karmada CRs.
Highlights
- Prevent Unnecessary Reconciliations: The operator currently performs redundant reconciliations when default values are applied to Karmada Custom Resources (CRs), even if the CR's semantic state remains unchanged. This PR addresses this by filtering out such "no-op" updates.
- Stabilize CR Status: The current defaulting mechanism causes the
Readycondition of Karmada CRs to flicker betweenTrueandFalsedue to repeated reconciliations. This change aims to stabilize the CR status by avoiding these unnecessary updates. - Update Event Filtering Logic: The
onKarmadaUpdatehandler now applies default values to both the old and new objects before performing a deep comparison of theirSpecfields. If the specs are identical after defaulting, the reconciliation is skipped.
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 :thumbsup: and :thumbsdown: 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.
[^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.
cc @jabellard @RainbowMango
:warning: Please install the to ensure uploads and comments are reliably processed by Codecov.
Codecov Report
:x: Patch coverage is 0% with 9 lines in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 46.39%. Comparing base (f26d76a) to head (603e4c9).
:warning: Report is 2 commits behind head on master.
| Files with missing lines | Patch % | Lines |
|---|---|---|
| operator/pkg/controller/karmada/controller.go | 0.00% | 9 Missing :warning: |
| :exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality. |
Additional details and impacted files
@@ Coverage Diff @@
## master #6908 +/- ##
==========================================
+ Coverage 46.37% 46.39% +0.01%
==========================================
Files 698 698
Lines 47763 47767 +4
==========================================
+ Hits 22152 22160 +8
+ Misses 23940 23938 -2
+ Partials 1671 1669 -2
| Flag | Coverage Δ | |
|---|---|---|
| unittests | 46.39% <0.00%> (+0.01%) |
:arrow_up: |
Flags with carried forward coverage won't be shown. Click here to find out more.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
[APPROVALNOTIFIER] This PR is NOT APPROVED
This pull-request has been approved by: Once this PR has been reviewed and has the lgtm label, please ask for approval from rainbowmango. For more information see the Code Review Process.
The full list of commands accepted by this bot can be found here.
Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment