Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add placement for bindingSpec #2702

Merged
merged 1 commit into from
Feb 13, 2023
Merged

Conversation

Poor12
Copy link
Member

@Poor12 Poor12 commented Oct 29, 2022

Signed-off-by: Poor12 shentiecheng@huawei.com

What type of PR is this?
/kind api-change

What this PR does / why we need it:
Add placement for BindingSpec can reduce the dependency of policy and make API more clear. Now the component above will check the placement of bindingSpec first and switch to get placement by label if placement of bindSpec is empty.

It can be smoothly upgraded from a lower version to a higher version. If karmada-controller-manager upgrades, spec.placement will occur according to the placement of policy.

Upgrade path: upgrade crd --> upgrade karmada-controller-manager --> upgrade karmada-scheduler.

Which issue(s) this PR fixes:
Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

Introduced `Placement` to the `ResoureBinding`/`ClusterResourceBinding` API.

@karmada-bot karmada-bot added the kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API label Oct 29, 2022
@karmada-bot karmada-bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Oct 29, 2022
@RainbowMango
Copy link
Member

Now we get placement from annotations of Binding, add toleration for bindingSpec so that taintManager do not need to query pp.

Please explain it in more detail. Who is we? Please show the code where this change would benefit.

@codecov-commenter
Copy link

codecov-commenter commented Oct 29, 2022

Codecov Report

Merging #2702 (5eff625) into master (69ecff6) will increase coverage by 0.36%.
The diff coverage is 0.00%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##           master    #2702      +/-   ##
==========================================
+ Coverage   47.98%   48.35%   +0.36%     
==========================================
  Files         200      201       +1     
  Lines       18082    18070      -12     
==========================================
+ Hits         8677     8738      +61     
+ Misses       8924     8847      -77     
- Partials      481      485       +4     
Flag Coverage Δ
unittests 48.35% <0.00%> (+0.36%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pkg/detector/detector.go 0.00% <0.00%> (ø)
pkg/scheduler/core/generic_scheduler.go 0.00% <0.00%> (ø)
pkg/scheduler/event_handler.go 28.17% <0.00%> (+4.16%) ⬆️
pkg/scheduler/scheduler.go 18.51% <0.00%> (+0.41%) ⬆️
...einterpreter/defaultinterpreter/aggregatestatus.go 71.02% <0.00%> (-0.52%) ⬇️
pkg/karmadactl/util/idempotency.go 23.07% <0.00%> (ø)
pkg/karmadactl/cmdinit/karmada/deploy.go 0.00% <0.00%> (ø)
pkg/karmadactl/cmdinit/cmdinit.go 72.36% <0.00%> (ø)
pkg/search/proxy/store/util.go 93.36% <0.00%> (+0.47%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@chaunceyjiang
Copy link
Member

// needEviction returns whether the binding should be evicted from target cluster right now.
// If a toleration time is found, we return false along with a minimum toleration time as the
// second return value.
func (tc *NoExecuteTaintManager) needEviction(clusterName string, appliedPlacement map[string]string) (bool, time.Duration, error) {
placement, err := helper.GetAppliedPlacement(appliedPlacement)
if err != nil {
return false, -1, err
}
cluster := &clusterv1alpha1.Cluster{}
if err = tc.Client.Get(context.TODO(), types.NamespacedName{Name: clusterName}, cluster); err != nil {
// The resource may no longer exist, in which case we stop processing.
if apierrors.IsNotFound(err) {
return false, -1, nil
}
return false, -1, err
}
taints := helper.GetNoExecuteTaints(cluster.Spec.Taints)
if len(taints) == 0 {
return false, -1, nil
}
tolerations := placement.ClusterTolerations
allTolerated, usedTolerations := helper.GetMatchingTolerations(taints, tolerations)
if !allTolerated {
return true, 0, nil
}
return false, helper.GetMinTolerationTime(taints, usedTolerations), nil

Are you trying to optimize this piece of code?

@Poor12
Copy link
Member Author

Poor12 commented Oct 31, 2022

// needEviction returns whether the binding should be evicted from target cluster right now.
// If a toleration time is found, we return false along with a minimum toleration time as the
// second return value.
func (tc *NoExecuteTaintManager) needEviction(clusterName string, appliedPlacement map[string]string) (bool, time.Duration, error) {
placement, err := helper.GetAppliedPlacement(appliedPlacement)
if err != nil {
return false, -1, err
}
cluster := &clusterv1alpha1.Cluster{}
if err = tc.Client.Get(context.TODO(), types.NamespacedName{Name: clusterName}, cluster); err != nil {
// The resource may no longer exist, in which case we stop processing.
if apierrors.IsNotFound(err) {
return false, -1, nil
}
return false, -1, err
}
taints := helper.GetNoExecuteTaints(cluster.Spec.Taints)
if len(taints) == 0 {
return false, -1, nil
}
tolerations := placement.ClusterTolerations
allTolerated, usedTolerations := helper.GetMatchingTolerations(taints, tolerations)
if !allTolerated {
return true, 0, nil
}
return false, helper.GetMinTolerationTime(taints, usedTolerations), nil

Are you trying to optimize this piece of code?

Not quite. Mainly to make calls simpler and make the API clearer.

@karmada-bot karmada-bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 2, 2022
@karmada-bot karmada-bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 2, 2022
@Poor12 Poor12 changed the title Add toleration for bindingSpec Add placement for bindingSpec Nov 2, 2022
@Poor12 Poor12 force-pushed the add-toleration branch 2 times, most recently from dc142e0 to 4d8d154 Compare November 3, 2022 01:49
@Poor12 Poor12 force-pushed the add-toleration branch 2 times, most recently from 5eddfc3 to 632b94b Compare November 4, 2022 07:46
@Poor12
Copy link
Member Author

Poor12 commented Nov 4, 2022

/cc @RainbowMango

@RainbowMango
Copy link
Member

Please add an agenda to next week's community meeting for public comment.

@RainbowMango RainbowMango added this to the v1.5 milestone Feb 4, 2023
@XiShanYongYe-Chang
Copy link
Member

Let me take a review.
/assign

@karmada-bot karmada-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Feb 6, 2023
@RainbowMango
Copy link
Member

Please fix the CI.

@karmada-bot karmada-bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Feb 9, 2023
@karmada-bot karmada-bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Feb 9, 2023
@RainbowMango
Copy link
Member

/assign

@Garrybest
Copy link
Member

This PR could help #2968 for determining whether a binding is divided scheduling easily.

@@ -273,20 +167,19 @@ func (s *Scheduler) updateCluster(oldObj, newObj interface{}) {
case !equality.Semantic.DeepEqual(oldCluster.Labels, newCluster.Labels):
fallthrough
case !equality.Semantic.DeepEqual(oldCluster.Spec, newCluster.Spec):
s.enqueueAffectedPolicy(oldCluster, newCluster)
s.enqueueAffectedClusterPolicy(oldCluster, newCluster)
s.enqueueAffectedBindings(oldCluster, newCluster)
Copy link
Member

Choose a reason for hiding this comment

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

Only the RB is processed. The CRB is not processed.

Copy link
Member Author

Choose a reason for hiding this comment

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

enqueueAffectedBindings alse enqueues the affected CRBs.

pkg/scheduler/scheduler.go Show resolved Hide resolved
pkg/scheduler/scheduler.go Show resolved Hide resolved
pkg/scheduler/scheduler.go Outdated Show resolved Hide resolved
Signed-off-by: Poor12 <shentiecheng@huawei.com>
Copy link
Member

@XiShanYongYe-Chang XiShanYongYe-Chang left a comment

Choose a reason for hiding this comment

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

Good job~
/lgtm

@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label Feb 13, 2023
Copy link
Member

@RainbowMango RainbowMango left a comment

Choose a reason for hiding this comment

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

/approve

@@ -19,7 +19,7 @@ import (

// ScheduleAlgorithm is the interface that should be implemented to schedule a resource to the target clusters.
type ScheduleAlgorithm interface {
Schedule(context.Context, *policyv1alpha1.Placement, *workv1alpha2.ResourceBindingSpec, *ScheduleAlgorithmOption) (scheduleResult ScheduleResult, err error)
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if we need to add this parameter back when implementing #3126, but it makes sense for this PR to do it.

@karmada-bot
Copy link
Collaborator

[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:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@karmada-bot karmada-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 13, 2023
@karmada-bot karmada-bot merged commit b36bc65 into karmada-io:master Feb 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API lgtm Indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants