support schedule based on cluster taint toleration
Signed-off-by: lihanbo <lihanbo2@huawei.com>
This commit is contained in:
parent
bbcf69f368
commit
483d5d9fa0
|
@ -0,0 +1,16 @@
|
||||||
|
apiVersion: policy.karmada.io/v1alpha1
|
||||||
|
kind: PropagationPolicy
|
||||||
|
metadata:
|
||||||
|
name: nginx-propagation
|
||||||
|
spec:
|
||||||
|
resourceSelectors:
|
||||||
|
- apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
name: nginx
|
||||||
|
placement:
|
||||||
|
clusterAffinity:
|
||||||
|
clusterNames:
|
||||||
|
- member1
|
||||||
|
- member2
|
||||||
|
clusterTolerations:
|
||||||
|
- effect: "NoSchedule"
|
|
@ -3,11 +3,13 @@ package plugins
|
||||||
import (
|
import (
|
||||||
"github.com/karmada-io/karmada/pkg/scheduler/framework"
|
"github.com/karmada-io/karmada/pkg/scheduler/framework"
|
||||||
"github.com/karmada-io/karmada/pkg/scheduler/framework/plugins/clusteraffinity"
|
"github.com/karmada-io/karmada/pkg/scheduler/framework/plugins/clusteraffinity"
|
||||||
|
"github.com/karmada-io/karmada/pkg/scheduler/framework/plugins/tainttoleration"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewPlugins builds all the scheduling plugins.
|
// NewPlugins builds all the scheduling plugins.
|
||||||
func NewPlugins() map[string]framework.Plugin {
|
func NewPlugins() map[string]framework.Plugin {
|
||||||
return map[string]framework.Plugin{
|
return map[string]framework.Plugin{
|
||||||
clusteraffinity.Name: clusteraffinity.New(),
|
clusteraffinity.Name: clusteraffinity.New(),
|
||||||
|
tainttoleration.Name: tainttoleration.New(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
package tainttoleration
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
v1 "k8s.io/api/core/v1"
|
||||||
|
v1helper "k8s.io/kubernetes/pkg/apis/core/v1/helper"
|
||||||
|
|
||||||
|
cluster "github.com/karmada-io/karmada/pkg/apis/cluster/v1alpha1"
|
||||||
|
"github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
|
||||||
|
"github.com/karmada-io/karmada/pkg/scheduler/framework"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Name is the name of the plugin used in the plugin registry and configurations.
|
||||||
|
Name = "TaintToleration"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TaintToleration is a plugin that checks if a propagation policy tolerates a cluster's taints.
|
||||||
|
type TaintToleration struct{}
|
||||||
|
|
||||||
|
var _ framework.FilterPlugin = &TaintToleration{}
|
||||||
|
var _ framework.ScorePlugin = &TaintToleration{}
|
||||||
|
|
||||||
|
// New instantiates the TaintToleration plugin.
|
||||||
|
func New() framework.Plugin {
|
||||||
|
return &TaintToleration{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Name returns the plugin name.
|
||||||
|
func (p *TaintToleration) Name() string {
|
||||||
|
return Name
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filter checks if the propagation policy tolerates a cluster's taints.
|
||||||
|
func (p *TaintToleration) Filter(ctx context.Context, placement *v1alpha1.Placement, cluster *cluster.Cluster) *framework.Result {
|
||||||
|
filterPredicate := func(t *v1.Taint) bool {
|
||||||
|
// only interested in NoSchedule taints.
|
||||||
|
return t.Effect == v1.TaintEffectNoSchedule
|
||||||
|
}
|
||||||
|
|
||||||
|
taint, isUntolerated := v1helper.FindMatchingUntoleratedTaint(cluster.Spec.Taints, placement.ClusterTolerations, filterPredicate)
|
||||||
|
if !isUntolerated {
|
||||||
|
return framework.NewResult(framework.Success)
|
||||||
|
}
|
||||||
|
|
||||||
|
return framework.NewResult(framework.Unschedulable, fmt.Sprintf("cluster had taint {%s: %s}, that the propagation policy didn't tolerate",
|
||||||
|
taint.Key, taint.Value))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Score calculates the score on the candidate cluster.
|
||||||
|
func (p *TaintToleration) Score(ctx context.Context, placement *v1alpha1.Placement, cluster *cluster.Cluster) (float64, *framework.Result) {
|
||||||
|
return 0, framework.NewResult(framework.Success)
|
||||||
|
}
|
|
@ -32,6 +32,7 @@ import (
|
||||||
schedulercache "github.com/karmada-io/karmada/pkg/scheduler/cache"
|
schedulercache "github.com/karmada-io/karmada/pkg/scheduler/cache"
|
||||||
"github.com/karmada-io/karmada/pkg/scheduler/core"
|
"github.com/karmada-io/karmada/pkg/scheduler/core"
|
||||||
"github.com/karmada-io/karmada/pkg/scheduler/framework/plugins/clusteraffinity"
|
"github.com/karmada-io/karmada/pkg/scheduler/framework/plugins/clusteraffinity"
|
||||||
|
"github.com/karmada-io/karmada/pkg/scheduler/framework/plugins/tainttoleration"
|
||||||
"github.com/karmada-io/karmada/pkg/util"
|
"github.com/karmada-io/karmada/pkg/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -106,7 +107,7 @@ func NewScheduler(dynamicClient dynamic.Interface, karmadaClient karmadaclientse
|
||||||
queue := workqueue.NewRateLimitingQueue(workqueue.DefaultControllerRateLimiter())
|
queue := workqueue.NewRateLimitingQueue(workqueue.DefaultControllerRateLimiter())
|
||||||
schedulerCache := schedulercache.NewCache()
|
schedulerCache := schedulercache.NewCache()
|
||||||
// TODO: make plugins as a flag
|
// TODO: make plugins as a flag
|
||||||
algorithm := core.NewGenericScheduler(schedulerCache, policyLister, []string{clusteraffinity.Name})
|
algorithm := core.NewGenericScheduler(schedulerCache, policyLister, []string{clusteraffinity.Name, tainttoleration.Name})
|
||||||
sched := &Scheduler{
|
sched := &Scheduler{
|
||||||
DynamicClient: dynamicClient,
|
DynamicClient: dynamicClient,
|
||||||
KarmadaClient: karmadaClient,
|
KarmadaClient: karmadaClient,
|
||||||
|
|
Loading…
Reference in New Issue