mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 05:27:21 +00:00
Merge pull request #102745 from ahg-g/ahg-provider
Remove SchedulerAlgorithmSource from scheduler's internal CC API
This commit is contained in:
commit
8955463c17
@ -31,6 +31,8 @@ type Config struct {
|
|||||||
// ComponentConfig is the scheduler server's configuration object.
|
// ComponentConfig is the scheduler server's configuration object.
|
||||||
ComponentConfig kubeschedulerconfig.KubeSchedulerConfiguration
|
ComponentConfig kubeschedulerconfig.KubeSchedulerConfiguration
|
||||||
|
|
||||||
|
LegacyPolicySource *kubeschedulerconfig.SchedulerPolicySource
|
||||||
|
|
||||||
// LoopbackClientConfig is a config for a privileged loopback connection
|
// LoopbackClientConfig is a config for a privileged loopback connection
|
||||||
LoopbackClientConfig *restclient.Config
|
LoopbackClientConfig *restclient.Config
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ import (
|
|||||||
|
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
"k8s.io/apimachinery/pkg/util/validation/field"
|
"k8s.io/apimachinery/pkg/util/validation/field"
|
||||||
|
schedulerappconfig "k8s.io/kubernetes/cmd/kube-scheduler/app/config"
|
||||||
kubeschedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
|
kubeschedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
|
||||||
"k8s.io/kubernetes/pkg/scheduler/apis/config/validation"
|
"k8s.io/kubernetes/pkg/scheduler/apis/config/validation"
|
||||||
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/interpodaffinity"
|
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/interpodaffinity"
|
||||||
@ -84,48 +85,44 @@ func (o *DeprecatedOptions) Validate() []error {
|
|||||||
return errs
|
return errs
|
||||||
}
|
}
|
||||||
|
|
||||||
// ApplyAlgorithmSourceTo sets cfg.AlgorithmSource from flags passed on the command line in the following precedence order:
|
// ApplyPolicySourceTo sets cfg.PolicySource from flags passed on the command line in the following precedence order:
|
||||||
//
|
//
|
||||||
// 1. --use-legacy-policy-config to use a policy file.
|
// 1. --use-legacy-policy-config to use a policy file.
|
||||||
// 2. --policy-configmap to use a policy config map value.
|
// 2. --policy-configmap to use a policy config map value.
|
||||||
func (o *DeprecatedOptions) ApplyAlgorithmSourceTo(cfg *kubeschedulerconfig.KubeSchedulerConfiguration) {
|
func (o *DeprecatedOptions) ApplyPolicySourceTo(c *schedulerappconfig.Config) {
|
||||||
if o == nil {
|
if o == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case o.UseLegacyPolicyConfig || (len(o.PolicyConfigFile) > 0 && o.PolicyConfigMapName == ""):
|
case o.UseLegacyPolicyConfig || (len(o.PolicyConfigFile) > 0 && o.PolicyConfigMapName == ""):
|
||||||
cfg.AlgorithmSource = kubeschedulerconfig.SchedulerAlgorithmSource{
|
c.LegacyPolicySource = &kubeschedulerconfig.SchedulerPolicySource{
|
||||||
Policy: &kubeschedulerconfig.SchedulerPolicySource{
|
File: &kubeschedulerconfig.SchedulerPolicyFileSource{
|
||||||
File: &kubeschedulerconfig.SchedulerPolicyFileSource{
|
Path: o.PolicyConfigFile,
|
||||||
Path: o.PolicyConfigFile,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
case len(o.PolicyConfigMapName) > 0:
|
case len(o.PolicyConfigMapName) > 0:
|
||||||
cfg.AlgorithmSource = kubeschedulerconfig.SchedulerAlgorithmSource{
|
c.LegacyPolicySource = &kubeschedulerconfig.SchedulerPolicySource{
|
||||||
Policy: &kubeschedulerconfig.SchedulerPolicySource{
|
ConfigMap: &kubeschedulerconfig.SchedulerPolicyConfigMapSource{
|
||||||
ConfigMap: &kubeschedulerconfig.SchedulerPolicyConfigMapSource{
|
Name: o.PolicyConfigMapName,
|
||||||
Name: o.PolicyConfigMapName,
|
Namespace: o.PolicyConfigMapNamespace,
|
||||||
Namespace: o.PolicyConfigMapNamespace,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ApplyTo sets a default profile plugin config if no config file is specified
|
// ApplyTo sets a default profile plugin config if no config file is specified
|
||||||
// It also calls ApplyAlgorithmSourceTo to set Policy settings in AlgorithmSource, if applicable.
|
// It also calls ApplyPolicySourceTo to set Policy source if applicable.
|
||||||
// Deprecated flags have an effect iff no config file was provided, in which
|
// Deprecated flags have an effect iff no config file was provided, in which
|
||||||
// case this function expects a default KubeSchedulerConfiguration instance,
|
// case this function expects a default KubeSchedulerConfiguration instance,
|
||||||
// which has a single profile.
|
// which has a single profile.
|
||||||
func (o *DeprecatedOptions) ApplyTo(cfg *kubeschedulerconfig.KubeSchedulerConfiguration) {
|
func (o *DeprecatedOptions) ApplyTo(c *schedulerappconfig.Config) {
|
||||||
if o == nil {
|
if o == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// The following deprecated options affect the only existing profile that is
|
// The following deprecated options affect the only existing profile that is
|
||||||
// added by default.
|
// added by default.
|
||||||
profile := &cfg.Profiles[0]
|
profile := &c.ComponentConfig.Profiles[0]
|
||||||
if len(o.SchedulerName) > 0 {
|
if len(o.SchedulerName) > 0 {
|
||||||
profile.SchedulerName = o.SchedulerName
|
profile.SchedulerName = o.SchedulerName
|
||||||
}
|
}
|
||||||
@ -137,5 +134,5 @@ func (o *DeprecatedOptions) ApplyTo(cfg *kubeschedulerconfig.KubeSchedulerConfig
|
|||||||
}
|
}
|
||||||
|
|
||||||
profile.PluginConfig = append(profile.PluginConfig, plCfg)
|
profile.PluginConfig = append(profile.PluginConfig, plCfg)
|
||||||
o.ApplyAlgorithmSourceTo(cfg)
|
o.ApplyPolicySourceTo(c)
|
||||||
}
|
}
|
||||||
|
@ -179,7 +179,7 @@ func (o *Options) ApplyTo(c *schedulerappconfig.Config) error {
|
|||||||
c.ComponentConfig = o.ComponentConfig
|
c.ComponentConfig = o.ComponentConfig
|
||||||
|
|
||||||
// apply deprecated flags if no config file is loaded (this is the old behaviour).
|
// apply deprecated flags if no config file is loaded (this is the old behaviour).
|
||||||
o.Deprecated.ApplyTo(&c.ComponentConfig)
|
o.Deprecated.ApplyTo(c)
|
||||||
if err := o.CombinedInsecureServing.ApplyTo(c, &c.ComponentConfig); err != nil {
|
if err := o.CombinedInsecureServing.ApplyTo(c, &c.ComponentConfig); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -195,11 +195,11 @@ func (o *Options) ApplyTo(c *schedulerappconfig.Config) error {
|
|||||||
c.ComponentConfig = *cfg
|
c.ComponentConfig = *cfg
|
||||||
|
|
||||||
// apply any deprecated Policy flags, if applicable
|
// apply any deprecated Policy flags, if applicable
|
||||||
o.Deprecated.ApplyAlgorithmSourceTo(&c.ComponentConfig)
|
o.Deprecated.ApplyPolicySourceTo(c)
|
||||||
|
|
||||||
// if the user has set CC profiles and is trying to use a Policy config, error out
|
// if the user has set CC profiles and is trying to use a Policy config, error out
|
||||||
// these configs are no longer merged and they should not be used simultaneously
|
// these configs are no longer merged and they should not be used simultaneously
|
||||||
if !emptySchedulerProfileConfig(c.ComponentConfig.Profiles) && c.ComponentConfig.AlgorithmSource.Policy != nil {
|
if !emptySchedulerProfileConfig(c.ComponentConfig.Profiles) && c.LegacyPolicySource != nil {
|
||||||
return fmt.Errorf("cannot set a Plugin config and Policy config")
|
return fmt.Errorf("cannot set a Plugin config and Policy config")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -330,7 +330,6 @@ profiles:
|
|||||||
defer os.Setenv("KUBERNETES_SERVICE_HOST", originalHost)
|
defer os.Setenv("KUBERNETES_SERVICE_HOST", originalHost)
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultSource := "DefaultProvider"
|
|
||||||
defaultPodInitialBackoffSeconds := int64(1)
|
defaultPodInitialBackoffSeconds := int64(1)
|
||||||
defaultPodMaxBackoffSeconds := int64(10)
|
defaultPodMaxBackoffSeconds := int64(10)
|
||||||
defaultPercentageOfNodesToScore := int32(0)
|
defaultPercentageOfNodesToScore := int32(0)
|
||||||
@ -386,7 +385,6 @@ profiles:
|
|||||||
APIVersion: v1beta2.SchemeGroupVersion.String(),
|
APIVersion: v1beta2.SchemeGroupVersion.String(),
|
||||||
},
|
},
|
||||||
Parallelism: 16,
|
Parallelism: 16,
|
||||||
AlgorithmSource: kubeschedulerconfig.SchedulerAlgorithmSource{Provider: &defaultSource},
|
|
||||||
HealthzBindAddress: "0.0.0.0:10251",
|
HealthzBindAddress: "0.0.0.0:10251",
|
||||||
MetricsBindAddress: "0.0.0.0:10251",
|
MetricsBindAddress: "0.0.0.0:10251",
|
||||||
DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{
|
DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{
|
||||||
@ -459,7 +457,6 @@ profiles:
|
|||||||
APIVersion: v1beta1.SchemeGroupVersion.String(),
|
APIVersion: v1beta1.SchemeGroupVersion.String(),
|
||||||
},
|
},
|
||||||
Parallelism: 16,
|
Parallelism: 16,
|
||||||
AlgorithmSource: kubeschedulerconfig.SchedulerAlgorithmSource{Provider: &defaultSource},
|
|
||||||
HealthzBindAddress: "0.0.0.0:10251",
|
HealthzBindAddress: "0.0.0.0:10251",
|
||||||
MetricsBindAddress: "0.0.0.0:10251",
|
MetricsBindAddress: "0.0.0.0:10251",
|
||||||
DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{
|
DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{
|
||||||
@ -560,7 +557,6 @@ profiles:
|
|||||||
APIVersion: v1beta2.SchemeGroupVersion.String(),
|
APIVersion: v1beta2.SchemeGroupVersion.String(),
|
||||||
},
|
},
|
||||||
Parallelism: 16,
|
Parallelism: 16,
|
||||||
AlgorithmSource: kubeschedulerconfig.SchedulerAlgorithmSource{Provider: &defaultSource},
|
|
||||||
HealthzBindAddress: "", // defaults empty when not running from config file
|
HealthzBindAddress: "", // defaults empty when not running from config file
|
||||||
MetricsBindAddress: "", // defaults empty when not running from config file
|
MetricsBindAddress: "", // defaults empty when not running from config file
|
||||||
DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{
|
DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{
|
||||||
@ -629,7 +625,6 @@ profiles:
|
|||||||
APIVersion: v1beta2.SchemeGroupVersion.String(),
|
APIVersion: v1beta2.SchemeGroupVersion.String(),
|
||||||
},
|
},
|
||||||
Parallelism: 16,
|
Parallelism: 16,
|
||||||
AlgorithmSource: kubeschedulerconfig.SchedulerAlgorithmSource{Provider: &defaultSource},
|
|
||||||
HealthzBindAddress: "", // defaults empty when not running from config file
|
HealthzBindAddress: "", // defaults empty when not running from config file
|
||||||
MetricsBindAddress: "", // defaults empty when not running from config file
|
MetricsBindAddress: "", // defaults empty when not running from config file
|
||||||
DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{
|
DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{
|
||||||
@ -672,7 +667,6 @@ profiles:
|
|||||||
APIVersion: v1beta2.SchemeGroupVersion.String(),
|
APIVersion: v1beta2.SchemeGroupVersion.String(),
|
||||||
},
|
},
|
||||||
Parallelism: 16,
|
Parallelism: 16,
|
||||||
AlgorithmSource: kubeschedulerconfig.SchedulerAlgorithmSource{Provider: &defaultSource},
|
|
||||||
HealthzBindAddress: "0.0.0.0:10251",
|
HealthzBindAddress: "0.0.0.0:10251",
|
||||||
MetricsBindAddress: "0.0.0.0:10251",
|
MetricsBindAddress: "0.0.0.0:10251",
|
||||||
DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{
|
DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{
|
||||||
@ -750,7 +744,6 @@ profiles:
|
|||||||
APIVersion: v1beta1.SchemeGroupVersion.String(),
|
APIVersion: v1beta1.SchemeGroupVersion.String(),
|
||||||
},
|
},
|
||||||
Parallelism: 16,
|
Parallelism: 16,
|
||||||
AlgorithmSource: kubeschedulerconfig.SchedulerAlgorithmSource{Provider: &defaultSource},
|
|
||||||
HealthzBindAddress: "0.0.0.0:10251",
|
HealthzBindAddress: "0.0.0.0:10251",
|
||||||
MetricsBindAddress: "0.0.0.0:10251",
|
MetricsBindAddress: "0.0.0.0:10251",
|
||||||
DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{
|
DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{
|
||||||
@ -829,7 +822,6 @@ profiles:
|
|||||||
APIVersion: v1beta2.SchemeGroupVersion.String(),
|
APIVersion: v1beta2.SchemeGroupVersion.String(),
|
||||||
},
|
},
|
||||||
Parallelism: 16,
|
Parallelism: 16,
|
||||||
AlgorithmSource: kubeschedulerconfig.SchedulerAlgorithmSource{Provider: &defaultSource},
|
|
||||||
HealthzBindAddress: "0.0.0.0:10251",
|
HealthzBindAddress: "0.0.0.0:10251",
|
||||||
MetricsBindAddress: "0.0.0.0:10251",
|
MetricsBindAddress: "0.0.0.0:10251",
|
||||||
DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{
|
DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{
|
||||||
@ -895,7 +887,6 @@ profiles:
|
|||||||
APIVersion: v1beta1.SchemeGroupVersion.String(),
|
APIVersion: v1beta1.SchemeGroupVersion.String(),
|
||||||
},
|
},
|
||||||
Parallelism: 16,
|
Parallelism: 16,
|
||||||
AlgorithmSource: kubeschedulerconfig.SchedulerAlgorithmSource{Provider: &defaultSource},
|
|
||||||
HealthzBindAddress: "0.0.0.0:10251",
|
HealthzBindAddress: "0.0.0.0:10251",
|
||||||
MetricsBindAddress: "0.0.0.0:10251",
|
MetricsBindAddress: "0.0.0.0:10251",
|
||||||
DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{
|
DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{
|
||||||
@ -974,8 +965,7 @@ profiles:
|
|||||||
TypeMeta: metav1.TypeMeta{
|
TypeMeta: metav1.TypeMeta{
|
||||||
APIVersion: v1beta2.SchemeGroupVersion.String(),
|
APIVersion: v1beta2.SchemeGroupVersion.String(),
|
||||||
},
|
},
|
||||||
Parallelism: 16,
|
Parallelism: 16,
|
||||||
AlgorithmSource: kubeschedulerconfig.SchedulerAlgorithmSource{Provider: &defaultSource},
|
|
||||||
DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{
|
DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{
|
||||||
EnableProfiling: true,
|
EnableProfiling: true,
|
||||||
EnableContentionProfiling: true,
|
EnableContentionProfiling: true,
|
||||||
@ -1030,8 +1020,7 @@ profiles:
|
|||||||
TypeMeta: metav1.TypeMeta{
|
TypeMeta: metav1.TypeMeta{
|
||||||
APIVersion: v1beta2.SchemeGroupVersion.String(),
|
APIVersion: v1beta2.SchemeGroupVersion.String(),
|
||||||
},
|
},
|
||||||
Parallelism: 16,
|
Parallelism: 16,
|
||||||
AlgorithmSource: kubeschedulerconfig.SchedulerAlgorithmSource{Provider: &defaultSource},
|
|
||||||
DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{
|
DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{
|
||||||
EnableProfiling: true,
|
EnableProfiling: true,
|
||||||
EnableContentionProfiling: true,
|
EnableContentionProfiling: true,
|
||||||
|
@ -333,7 +333,7 @@ func Setup(ctx context.Context, opts *options.Options, outOfTreeRegistryOptions
|
|||||||
scheduler.WithComponentConfigVersion(cc.ComponentConfig.TypeMeta.APIVersion),
|
scheduler.WithComponentConfigVersion(cc.ComponentConfig.TypeMeta.APIVersion),
|
||||||
scheduler.WithKubeConfig(cc.KubeConfig),
|
scheduler.WithKubeConfig(cc.KubeConfig),
|
||||||
scheduler.WithProfiles(cc.ComponentConfig.Profiles...),
|
scheduler.WithProfiles(cc.ComponentConfig.Profiles...),
|
||||||
scheduler.WithAlgorithmSource(cc.ComponentConfig.AlgorithmSource),
|
scheduler.WithLegacyPolicySource(cc.LegacyPolicySource),
|
||||||
scheduler.WithPercentageOfNodesToScore(cc.ComponentConfig.PercentageOfNodesToScore),
|
scheduler.WithPercentageOfNodesToScore(cc.ComponentConfig.PercentageOfNodesToScore),
|
||||||
scheduler.WithFrameworkOutOfTreeRegistry(outOfTreeRegistry),
|
scheduler.WithFrameworkOutOfTreeRegistry(outOfTreeRegistry),
|
||||||
scheduler.WithPodMaxBackoffSeconds(cc.ComponentConfig.PodMaxBackoffSeconds),
|
scheduler.WithPodMaxBackoffSeconds(cc.ComponentConfig.PodMaxBackoffSeconds),
|
||||||
|
@ -1365,14 +1365,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
|
|||||||
Data: map[string]string{config.SchedulerPolicyConfigMapKey: tc.JSON},
|
Data: map[string]string{config.SchedulerPolicyConfigMapKey: tc.JSON},
|
||||||
}
|
}
|
||||||
client := fake.NewSimpleClientset(&policyConfigMap)
|
client := fake.NewSimpleClientset(&policyConfigMap)
|
||||||
algorithmSrc := config.SchedulerAlgorithmSource{
|
|
||||||
Policy: &config.SchedulerPolicySource{
|
|
||||||
ConfigMap: &config.SchedulerPolicyConfigMapSource{
|
|
||||||
Namespace: policyConfigMap.Namespace,
|
|
||||||
Name: policyConfigMap.Name,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
informerFactory := informers.NewSharedInformerFactory(client, 0)
|
informerFactory := informers.NewSharedInformerFactory(client, 0)
|
||||||
recorderFactory := profile.NewRecorderFactory(events.NewBroadcaster(&events.EventSinkImpl{Interface: client.EventsV1()}))
|
recorderFactory := profile.NewRecorderFactory(events.NewBroadcaster(&events.EventSinkImpl{Interface: client.EventsV1()}))
|
||||||
|
|
||||||
@ -1381,7 +1373,12 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
|
|||||||
informerFactory,
|
informerFactory,
|
||||||
recorderFactory,
|
recorderFactory,
|
||||||
make(chan struct{}),
|
make(chan struct{}),
|
||||||
scheduler.WithAlgorithmSource(algorithmSrc),
|
scheduler.WithLegacyPolicySource(&config.SchedulerPolicySource{
|
||||||
|
ConfigMap: &config.SchedulerPolicyConfigMapSource{
|
||||||
|
Namespace: policyConfigMap.Namespace,
|
||||||
|
Name: policyConfigMap.Name,
|
||||||
|
},
|
||||||
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -1412,110 +1409,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAlgorithmProviderCompatibility(t *testing.T) {
|
|
||||||
// Add serialized versions of scheduler config that exercise available options to ensure compatibility between releases
|
|
||||||
defaultPlugins := map[string][]config.Plugin{
|
|
||||||
"QueueSortPlugin": {
|
|
||||||
{Name: "PrioritySort"},
|
|
||||||
},
|
|
||||||
"PreFilterPlugin": {
|
|
||||||
{Name: "NodeResourcesFit"},
|
|
||||||
{Name: "NodePorts"},
|
|
||||||
{Name: "PodTopologySpread"},
|
|
||||||
{Name: "InterPodAffinity"},
|
|
||||||
{Name: "VolumeBinding"},
|
|
||||||
{Name: "NodeAffinity"},
|
|
||||||
},
|
|
||||||
"FilterPlugin": {
|
|
||||||
{Name: "NodeUnschedulable"},
|
|
||||||
{Name: "NodeName"},
|
|
||||||
{Name: "TaintToleration"},
|
|
||||||
{Name: "NodeAffinity"},
|
|
||||||
{Name: "NodePorts"},
|
|
||||||
{Name: "NodeResourcesFit"},
|
|
||||||
{Name: "VolumeRestrictions"},
|
|
||||||
{Name: "EBSLimits"},
|
|
||||||
{Name: "GCEPDLimits"},
|
|
||||||
{Name: "NodeVolumeLimits"},
|
|
||||||
{Name: "AzureDiskLimits"},
|
|
||||||
{Name: "VolumeBinding"},
|
|
||||||
{Name: "VolumeZone"},
|
|
||||||
{Name: "PodTopologySpread"},
|
|
||||||
{Name: "InterPodAffinity"},
|
|
||||||
},
|
|
||||||
"PostFilterPlugin": {
|
|
||||||
{Name: "DefaultPreemption"},
|
|
||||||
},
|
|
||||||
"PreScorePlugin": {
|
|
||||||
{Name: "InterPodAffinity"},
|
|
||||||
{Name: "PodTopologySpread"},
|
|
||||||
{Name: "TaintToleration"},
|
|
||||||
{Name: "NodeAffinity"},
|
|
||||||
},
|
|
||||||
"ScorePlugin": {
|
|
||||||
{Name: "NodeResourcesBalancedAllocation", Weight: 1},
|
|
||||||
{Name: "ImageLocality", Weight: 1},
|
|
||||||
{Name: "InterPodAffinity", Weight: 1},
|
|
||||||
{Name: "NodeResourcesLeastAllocated", Weight: 1},
|
|
||||||
{Name: "NodeAffinity", Weight: 1},
|
|
||||||
{Name: "NodePreferAvoidPods", Weight: 10000},
|
|
||||||
{Name: "PodTopologySpread", Weight: 2},
|
|
||||||
{Name: "TaintToleration", Weight: 1},
|
|
||||||
},
|
|
||||||
"BindPlugin": {{Name: "DefaultBinder"}},
|
|
||||||
"ReservePlugin": {{Name: "VolumeBinding"}},
|
|
||||||
"PreBindPlugin": {{Name: "VolumeBinding"}},
|
|
||||||
}
|
|
||||||
|
|
||||||
testcases := []struct {
|
|
||||||
name string
|
|
||||||
provider string
|
|
||||||
wantPlugins map[string][]config.Plugin
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "No Provider specified",
|
|
||||||
wantPlugins: defaultPlugins,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "DefaultProvider",
|
|
||||||
provider: config.SchedulerDefaultProviderName,
|
|
||||||
wantPlugins: defaultPlugins,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for _, tc := range testcases {
|
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
|
||||||
var opts []scheduler.Option
|
|
||||||
if len(tc.provider) != 0 {
|
|
||||||
opts = append(opts, scheduler.WithAlgorithmSource(config.SchedulerAlgorithmSource{
|
|
||||||
Provider: &tc.provider,
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
|
|
||||||
client := fake.NewSimpleClientset()
|
|
||||||
informerFactory := informers.NewSharedInformerFactory(client, 0)
|
|
||||||
recorderFactory := profile.NewRecorderFactory(events.NewBroadcaster(&events.EventSinkImpl{Interface: client.EventsV1()}))
|
|
||||||
|
|
||||||
sched, err := scheduler.New(
|
|
||||||
client,
|
|
||||||
informerFactory,
|
|
||||||
recorderFactory,
|
|
||||||
make(chan struct{}),
|
|
||||||
opts...,
|
|
||||||
)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Error constructing: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
defProf := sched.Profiles["default-scheduler"]
|
|
||||||
gotPlugins := defProf.ListPlugins()
|
|
||||||
if diff := cmp.Diff(tc.wantPlugins, gotPlugins); diff != "" {
|
|
||||||
t.Errorf("unexpected plugins diff (-want, +got): %s", diff)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestPluginsConfigurationCompatibility(t *testing.T) {
|
func TestPluginsConfigurationCompatibility(t *testing.T) {
|
||||||
defaultPlugins := map[string][]config.Plugin{
|
defaultPlugins := map[string][]config.Plugin{
|
||||||
"QueueSortPlugin": {
|
"QueueSortPlugin": {
|
||||||
|
@ -30,9 +30,6 @@ const (
|
|||||||
// scheduler's policy ConfigMap that contains scheduler's policy config.
|
// scheduler's policy ConfigMap that contains scheduler's policy config.
|
||||||
SchedulerPolicyConfigMapKey = "policy.cfg"
|
SchedulerPolicyConfigMapKey = "policy.cfg"
|
||||||
|
|
||||||
// SchedulerDefaultProviderName defines the default provider names
|
|
||||||
SchedulerDefaultProviderName = "DefaultProvider"
|
|
||||||
|
|
||||||
// DefaultInsecureSchedulerPort is the default port for the scheduler status server.
|
// DefaultInsecureSchedulerPort is the default port for the scheduler status server.
|
||||||
// May be overridden by a flag at startup.
|
// May be overridden by a flag at startup.
|
||||||
// Deprecated: use the secure KubeSchedulerPort instead.
|
// Deprecated: use the secure KubeSchedulerPort instead.
|
||||||
@ -60,11 +57,6 @@ type KubeSchedulerConfiguration struct {
|
|||||||
// Parallelism defines the amount of parallelism in algorithms for scheduling a Pods. Must be greater than 0. Defaults to 16
|
// Parallelism defines the amount of parallelism in algorithms for scheduling a Pods. Must be greater than 0. Defaults to 16
|
||||||
Parallelism int32
|
Parallelism int32
|
||||||
|
|
||||||
// AlgorithmSource specifies the scheduler algorithm source.
|
|
||||||
// TODO(#87526): Remove AlgorithmSource from this package
|
|
||||||
// DEPRECATED: AlgorithmSource is removed in the v1beta1 ComponentConfig
|
|
||||||
AlgorithmSource SchedulerAlgorithmSource
|
|
||||||
|
|
||||||
// LeaderElection defines the configuration of leader election client.
|
// LeaderElection defines the configuration of leader election client.
|
||||||
LeaderElection componentbaseconfig.LeaderElectionConfiguration
|
LeaderElection componentbaseconfig.LeaderElectionConfiguration
|
||||||
|
|
||||||
@ -136,15 +128,6 @@ type KubeSchedulerProfile struct {
|
|||||||
PluginConfig []PluginConfig
|
PluginConfig []PluginConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
// SchedulerAlgorithmSource is the source of a scheduler algorithm. One source
|
|
||||||
// field must be specified, and source fields are mutually exclusive.
|
|
||||||
type SchedulerAlgorithmSource struct {
|
|
||||||
// Policy is a policy based algorithm source.
|
|
||||||
Policy *SchedulerPolicySource
|
|
||||||
// Provider is the name of a scheduling algorithm provider to use.
|
|
||||||
Provider *string
|
|
||||||
}
|
|
||||||
|
|
||||||
// SchedulerPolicySource configures a means to obtain a scheduler Policy. One
|
// SchedulerPolicySource configures a means to obtain a scheduler Policy. One
|
||||||
// source field must be specified, and source fields are mutually exclusive.
|
// source field must be specified, and source fields are mutually exclusive.
|
||||||
type SchedulerPolicySource struct {
|
type SchedulerPolicySource struct {
|
||||||
@ -305,7 +288,6 @@ func (p *Plugins) Apply(customPlugins *Plugins) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func mergePluginSets(defaultPluginSet, customPluginSet PluginSet) PluginSet {
|
func mergePluginSets(defaultPluginSet, customPluginSet PluginSet) PluginSet {
|
||||||
|
|
||||||
disabledPlugins := sets.NewString()
|
disabledPlugins := sets.NewString()
|
||||||
for _, disabledPlugin := range customPluginSet.Disabled {
|
for _, disabledPlugin := range customPluginSet.Disabled {
|
||||||
disabledPlugins.Insert(disabledPlugin.Name)
|
disabledPlugins.Insert(disabledPlugin.Name)
|
||||||
@ -323,7 +305,6 @@ func mergePluginSets(defaultPluginSet, customPluginSet PluginSet) PluginSet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
enabledPlugins = append(enabledPlugins, customPluginSet.Enabled...)
|
enabledPlugins = append(enabledPlugins, customPluginSet.Enabled...)
|
||||||
|
|
||||||
return PluginSet{Enabled: enabledPlugins}
|
return PluginSet{Enabled: enabledPlugins}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,6 @@ import (
|
|||||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||||
"k8s.io/kube-scheduler/config/v1beta1"
|
"k8s.io/kube-scheduler/config/v1beta1"
|
||||||
"k8s.io/kubernetes/pkg/scheduler/apis/config"
|
"k8s.io/kubernetes/pkg/scheduler/apis/config"
|
||||||
"k8s.io/utils/pointer"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -142,7 +141,6 @@ func Convert_v1beta1_KubeSchedulerConfiguration_To_config_KubeSchedulerConfigura
|
|||||||
if err := autoConvert_v1beta1_KubeSchedulerConfiguration_To_config_KubeSchedulerConfiguration(in, out, s); err != nil {
|
if err := autoConvert_v1beta1_KubeSchedulerConfiguration_To_config_KubeSchedulerConfiguration(in, out, s); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
out.AlgorithmSource.Provider = pointer.StringPtr(v1beta1.SchedulerDefaultProviderName)
|
|
||||||
return convertToInternalPluginConfigArgs(out)
|
return convertToInternalPluginConfigArgs(out)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,62 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2020 The Kubernetes Authors.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package v1beta1
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/google/go-cmp/cmp"
|
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
|
||||||
"k8s.io/kube-scheduler/config/v1beta1"
|
|
||||||
"k8s.io/kubernetes/pkg/scheduler/apis/config"
|
|
||||||
"k8s.io/utils/pointer"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestV1beta1ToConfigKubeSchedulerConfigurationConversion(t *testing.T) {
|
|
||||||
cases := []struct {
|
|
||||||
name string
|
|
||||||
config v1beta1.KubeSchedulerConfiguration
|
|
||||||
want config.KubeSchedulerConfiguration
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "default conversion v1beta1 to config",
|
|
||||||
config: v1beta1.KubeSchedulerConfiguration{},
|
|
||||||
want: config.KubeSchedulerConfiguration{
|
|
||||||
AlgorithmSource: config.SchedulerAlgorithmSource{
|
|
||||||
Provider: pointer.StringPtr(v1beta1.SchedulerDefaultProviderName),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
scheme := runtime.NewScheme()
|
|
||||||
if err := AddToScheme(scheme); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, tc := range cases {
|
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
|
||||||
var got config.KubeSchedulerConfiguration
|
|
||||||
if err := scheme.Convert(&tc.config, &got, nil); err != nil {
|
|
||||||
t.Errorf("failed to convert: %+v", err)
|
|
||||||
}
|
|
||||||
if diff := cmp.Diff(tc.want, got); diff != "" {
|
|
||||||
t.Errorf("unexpected conversion (-want, +got):\n%s", diff)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
@ -386,7 +386,6 @@ func autoConvert_config_KubeSchedulerConfiguration_To_v1beta1_KubeSchedulerConfi
|
|||||||
if err := v1.Convert_int32_To_Pointer_int32(&in.Parallelism, &out.Parallelism, s); err != nil {
|
if err := v1.Convert_int32_To_Pointer_int32(&in.Parallelism, &out.Parallelism, s); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// WARNING: in.AlgorithmSource requires manual conversion: does not exist in peer-type
|
|
||||||
if err := v1alpha1.Convert_config_LeaderElectionConfiguration_To_v1alpha1_LeaderElectionConfiguration(&in.LeaderElection, &out.LeaderElection, s); err != nil {
|
if err := v1alpha1.Convert_config_LeaderElectionConfiguration_To_v1alpha1_LeaderElectionConfiguration(&in.LeaderElection, &out.LeaderElection, s); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,6 @@ import (
|
|||||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||||
"k8s.io/kube-scheduler/config/v1beta2"
|
"k8s.io/kube-scheduler/config/v1beta2"
|
||||||
"k8s.io/kubernetes/pkg/scheduler/apis/config"
|
"k8s.io/kubernetes/pkg/scheduler/apis/config"
|
||||||
"k8s.io/utils/pointer"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -50,7 +49,6 @@ func Convert_v1beta2_KubeSchedulerConfiguration_To_config_KubeSchedulerConfigura
|
|||||||
if err := autoConvert_v1beta2_KubeSchedulerConfiguration_To_config_KubeSchedulerConfiguration(in, out, s); err != nil {
|
if err := autoConvert_v1beta2_KubeSchedulerConfiguration_To_config_KubeSchedulerConfiguration(in, out, s); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
out.AlgorithmSource.Provider = pointer.StringPtr(v1beta2.SchedulerDefaultProviderName)
|
|
||||||
return convertToInternalPluginConfigArgs(out)
|
return convertToInternalPluginConfigArgs(out)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,62 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2021 The Kubernetes Authors.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package v1beta2
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/google/go-cmp/cmp"
|
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
|
||||||
"k8s.io/kube-scheduler/config/v1beta2"
|
|
||||||
"k8s.io/kubernetes/pkg/scheduler/apis/config"
|
|
||||||
"k8s.io/utils/pointer"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestV1beta2ToConfigKubeSchedulerConfigurationConversion(t *testing.T) {
|
|
||||||
cases := []struct {
|
|
||||||
name string
|
|
||||||
config v1beta2.KubeSchedulerConfiguration
|
|
||||||
want config.KubeSchedulerConfiguration
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "default conversion v1beta2 to config",
|
|
||||||
config: v1beta2.KubeSchedulerConfiguration{},
|
|
||||||
want: config.KubeSchedulerConfiguration{
|
|
||||||
AlgorithmSource: config.SchedulerAlgorithmSource{
|
|
||||||
Provider: pointer.StringPtr(v1beta2.SchedulerDefaultProviderName),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
scheme := runtime.NewScheme()
|
|
||||||
if err := AddToScheme(scheme); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, tc := range cases {
|
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
|
||||||
var got config.KubeSchedulerConfiguration
|
|
||||||
if err := scheme.Convert(&tc.config, &got, nil); err != nil {
|
|
||||||
t.Errorf("failed to convert: %+v", err)
|
|
||||||
}
|
|
||||||
if diff := cmp.Diff(tc.want, got); diff != "" {
|
|
||||||
t.Errorf("unexpected conversion (-want, +got):\n%s", diff)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
@ -366,7 +366,6 @@ func autoConvert_config_KubeSchedulerConfiguration_To_v1beta2_KubeSchedulerConfi
|
|||||||
if err := v1.Convert_int32_To_Pointer_int32(&in.Parallelism, &out.Parallelism, s); err != nil {
|
if err := v1.Convert_int32_To_Pointer_int32(&in.Parallelism, &out.Parallelism, s); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// WARNING: in.AlgorithmSource requires manual conversion: does not exist in peer-type
|
|
||||||
if err := v1alpha1.Convert_config_LeaderElectionConfiguration_To_v1alpha1_LeaderElectionConfiguration(&in.LeaderElection, &out.LeaderElection, s); err != nil {
|
if err := v1alpha1.Convert_config_LeaderElectionConfiguration_To_v1alpha1_LeaderElectionConfiguration(&in.LeaderElection, &out.LeaderElection, s); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -45,14 +45,6 @@ func TestValidateKubeSchedulerConfiguration(t *testing.T) {
|
|||||||
QPS: 10,
|
QPS: 10,
|
||||||
Burst: 10,
|
Burst: 10,
|
||||||
},
|
},
|
||||||
AlgorithmSource: config.SchedulerAlgorithmSource{
|
|
||||||
Policy: &config.SchedulerPolicySource{
|
|
||||||
ConfigMap: &config.SchedulerPolicyConfigMapSource{
|
|
||||||
Namespace: "name",
|
|
||||||
Name: "name",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
LeaderElection: componentbaseconfig.LeaderElectionConfiguration{
|
LeaderElection: componentbaseconfig.LeaderElectionConfiguration{
|
||||||
ResourceLock: "configmap",
|
ResourceLock: "configmap",
|
||||||
LeaderElect: true,
|
LeaderElect: true,
|
||||||
|
27
pkg/scheduler/apis/config/zz_generated.deepcopy.go
generated
27
pkg/scheduler/apis/config/zz_generated.deepcopy.go
generated
@ -153,7 +153,6 @@ func (in *InterPodAffinityArgs) DeepCopyObject() runtime.Object {
|
|||||||
func (in *KubeSchedulerConfiguration) DeepCopyInto(out *KubeSchedulerConfiguration) {
|
func (in *KubeSchedulerConfiguration) DeepCopyInto(out *KubeSchedulerConfiguration) {
|
||||||
*out = *in
|
*out = *in
|
||||||
out.TypeMeta = in.TypeMeta
|
out.TypeMeta = in.TypeMeta
|
||||||
in.AlgorithmSource.DeepCopyInto(&out.AlgorithmSource)
|
|
||||||
out.LeaderElection = in.LeaderElection
|
out.LeaderElection = in.LeaderElection
|
||||||
out.ClientConnection = in.ClientConnection
|
out.ClientConnection = in.ClientConnection
|
||||||
out.DebuggingConfiguration = in.DebuggingConfiguration
|
out.DebuggingConfiguration = in.DebuggingConfiguration
|
||||||
@ -769,32 +768,6 @@ func (in *ResourceSpec) DeepCopy() *ResourceSpec {
|
|||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
|
||||||
func (in *SchedulerAlgorithmSource) DeepCopyInto(out *SchedulerAlgorithmSource) {
|
|
||||||
*out = *in
|
|
||||||
if in.Policy != nil {
|
|
||||||
in, out := &in.Policy, &out.Policy
|
|
||||||
*out = new(SchedulerPolicySource)
|
|
||||||
(*in).DeepCopyInto(*out)
|
|
||||||
}
|
|
||||||
if in.Provider != nil {
|
|
||||||
in, out := &in.Provider, &out.Provider
|
|
||||||
*out = new(string)
|
|
||||||
**out = **in
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SchedulerAlgorithmSource.
|
|
||||||
func (in *SchedulerAlgorithmSource) DeepCopy() *SchedulerAlgorithmSource {
|
|
||||||
if in == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
out := new(SchedulerAlgorithmSource)
|
|
||||||
in.DeepCopyInto(out)
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||||
func (in *SchedulerPolicyConfigMapSource) DeepCopyInto(out *SchedulerPolicyConfigMapSource) {
|
func (in *SchedulerPolicyConfigMapSource) DeepCopyInto(out *SchedulerPolicyConfigMapSource) {
|
||||||
*out = *in
|
*out = *in
|
||||||
|
@ -195,10 +195,8 @@ func (c *Configurator) create() (*Scheduler, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// createFromProvider creates a scheduler from the name of a registered algorithm provider.
|
// createFromConfig creates a scheduler from ComonentConfig profiles.
|
||||||
func (c *Configurator) createFromProvider(providerName string) (*Scheduler, error) {
|
func (c *Configurator) createFromConfig() (*Scheduler, error) {
|
||||||
klog.V(2).InfoS("Creating scheduler from algorithm provider", "algorithmProvider", providerName)
|
|
||||||
|
|
||||||
defaultPlugins := algorithmprovider.GetDefaultConfig()
|
defaultPlugins := algorithmprovider.GetDefaultConfig()
|
||||||
|
|
||||||
for i := range c.profiles {
|
for i := range c.profiles {
|
||||||
@ -211,9 +209,8 @@ func (c *Configurator) createFromProvider(providerName string) (*Scheduler, erro
|
|||||||
return c.create()
|
return c.create()
|
||||||
}
|
}
|
||||||
|
|
||||||
// createFromConfig creates a scheduler from the configuration file
|
// createFromPolicy creates a scheduler from the legacy policy file
|
||||||
// Only reachable when using v1alpha1 component config
|
func (c *Configurator) createFromPolicy(policy schedulerapi.Policy) (*Scheduler, error) {
|
||||||
func (c *Configurator) createFromConfig(policy schedulerapi.Policy) (*Scheduler, error) {
|
|
||||||
lr := frameworkplugins.NewLegacyRegistry()
|
lr := frameworkplugins.NewLegacyRegistry()
|
||||||
args := &frameworkplugins.ConfigProducerArgs{}
|
args := &frameworkplugins.ConfigProducerArgs{}
|
||||||
|
|
||||||
@ -226,7 +223,6 @@ func (c *Configurator) createFromConfig(policy schedulerapi.Policy) (*Scheduler,
|
|||||||
|
|
||||||
predicateKeys := sets.NewString()
|
predicateKeys := sets.NewString()
|
||||||
if policy.Predicates == nil {
|
if policy.Predicates == nil {
|
||||||
klog.V(2).InfoS("Using predicates from algorithm provider", "algorithmProvider", schedulerapi.SchedulerDefaultProviderName)
|
|
||||||
predicateKeys = lr.DefaultPredicates
|
predicateKeys = lr.DefaultPredicates
|
||||||
} else {
|
} else {
|
||||||
for _, predicate := range policy.Predicates {
|
for _, predicate := range policy.Predicates {
|
||||||
|
@ -64,13 +64,12 @@ func TestCreate(t *testing.T) {
|
|||||||
stopCh := make(chan struct{})
|
stopCh := make(chan struct{})
|
||||||
defer close(stopCh)
|
defer close(stopCh)
|
||||||
factory := newConfigFactory(client, stopCh)
|
factory := newConfigFactory(client, stopCh)
|
||||||
if _, err := factory.createFromProvider(schedulerapi.SchedulerDefaultProviderName); err != nil {
|
if _, err := factory.createFromConfig(); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// createAlgorithmSourceFromPolicy creates the schedulerAlgorithmSource from policy string
|
func createPolicySource(configData []byte, clientSet clientset.Interface) *schedulerapi.SchedulerPolicySource {
|
||||||
func createAlgorithmSourceFromPolicy(configData []byte, clientSet clientset.Interface) schedulerapi.SchedulerAlgorithmSource {
|
|
||||||
configPolicyName := "scheduler-custom-policy-config"
|
configPolicyName := "scheduler-custom-policy-config"
|
||||||
policyConfigMap := v1.ConfigMap{
|
policyConfigMap := v1.ConfigMap{
|
||||||
TypeMeta: metav1.TypeMeta{
|
TypeMeta: metav1.TypeMeta{
|
||||||
@ -82,12 +81,10 @@ func createAlgorithmSourceFromPolicy(configData []byte, clientSet clientset.Inte
|
|||||||
|
|
||||||
clientSet.CoreV1().ConfigMaps(metav1.NamespaceSystem).Create(context.TODO(), &policyConfigMap, metav1.CreateOptions{})
|
clientSet.CoreV1().ConfigMaps(metav1.NamespaceSystem).Create(context.TODO(), &policyConfigMap, metav1.CreateOptions{})
|
||||||
|
|
||||||
return schedulerapi.SchedulerAlgorithmSource{
|
return &schedulerapi.SchedulerPolicySource{
|
||||||
Policy: &schedulerapi.SchedulerPolicySource{
|
ConfigMap: &schedulerapi.SchedulerPolicyConfigMapSource{
|
||||||
ConfigMap: &schedulerapi.SchedulerPolicyConfigMapSource{
|
Namespace: policyConfigMap.Namespace,
|
||||||
Namespace: policyConfigMap.Namespace,
|
Name: policyConfigMap.Name,
|
||||||
Name: policyConfigMap.Name,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -405,7 +402,7 @@ func TestCreateFromConfig(t *testing.T) {
|
|||||||
informerFactory,
|
informerFactory,
|
||||||
recorderFactory,
|
recorderFactory,
|
||||||
make(chan struct{}),
|
make(chan struct{}),
|
||||||
WithAlgorithmSource(createAlgorithmSourceFromPolicy(tc.configData, client)),
|
WithLegacyPolicySource(createPolicySource(tc.configData, client)),
|
||||||
WithBuildFrameworkCapturer(func(p schedulerapi.KubeSchedulerProfile) {
|
WithBuildFrameworkCapturer(func(p schedulerapi.KubeSchedulerProfile) {
|
||||||
if p.SchedulerName != v1.DefaultSchedulerName {
|
if p.SchedulerName != v1.DefaultSchedulerName {
|
||||||
t.Errorf("unexpected scheduler name: want %q, got %q", v1.DefaultSchedulerName, p.SchedulerName)
|
t.Errorf("unexpected scheduler name: want %q, got %q", v1.DefaultSchedulerName, p.SchedulerName)
|
||||||
|
@ -98,7 +98,7 @@ type Scheduler struct {
|
|||||||
type schedulerOptions struct {
|
type schedulerOptions struct {
|
||||||
componentConfigVersion string
|
componentConfigVersion string
|
||||||
kubeConfig *restclient.Config
|
kubeConfig *restclient.Config
|
||||||
schedulerAlgorithmSource schedulerapi.SchedulerAlgorithmSource
|
legacyPolicySource *schedulerapi.SchedulerPolicySource
|
||||||
percentageOfNodesToScore int32
|
percentageOfNodesToScore int32
|
||||||
podInitialBackoffSeconds int64
|
podInitialBackoffSeconds int64
|
||||||
podMaxBackoffSeconds int64
|
podMaxBackoffSeconds int64
|
||||||
@ -145,10 +145,10 @@ func WithParallelism(threads int32) Option {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithAlgorithmSource sets schedulerAlgorithmSource for Scheduler, the default is a source with DefaultProvider.
|
// WithPolicySource sets legacy policy config file source.
|
||||||
func WithAlgorithmSource(source schedulerapi.SchedulerAlgorithmSource) Option {
|
func WithLegacyPolicySource(source *schedulerapi.SchedulerPolicySource) Option {
|
||||||
return func(o *schedulerOptions) {
|
return func(o *schedulerOptions) {
|
||||||
o.schedulerAlgorithmSource = source
|
o.legacyPolicySource = source
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,9 +203,6 @@ var defaultSchedulerOptions = schedulerOptions{
|
|||||||
// Profiles' default plugins are set from the algorithm provider.
|
// Profiles' default plugins are set from the algorithm provider.
|
||||||
{SchedulerName: v1.DefaultSchedulerName},
|
{SchedulerName: v1.DefaultSchedulerName},
|
||||||
},
|
},
|
||||||
schedulerAlgorithmSource: schedulerapi.SchedulerAlgorithmSource{
|
|
||||||
Provider: defaultAlgorithmSourceProviderName(),
|
|
||||||
},
|
|
||||||
percentageOfNodesToScore: schedulerapi.DefaultPercentageOfNodesToScore,
|
percentageOfNodesToScore: schedulerapi.DefaultPercentageOfNodesToScore,
|
||||||
podInitialBackoffSeconds: int64(internalqueue.DefaultPodInitialBackoffDuration.Seconds()),
|
podInitialBackoffSeconds: int64(internalqueue.DefaultPodInitialBackoffDuration.Seconds()),
|
||||||
podMaxBackoffSeconds: int64(internalqueue.DefaultPodMaxBackoffDuration.Seconds()),
|
podMaxBackoffSeconds: int64(internalqueue.DefaultPodMaxBackoffDuration.Seconds()),
|
||||||
@ -262,25 +259,23 @@ func New(client clientset.Interface,
|
|||||||
metrics.Register()
|
metrics.Register()
|
||||||
|
|
||||||
var sched *Scheduler
|
var sched *Scheduler
|
||||||
source := options.schedulerAlgorithmSource
|
if options.legacyPolicySource == nil {
|
||||||
switch {
|
sc, err := configurator.createFromConfig()
|
||||||
case source.Provider != nil:
|
|
||||||
// Create the config from a named algorithm provider.
|
|
||||||
sc, err := configurator.createFromProvider(*source.Provider)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("couldn't create scheduler using provider %q: %v", *source.Provider, err)
|
return nil, fmt.Errorf("couldn't create scheduler: %v", err)
|
||||||
}
|
}
|
||||||
sched = sc
|
sched = sc
|
||||||
case source.Policy != nil:
|
|
||||||
|
} else {
|
||||||
// Create the config from a user specified policy source.
|
// Create the config from a user specified policy source.
|
||||||
policy := &schedulerapi.Policy{}
|
policy := &schedulerapi.Policy{}
|
||||||
switch {
|
switch {
|
||||||
case source.Policy.File != nil:
|
case options.legacyPolicySource.File != nil:
|
||||||
if err := initPolicyFromFile(source.Policy.File.Path, policy); err != nil {
|
if err := initPolicyFromFile(options.legacyPolicySource.File.Path, policy); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
case source.Policy.ConfigMap != nil:
|
case options.legacyPolicySource.ConfigMap != nil:
|
||||||
if err := initPolicyFromConfigMap(client, source.Policy.ConfigMap, policy); err != nil {
|
if err := initPolicyFromConfigMap(client, options.legacyPolicySource.ConfigMap, policy); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -288,14 +283,13 @@ func New(client clientset.Interface,
|
|||||||
// In this case, c.extenders should be nil since we're using a policy (and therefore not componentconfig,
|
// In this case, c.extenders should be nil since we're using a policy (and therefore not componentconfig,
|
||||||
// which would have set extenders in the above instantiation of Configurator from CC options)
|
// which would have set extenders in the above instantiation of Configurator from CC options)
|
||||||
configurator.extenders = policy.Extenders
|
configurator.extenders = policy.Extenders
|
||||||
sc, err := configurator.createFromConfig(*policy)
|
sc, err := configurator.createFromPolicy(*policy)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("couldn't create scheduler from policy: %v", err)
|
return nil, fmt.Errorf("couldn't create scheduler from policy: %v", err)
|
||||||
}
|
}
|
||||||
sched = sc
|
sched = sc
|
||||||
default:
|
|
||||||
return nil, fmt.Errorf("unsupported algorithm source: %v", source)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Additional tweaks to the config produced by the configurator.
|
// Additional tweaks to the config produced by the configurator.
|
||||||
sched.StopEverything = stopEverything
|
sched.StopEverything = stopEverything
|
||||||
sched.client = client
|
sched.client = client
|
||||||
@ -700,11 +694,6 @@ func (sched *Scheduler) skipPodSchedule(fwk framework.Framework, pod *v1.Pod) bo
|
|||||||
return isAssumed
|
return isAssumed
|
||||||
}
|
}
|
||||||
|
|
||||||
func defaultAlgorithmSourceProviderName() *string {
|
|
||||||
provider := schedulerapi.SchedulerDefaultProviderName
|
|
||||||
return &provider
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewInformerFactory creates a SharedInformerFactory and initializes a scheduler specific
|
// NewInformerFactory creates a SharedInformerFactory and initializes a scheduler specific
|
||||||
// in-place podInformer.
|
// in-place podInformer.
|
||||||
func NewInformerFactory(cs clientset.Interface, resyncPeriod time.Duration) informers.SharedInformerFactory {
|
func NewInformerFactory(cs clientset.Interface, resyncPeriod time.Duration) informers.SharedInformerFactory {
|
||||||
|
@ -282,12 +282,10 @@ priorities: []
|
|||||||
informerFactory,
|
informerFactory,
|
||||||
profile.NewRecorderFactory(eventBroadcaster),
|
profile.NewRecorderFactory(eventBroadcaster),
|
||||||
nil,
|
nil,
|
||||||
scheduler.WithAlgorithmSource(kubeschedulerconfig.SchedulerAlgorithmSource{
|
scheduler.WithLegacyPolicySource(&kubeschedulerconfig.SchedulerPolicySource{
|
||||||
Policy: &kubeschedulerconfig.SchedulerPolicySource{
|
ConfigMap: &kubeschedulerconfig.SchedulerPolicyConfigMapSource{
|
||||||
ConfigMap: &kubeschedulerconfig.SchedulerPolicyConfigMapSource{
|
Namespace: policyConfigMap.Namespace,
|
||||||
Namespace: policyConfigMap.Namespace,
|
Name: policyConfigMap.Name,
|
||||||
Name: policyConfigMap.Name,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
scheduler.WithProfiles(kubeschedulerconfig.KubeSchedulerProfile{
|
scheduler.WithProfiles(kubeschedulerconfig.KubeSchedulerProfile{
|
||||||
@ -335,12 +333,10 @@ func TestSchedulerCreationFromNonExistentConfigMap(t *testing.T) {
|
|||||||
informerFactory,
|
informerFactory,
|
||||||
profile.NewRecorderFactory(eventBroadcaster),
|
profile.NewRecorderFactory(eventBroadcaster),
|
||||||
nil,
|
nil,
|
||||||
scheduler.WithAlgorithmSource(kubeschedulerconfig.SchedulerAlgorithmSource{
|
scheduler.WithLegacyPolicySource(&kubeschedulerconfig.SchedulerPolicySource{
|
||||||
Policy: &kubeschedulerconfig.SchedulerPolicySource{
|
ConfigMap: &kubeschedulerconfig.SchedulerPolicyConfigMapSource{
|
||||||
ConfigMap: &kubeschedulerconfig.SchedulerPolicyConfigMapSource{
|
Namespace: "non-existent-config",
|
||||||
Namespace: "non-existent-config",
|
Name: "non-existent-config",
|
||||||
Name: "non-existent-config",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
scheduler.WithProfiles(kubeschedulerconfig.KubeSchedulerProfile{
|
scheduler.WithProfiles(kubeschedulerconfig.KubeSchedulerProfile{
|
||||||
|
@ -91,7 +91,6 @@ func StartScheduler(clientSet clientset.Interface, kubeConfig *restclient.Config
|
|||||||
ctx.Done(),
|
ctx.Done(),
|
||||||
scheduler.WithKubeConfig(kubeConfig),
|
scheduler.WithKubeConfig(kubeConfig),
|
||||||
scheduler.WithProfiles(cfg.Profiles...),
|
scheduler.WithProfiles(cfg.Profiles...),
|
||||||
scheduler.WithAlgorithmSource(cfg.AlgorithmSource),
|
|
||||||
scheduler.WithPercentageOfNodesToScore(cfg.PercentageOfNodesToScore),
|
scheduler.WithPercentageOfNodesToScore(cfg.PercentageOfNodesToScore),
|
||||||
scheduler.WithPodMaxBackoffSeconds(cfg.PodMaxBackoffSeconds),
|
scheduler.WithPodMaxBackoffSeconds(cfg.PodMaxBackoffSeconds),
|
||||||
scheduler.WithPodInitialBackoffSeconds(cfg.PodInitialBackoffSeconds),
|
scheduler.WithPodInitialBackoffSeconds(cfg.PodInitialBackoffSeconds),
|
||||||
@ -403,7 +402,7 @@ func InitTestSchedulerWithOptions(
|
|||||||
})
|
})
|
||||||
|
|
||||||
if policy != nil {
|
if policy != nil {
|
||||||
opts = append(opts, scheduler.WithAlgorithmSource(CreateAlgorithmSourceFromPolicy(policy, testCtx.ClientSet)))
|
opts = append(opts, scheduler.WithLegacyPolicySource(CreateSchedulerPolicySource(policy, testCtx.ClientSet)))
|
||||||
}
|
}
|
||||||
opts = append(opts, scheduler.WithKubeConfig(testCtx.KubeConfig))
|
opts = append(opts, scheduler.WithKubeConfig(testCtx.KubeConfig))
|
||||||
testCtx.Scheduler, err = scheduler.New(
|
testCtx.Scheduler, err = scheduler.New(
|
||||||
@ -424,8 +423,8 @@ func InitTestSchedulerWithOptions(
|
|||||||
return testCtx
|
return testCtx
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateAlgorithmSourceFromPolicy creates the schedulerAlgorithmSource from the policy parameter
|
// CreateSchedulerPolicySource creates a source from the given policy.
|
||||||
func CreateAlgorithmSourceFromPolicy(policy *schedulerapi.Policy, clientSet clientset.Interface) schedulerapi.SchedulerAlgorithmSource {
|
func CreateSchedulerPolicySource(policy *schedulerapi.Policy, clientSet clientset.Interface) *schedulerapi.SchedulerPolicySource {
|
||||||
// Serialize the Policy object into a ConfigMap later.
|
// Serialize the Policy object into a ConfigMap later.
|
||||||
info, ok := runtime.SerializerInfoForMediaType(scheme.Codecs.SupportedMediaTypes(), runtime.ContentTypeJSON)
|
info, ok := runtime.SerializerInfoForMediaType(scheme.Codecs.SupportedMediaTypes(), runtime.ContentTypeJSON)
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -441,12 +440,10 @@ func CreateAlgorithmSourceFromPolicy(policy *schedulerapi.Policy, clientSet clie
|
|||||||
policyConfigMap.APIVersion = "v1"
|
policyConfigMap.APIVersion = "v1"
|
||||||
clientSet.CoreV1().ConfigMaps(metav1.NamespaceSystem).Create(context.TODO(), &policyConfigMap, metav1.CreateOptions{})
|
clientSet.CoreV1().ConfigMaps(metav1.NamespaceSystem).Create(context.TODO(), &policyConfigMap, metav1.CreateOptions{})
|
||||||
|
|
||||||
return schedulerapi.SchedulerAlgorithmSource{
|
return &schedulerapi.SchedulerPolicySource{
|
||||||
Policy: &schedulerapi.SchedulerPolicySource{
|
ConfigMap: &schedulerapi.SchedulerPolicyConfigMapSource{
|
||||||
ConfigMap: &schedulerapi.SchedulerPolicyConfigMapSource{
|
Namespace: policyConfigMap.Namespace,
|
||||||
Namespace: policyConfigMap.Namespace,
|
Name: policyConfigMap.Name,
|
||||||
Name: policyConfigMap.Name,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user