add toleration match in rescheduling
Signed-off-by: changzhen <changzhen5@huawei.com>
This commit is contained in:
parent
7a35aa069d
commit
db441697e8
|
@ -19,6 +19,7 @@ import (
|
||||||
"k8s.io/client-go/tools/cache"
|
"k8s.io/client-go/tools/cache"
|
||||||
"k8s.io/client-go/util/workqueue"
|
"k8s.io/client-go/util/workqueue"
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
|
v1helper "k8s.io/kubernetes/pkg/apis/core/v1/helper"
|
||||||
|
|
||||||
clusterv1alpha1 "github.com/karmada-io/karmada/pkg/apis/cluster/v1alpha1"
|
clusterv1alpha1 "github.com/karmada-io/karmada/pkg/apis/cluster/v1alpha1"
|
||||||
policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
|
policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
|
||||||
|
@ -729,12 +730,14 @@ func (s *Scheduler) rescheduleResourceBinding(resourceBinding *workv1alpha1.Reso
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func calcReservedCluster(total, ready sets.String) sets.String {
|
// calcReservedCluster eliminates the not-ready clusters from the 'bindClusters'.
|
||||||
return total.Difference(total.Difference(ready))
|
func calcReservedCluster(bindClusters, readyClusters sets.String) sets.String {
|
||||||
|
return bindClusters.Difference(bindClusters.Difference(readyClusters))
|
||||||
}
|
}
|
||||||
|
|
||||||
func calcAvailableCluster(total, ready sets.String) sets.String {
|
// calcAvailableCluster returns a list of ready clusters that not in 'bindClusters'.
|
||||||
return ready.Difference(total)
|
func calcAvailableCluster(bindCluster, readyClusters sets.String) sets.String {
|
||||||
|
return readyClusters.Difference(bindCluster)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Scheduler) obtainTargetCluster(bindingClusters []workv1alpha1.TargetCluster, placement policyv1alpha1.Placement) (sets.String, error) {
|
func (s *Scheduler) obtainTargetCluster(bindingClusters []workv1alpha1.TargetCluster, placement policyv1alpha1.Placement) (sets.String, error) {
|
||||||
|
@ -744,20 +747,27 @@ func (s *Scheduler) obtainTargetCluster(bindingClusters []workv1alpha1.TargetClu
|
||||||
reservedClusters := calcReservedCluster(totalClusters, readyClusters)
|
reservedClusters := calcReservedCluster(totalClusters, readyClusters)
|
||||||
availableClusters := calcAvailableCluster(totalClusters, readyClusters)
|
availableClusters := calcAvailableCluster(totalClusters, readyClusters)
|
||||||
|
|
||||||
candidateClusters := sets.NewString()
|
filterPredicate := func(t *corev1.Taint) bool {
|
||||||
if placement.ClusterAffinity == nil {
|
// now only interested in NoSchedule taint which means do not allow new resource to schedule onto the cluster unless they tolerate the taint
|
||||||
candidateClusters.Insert(availableClusters.List()...)
|
// todo: supprot NoExecute taint
|
||||||
} else {
|
return t.Effect == corev1.TaintEffectNoSchedule
|
||||||
for clusterName := range availableClusters {
|
}
|
||||||
clusterObj, err := s.clusterLister.Get(clusterName)
|
|
||||||
if err != nil {
|
|
||||||
klog.Errorf("Failed to get clusterObj by clusterName: %s", clusterName)
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if util.ClusterMatches(clusterObj, *placement.ClusterAffinity) {
|
candidateClusters := sets.NewString()
|
||||||
candidateClusters.Insert(clusterName)
|
for clusterName := range availableClusters {
|
||||||
}
|
clusterObj, err := s.clusterLister.Get(clusterName)
|
||||||
|
if err != nil {
|
||||||
|
klog.Errorf("Failed to get clusterObj by clusterName: %s", clusterName)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if placement.ClusterAffinity != nil && !util.ClusterMatches(clusterObj, *placement.ClusterAffinity) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
_, isUntolerated := v1helper.FindMatchingUntoleratedTaint(clusterObj.Spec.Taints, placement.ClusterTolerations, filterPredicate)
|
||||||
|
if !isUntolerated {
|
||||||
|
candidateClusters.Insert(clusterName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue