karmada-io / karmada

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

Introduce a mechanism to scheduler to actively trigger rescheduling #4848

Closed chaosi-zju closed 1 week ago

chaosi-zju commented 2 weeks ago

What type of PR is this?

/kind api-change /kind feature

What this PR does / why we need it:

Introduce a mechanism to scheduler to actively trigger rescheduling

Which issue(s) this PR fixes:

Fixes part of #4840

Special notes for your reviewer:

How to test it:

  1. create a deployment and policy like follows:
resource.yaml ```yaml apiVersion: apps/v1 kind: Deployment metadata: name: demo-test-1 labels: app: test spec: replicas: 3 selector: matchLabels: app: demo-test-1 template: metadata: labels: app: demo-test-1 spec: terminationGracePeriodSeconds: 0 containers: - image: nginx name: demo-test-1 resources: limits: cpu: 10m memory: 10Mi --- apiVersion: policy.karmada.io/v1alpha1 kind: PropagationPolicy metadata: name: default-pp spec: placement: clusterAffinity: clusterNames: - member1 - member2 replicaScheduling: replicaDivisionPreference: Weighted replicaSchedulingType: Divided weightPreference: dynamicWeight: AvailableReplicas resourceSelectors: - apiVersion: apps/v1 kind: Deployment name: demo-test-1 namespace: default ```
  1. when first schedule finished, update schedule result in bingding manually, like:
ka patch rb demo-test-1-deployment --type='json' -p '[{"op": "replace", "path": "/spec/clusters", "value": [{"name": "member2", "replicas": 3}]}]'
  1. add filed spec.rescheduleTriggeredAt binding manually, like:
ka patch rb demo-test-1-deployment --type='json' -p '[{"op": "replace", "path": "/spec/rescheduleTriggeredAt", "value": "2024-04-18T11:38:15Z"}]'

notes that the timestamp value can set to one second later than current status.lastScheduledTime.

  1. check whether reschedule executed by observing whether spec.cluster and status.lastScheduledTime updated.

Does this PR introduce a user-facing change?:

Introduce a mechanism to scheduler to actively trigger rescheduling
codecov-commenter commented 1 week ago

Codecov Report

Attention: Patch coverage is 26.31579% with 56 lines in your changes are missing coverage. Please review.

Project coverage is 52.97%. Comparing base (fdad87e) to head (0372cab). Report is 14 commits behind head on master.

Files Patch % Lines
pkg/scheduler/scheduler.go 10.81% 33 Missing :warning:
pkg/scheduler/core/division_algorithm.go 0.00% 14 Missing :warning:
pkg/scheduler/core/assignment.go 46.15% 5 Missing and 2 partials :warning:
pkg/scheduler/core/common.go 66.66% 1 Missing :warning:
pkg/scheduler/core/generic_scheduler.go 66.66% 1 Missing :warning:

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

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #4848 +/- ## ========================================== - Coverage 53.11% 52.97% -0.15% ========================================== Files 250 250 Lines 20351 20420 +69 ========================================== + Hits 10810 10817 +7 - Misses 8824 8883 +59 - Partials 717 720 +3 ``` | [Flag](https://app.codecov.io/gh/karmada-io/karmada/pull/4848/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/4848/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=karmada-io) | `52.97% <26.31%> (-0.15%)` | :arrow_down: | 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 1 week ago

ready to review, already tested @RainbowMango

RainbowMango commented 1 week ago

I tend to start with the proposal(#4698).

RainbowMango commented 1 week ago

/assign @XiShanYongYe-Chang

RainbowMango commented 1 week ago

/lgtm

@XiShanYongYe-Chang Do you have any further comments?

XiShanYongYe-Chang commented 1 week ago

/LGTM

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: - ~~[OWNERS](https://github.com/karmada-io/karmada/blob/master/OWNERS)~~ [RainbowMango] Approvers can indicate their approval by writing `/approve` in a comment Approvers can cancel approval by writing `/approve cancel` in a comment