mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 03:11:40 +00:00
scheduler: make algorithm source an option
Changes scheduler.New so that algorithm source is moved from the parameter to an option. The default algorithm source is source with the DefaultProvider.
This commit is contained in:
parent
fb87f72b88
commit
6350095d3c
@ -189,9 +189,9 @@ func Run(ctx context.Context, cc schedulerserverconfig.CompletedConfig, outOfTre
|
||||
cc.InformerFactory,
|
||||
cc.PodInformer,
|
||||
cc.Recorder,
|
||||
cc.ComponentConfig.AlgorithmSource,
|
||||
ctx.Done(),
|
||||
scheduler.WithName(cc.ComponentConfig.SchedulerName),
|
||||
scheduler.WithAlgorithmSource(cc.ComponentConfig.AlgorithmSource),
|
||||
scheduler.WithHardPodAffinitySymmetricWeight(cc.ComponentConfig.HardPodAffinitySymmetricWeight),
|
||||
scheduler.WithPreemptionDisabled(cc.ComponentConfig.DisablePreemption),
|
||||
scheduler.WithPercentageOfNodesToScore(cc.ComponentConfig.PercentageOfNodesToScore),
|
||||
|
@ -1263,8 +1263,8 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
|
||||
informerFactory,
|
||||
informerFactory.Core().V1().Pods(),
|
||||
nil,
|
||||
algorithmSrc,
|
||||
make(chan struct{}),
|
||||
scheduler.WithAlgorithmSource(algorithmSrc),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
|
@ -132,6 +132,7 @@ func (sched *Scheduler) Cache() internalcache.Cache {
|
||||
|
||||
type schedulerOptions struct {
|
||||
schedulerName string
|
||||
schedulerAlgorithmSource schedulerapi.SchedulerAlgorithmSource
|
||||
hardPodAffinitySymmetricWeight int32
|
||||
disablePreemption bool
|
||||
percentageOfNodesToScore int32
|
||||
@ -157,6 +158,13 @@ func WithName(schedulerName string) Option {
|
||||
}
|
||||
}
|
||||
|
||||
// WithAlgorithmSource sets schedulerAlgorithmSource for Scheduler, the default is a source with DefaultProvider.
|
||||
func WithAlgorithmSource(source schedulerapi.SchedulerAlgorithmSource) Option {
|
||||
return func(o *schedulerOptions) {
|
||||
o.schedulerAlgorithmSource = source
|
||||
}
|
||||
}
|
||||
|
||||
// WithHardPodAffinitySymmetricWeight sets hardPodAffinitySymmetricWeight for Scheduler, the default value is 1
|
||||
func WithHardPodAffinitySymmetricWeight(hardPodAffinitySymmetricWeight int32) Option {
|
||||
return func(o *schedulerOptions) {
|
||||
@ -236,7 +244,10 @@ func WithPodMaxBackoffSeconds(podMaxBackoffSeconds int64) Option {
|
||||
}
|
||||
|
||||
var defaultSchedulerOptions = schedulerOptions{
|
||||
schedulerName: v1.DefaultSchedulerName,
|
||||
schedulerName: v1.DefaultSchedulerName,
|
||||
schedulerAlgorithmSource: schedulerapi.SchedulerAlgorithmSource{
|
||||
Provider: defaultAlgorithmSourceProviderName(),
|
||||
},
|
||||
hardPodAffinitySymmetricWeight: v1.DefaultHardPodAffinitySymmetricWeight,
|
||||
disablePreemption: false,
|
||||
percentageOfNodesToScore: schedulerapi.DefaultPercentageOfNodesToScore,
|
||||
@ -260,7 +271,6 @@ func New(client clientset.Interface,
|
||||
informerFactory informers.SharedInformerFactory,
|
||||
podInformer coreinformers.PodInformer,
|
||||
recorder events.EventRecorder,
|
||||
schedulerAlgorithmSource schedulerapi.SchedulerAlgorithmSource,
|
||||
stopCh <-chan struct{},
|
||||
opts ...Option) (*Scheduler, error) {
|
||||
|
||||
@ -326,7 +336,7 @@ func New(client clientset.Interface,
|
||||
PluginConfig: options.frameworkPluginConfig,
|
||||
})
|
||||
var sched *Scheduler
|
||||
source := schedulerAlgorithmSource
|
||||
source := options.schedulerAlgorithmSource
|
||||
switch {
|
||||
case source.Provider != nil:
|
||||
// Create the config from a named algorithm provider.
|
||||
@ -788,3 +798,8 @@ func (p *podPreemptorImpl) removeNominatedNodeName(pod *v1.Pod) error {
|
||||
}
|
||||
return p.setNominatedNodeName(pod, "")
|
||||
}
|
||||
|
||||
func defaultAlgorithmSourceProviderName() *string {
|
||||
provider := schedulerapi.SchedulerDefaultProviderName
|
||||
return &provider
|
||||
}
|
||||
|
@ -192,8 +192,8 @@ func TestSchedulerCreation(t *testing.T) {
|
||||
informerFactory,
|
||||
NewPodInformer(client, 0),
|
||||
eventBroadcaster.NewRecorder(scheme.Scheme, "scheduler"),
|
||||
schedulerapi.SchedulerAlgorithmSource{Provider: &testSource},
|
||||
stopCh,
|
||||
WithAlgorithmSource(schedulerapi.SchedulerAlgorithmSource{Provider: &testSource}),
|
||||
WithPodInitialBackoffSeconds(1),
|
||||
WithPodMaxBackoffSeconds(10),
|
||||
)
|
||||
|
@ -21,7 +21,6 @@ go_test(
|
||||
"//pkg/controller/daemon:go_default_library",
|
||||
"//pkg/scheduler:go_default_library",
|
||||
"//pkg/scheduler/algorithmprovider:go_default_library",
|
||||
"//pkg/scheduler/apis/config:go_default_library",
|
||||
"//pkg/util/labels:go_default_library",
|
||||
"//staging/src/k8s.io/api/apps/v1:go_default_library",
|
||||
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
||||
|
@ -47,7 +47,6 @@ import (
|
||||
"k8s.io/kubernetes/pkg/controller/daemon"
|
||||
"k8s.io/kubernetes/pkg/scheduler"
|
||||
"k8s.io/kubernetes/pkg/scheduler/algorithmprovider"
|
||||
schedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
|
||||
labelsutil "k8s.io/kubernetes/pkg/util/labels"
|
||||
"k8s.io/kubernetes/test/integration/framework"
|
||||
)
|
||||
@ -93,8 +92,6 @@ func setupScheduler(
|
||||
Interface: cs.EventsV1beta1().Events(""),
|
||||
})
|
||||
|
||||
defaultProviderName := schedulerconfig.SchedulerDefaultProviderName
|
||||
|
||||
sched, err := scheduler.New(
|
||||
cs,
|
||||
informerFactory,
|
||||
@ -103,9 +100,6 @@ func setupScheduler(
|
||||
legacyscheme.Scheme,
|
||||
v1.DefaultSchedulerName,
|
||||
),
|
||||
schedulerconfig.SchedulerAlgorithmSource{
|
||||
Provider: &defaultProviderName,
|
||||
},
|
||||
ctx.Done(),
|
||||
)
|
||||
if err != nil {
|
||||
|
@ -272,16 +272,16 @@ priorities: []
|
||||
informerFactory,
|
||||
scheduler.NewPodInformer(clientSet, 0),
|
||||
eventBroadcaster.NewRecorder(legacyscheme.Scheme, v1.DefaultSchedulerName),
|
||||
kubeschedulerconfig.SchedulerAlgorithmSource{
|
||||
nil,
|
||||
scheduler.WithName(v1.DefaultSchedulerName),
|
||||
scheduler.WithAlgorithmSource(kubeschedulerconfig.SchedulerAlgorithmSource{
|
||||
Policy: &kubeschedulerconfig.SchedulerPolicySource{
|
||||
ConfigMap: &kubeschedulerconfig.SchedulerPolicyConfigMapSource{
|
||||
Namespace: policyConfigMap.Namespace,
|
||||
Name: policyConfigMap.Name,
|
||||
},
|
||||
},
|
||||
},
|
||||
nil,
|
||||
scheduler.WithName(v1.DefaultSchedulerName),
|
||||
}),
|
||||
scheduler.WithHardPodAffinitySymmetricWeight(v1.DefaultHardPodAffinitySymmetricWeight),
|
||||
scheduler.WithBindTimeoutSeconds(defaultBindTimeout),
|
||||
)
|
||||
@ -335,16 +335,16 @@ func TestSchedulerCreationFromNonExistentConfigMap(t *testing.T) {
|
||||
informerFactory,
|
||||
scheduler.NewPodInformer(clientSet, 0),
|
||||
eventBroadcaster.NewRecorder(legacyscheme.Scheme, v1.DefaultSchedulerName),
|
||||
kubeschedulerconfig.SchedulerAlgorithmSource{
|
||||
nil,
|
||||
scheduler.WithName(v1.DefaultSchedulerName),
|
||||
scheduler.WithAlgorithmSource(kubeschedulerconfig.SchedulerAlgorithmSource{
|
||||
Policy: &kubeschedulerconfig.SchedulerPolicySource{
|
||||
ConfigMap: &kubeschedulerconfig.SchedulerPolicyConfigMapSource{
|
||||
Namespace: "non-existent-config",
|
||||
Name: "non-existent-config",
|
||||
},
|
||||
},
|
||||
},
|
||||
nil,
|
||||
scheduler.WithName(v1.DefaultSchedulerName),
|
||||
}),
|
||||
scheduler.WithHardPodAffinitySymmetricWeight(v1.DefaultHardPodAffinitySymmetricWeight),
|
||||
scheduler.WithBindTimeoutSeconds(defaultBindTimeout))
|
||||
|
||||
|
@ -181,14 +181,8 @@ func initTestSchedulerWithOptions(
|
||||
legacyscheme.Scheme,
|
||||
v1.DefaultSchedulerName,
|
||||
)
|
||||
var algorithmSrc schedulerapi.SchedulerAlgorithmSource
|
||||
if policy != nil {
|
||||
algorithmSrc = createAlgorithmSourceFromPolicy(policy, context.clientSet)
|
||||
} else {
|
||||
provider := schedulerapi.SchedulerDefaultProviderName
|
||||
algorithmSrc = schedulerapi.SchedulerAlgorithmSource{
|
||||
Provider: &provider,
|
||||
}
|
||||
opts = append(opts, scheduler.WithAlgorithmSource(createAlgorithmSourceFromPolicy(policy, context.clientSet)))
|
||||
}
|
||||
opts = append([]scheduler.Option{scheduler.WithBindTimeoutSeconds(600)}, opts...)
|
||||
context.scheduler, err = scheduler.New(
|
||||
@ -196,7 +190,6 @@ func initTestSchedulerWithOptions(
|
||||
context.informerFactory,
|
||||
podInformer,
|
||||
recorder,
|
||||
algorithmSrc,
|
||||
context.ctx.Done(),
|
||||
opts...,
|
||||
)
|
||||
|
@ -16,7 +16,6 @@ go_library(
|
||||
"//pkg/api/legacyscheme:go_default_library",
|
||||
"//pkg/scheduler:go_default_library",
|
||||
"//pkg/scheduler/algorithmprovider/defaults:go_default_library",
|
||||
"//pkg/scheduler/apis/config:go_default_library",
|
||||
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
||||
"//staging/src/k8s.io/client-go/informers:go_default_library",
|
||||
"//staging/src/k8s.io/client-go/informers/core/v1:go_default_library",
|
||||
|
@ -32,7 +32,6 @@ import (
|
||||
|
||||
// import DefaultProvider
|
||||
_ "k8s.io/kubernetes/pkg/scheduler/algorithmprovider/defaults"
|
||||
schedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
|
||||
"k8s.io/kubernetes/test/integration/framework"
|
||||
)
|
||||
|
||||
@ -99,16 +98,11 @@ func createScheduler(
|
||||
recorder events.EventRecorder,
|
||||
stopCh <-chan struct{},
|
||||
) (*scheduler.Scheduler, error) {
|
||||
defaultProviderName := schedulerconfig.SchedulerDefaultProviderName
|
||||
|
||||
return scheduler.New(
|
||||
clientSet,
|
||||
informerFactory,
|
||||
podInformer,
|
||||
recorder,
|
||||
schedulerconfig.SchedulerAlgorithmSource{
|
||||
Provider: &defaultProviderName,
|
||||
},
|
||||
stopCh,
|
||||
)
|
||||
}
|
||||
|
@ -59,7 +59,6 @@ go_library(
|
||||
"//pkg/api/v1/pod:go_default_library",
|
||||
"//pkg/scheduler:go_default_library",
|
||||
"//pkg/scheduler/algorithmprovider/defaults:go_default_library",
|
||||
"//pkg/scheduler/apis/config:go_default_library",
|
||||
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
|
||||
|
@ -37,7 +37,6 @@ import (
|
||||
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
||||
podutil "k8s.io/kubernetes/pkg/api/v1/pod"
|
||||
"k8s.io/kubernetes/pkg/scheduler"
|
||||
schedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
|
||||
"k8s.io/kubernetes/test/integration/framework"
|
||||
|
||||
// Install "DefaultProvider" algorithprovider
|
||||
@ -142,16 +141,11 @@ func createSchedulerWithPodInformer(
|
||||
recorder events.EventRecorder,
|
||||
stopCh <-chan struct{},
|
||||
) (*scheduler.Scheduler, error) {
|
||||
defaultProviderName := schedulerconfig.SchedulerDefaultProviderName
|
||||
|
||||
return scheduler.New(
|
||||
clientSet,
|
||||
informerFactory,
|
||||
podInformer,
|
||||
recorder,
|
||||
schedulerconfig.SchedulerAlgorithmSource{
|
||||
Provider: &defaultProviderName,
|
||||
},
|
||||
stopCh,
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user