karmada-io / karmada

Open, Multi-Cloud, Multi-Cluster Kubernetes Orchestration
https://karmada.io
Apache License 2.0
4.14k stars 811 forks source link

fix patching WorkloadRebalancer failed due to misuse of shared slices #4875

Closed chaosi-zju closed 1 week ago

chaosi-zju commented 2 weeks ago

What type of PR is this?

/kind bug

What this PR does / why we need it:

fix patching WorkloadRebalancer failed due to misuse of shared slices.

in previous code:

// get previous status and update basing on it
newStatus = rebalancer.Status
if len(newStatus.ObservedWorkloads) == 0 {
    newStatus = c.buildWorkloadRebalancerStatus(rebalancer)
}

actually newStatus and rebalancer.Status shared the slice of rebalancer.Status.ObservedWorkloads.

if this slice didn't change from nil to non-nil or occurs expansion, modification to newStatus will also be applied to the rebalancer.Status, which will lead to patch status failed.

Which issue(s) this PR fixes:

Fixes part of #4840

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

chaosi-zju commented 2 weeks ago

@XiShanYongYe-Chang @RainbowMango

Hello, sorry for this bug, please help review once more.

In previous code:

// get previous status and update basing on it
newStatus = rebalancer.Status
if len(newStatus.ObservedWorkloads) == 0 {
    newStatus = c.buildWorkloadRebalancerStatus(rebalancer)
}

Actually newStatus and rebalancer.Status shared the slice of rebalancer.Status.ObservedWorkloads.

If this slice didn't change from nil to non-nil or occurs expansion, modification to newStatus will also be applied to the rebalancer.Status, which will lead to patch status ignored.

codecov-commenter commented 2 weeks ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 53.06%. Comparing base (6e5a602) to head (f672ffa). Report is 20 commits behind head on master.

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #4875 +/- ## ========================================== + Coverage 52.98% 53.06% +0.08% ========================================== Files 250 251 +1 Lines 20421 20387 -34 ========================================== - Hits 10820 10819 -1 + Misses 8881 8854 -27 + Partials 720 714 -6 ``` | [Flag](https://app.codecov.io/gh/karmada-io/karmada/pull/4875/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=karmada-io) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/karmada-io/karmada/pull/4875/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=karmada-io) | `53.06% <ø> (+0.08%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=karmada-io#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

chaosi-zju commented 2 weeks ago

Is there any further comments? If any other suggestions, please let me know.

RainbowMango commented 2 weeks ago

@XiShanYongYe-Chang If you want to get approval from someone else, you can cc or assign.

/assign

XiShanYongYe-Chang commented 2 weeks ago

If you want to get approval from someone else, you can cc or assign.

Got it.

RainbowMango commented 2 weeks ago

modification to newStatus will also be applied to the rebalancer.Status, which will lead to patch status failed.

Won't lead to patch failed, but non-ops, right? That means the patch will be ignored.

chaosi-zju commented 2 weeks ago

Won't lead to patch failed, but non-ops, right? That means the patch will be ignored.

yes, the patch will be ignored.

karmada-bot commented 1 week ago

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: RainbowMango

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files: - ~~[pkg/controllers/OWNERS](https://github.com/karmada-io/karmada/blob/master/pkg/controllers/OWNERS)~~ [RainbowMango] Approvers can indicate their approval by writing `/approve` in a comment Approvers can cancel approval by writing `/approve cancel` in a comment
RainbowMango commented 1 week ago

What's the next PR blocked by this?

chaosi-zju commented 1 week ago

What's the next PR blocked by this?

4860

chaosi-zju commented 1 week ago

What's the next PR blocked by this?

or #4876 if you prefer

RainbowMango commented 1 week ago

I can review them but please also ask for review from controller owners.

chaosi-zju commented 1 week ago

I can review them but please also ask for review from controller owners.

ok