mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-01 07:47:56 +00:00
Disable pod preemption by config
This commit is contained in:
parent
dfd6f581b5
commit
4f0bd4121e
@ -381,6 +381,8 @@ type SchedulerServer struct {
|
|||||||
HealthzServer *http.Server
|
HealthzServer *http.Server
|
||||||
// MetricsServer is optional.
|
// MetricsServer is optional.
|
||||||
MetricsServer *http.Server
|
MetricsServer *http.Server
|
||||||
|
// Disable pod preemption or not.
|
||||||
|
DisablePreemption bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSchedulerServer creates a runnable SchedulerServer from configuration.
|
// NewSchedulerServer creates a runnable SchedulerServer from configuration.
|
||||||
@ -445,6 +447,7 @@ func NewSchedulerServer(config *componentconfig.KubeSchedulerConfiguration, mast
|
|||||||
LeaderElection: leaderElectionConfig,
|
LeaderElection: leaderElectionConfig,
|
||||||
HealthzServer: healthzServer,
|
HealthzServer: healthzServer,
|
||||||
MetricsServer: metricsServer,
|
MetricsServer: metricsServer,
|
||||||
|
DisablePreemption: config.DisablePreemption,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -659,6 +662,7 @@ func (s *SchedulerServer) SchedulerConfig() (*scheduler.Config, error) {
|
|||||||
storageClassInformer,
|
storageClassInformer,
|
||||||
s.HardPodAffinitySymmetricWeight,
|
s.HardPodAffinitySymmetricWeight,
|
||||||
utilfeature.DefaultFeatureGate.Enabled(features.EnableEquivalenceClassCache),
|
utilfeature.DefaultFeatureGate.Enabled(features.EnableEquivalenceClassCache),
|
||||||
|
s.DisablePreemption,
|
||||||
)
|
)
|
||||||
|
|
||||||
source := s.AlgorithmSource
|
source := s.AlgorithmSource
|
||||||
@ -716,5 +720,7 @@ func (s *SchedulerServer) SchedulerConfig() (*scheduler.Config, error) {
|
|||||||
}
|
}
|
||||||
// Additional tweaks to the config produced by the configurator.
|
// Additional tweaks to the config produced by the configurator.
|
||||||
config.Recorder = s.Recorder
|
config.Recorder = s.Recorder
|
||||||
|
|
||||||
|
config.DisablePreemption = s.DisablePreemption
|
||||||
return config, nil
|
return config, nil
|
||||||
}
|
}
|
||||||
|
@ -111,6 +111,9 @@ type KubeSchedulerConfiguration struct {
|
|||||||
// Indicate the "all topologies" set for empty topologyKey when it's used for PreferredDuringScheduling pod anti-affinity.
|
// Indicate the "all topologies" set for empty topologyKey when it's used for PreferredDuringScheduling pod anti-affinity.
|
||||||
// DEPRECATED: This is no longer used.
|
// DEPRECATED: This is no longer used.
|
||||||
FailureDomains string
|
FailureDomains string
|
||||||
|
|
||||||
|
// DisablePreemption disables the pod preemption feature.
|
||||||
|
DisablePreemption bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// KubeSchedulerLeaderElectionConfiguration expands LeaderElectionConfiguration
|
// KubeSchedulerLeaderElectionConfiguration expands LeaderElectionConfiguration
|
||||||
|
@ -106,6 +106,9 @@ type KubeSchedulerConfiguration struct {
|
|||||||
|
|
||||||
// Indicate the "all topologies" set for empty topologyKey when it's used for PreferredDuringScheduling pod anti-affinity.
|
// Indicate the "all topologies" set for empty topologyKey when it's used for PreferredDuringScheduling pod anti-affinity.
|
||||||
FailureDomains string `json:"failureDomains"`
|
FailureDomains string `json:"failureDomains"`
|
||||||
|
|
||||||
|
// DisablePreemption disables the pod preemption feature.
|
||||||
|
DisablePreemption bool `json:"disablePreemption"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// LeaderElectionConfiguration defines the configuration of leader election
|
// LeaderElectionConfiguration defines the configuration of leader election
|
||||||
|
@ -309,6 +309,7 @@ func autoConvert_v1alpha1_KubeSchedulerConfiguration_To_componentconfig_KubeSche
|
|||||||
out.EnableProfiling = in.EnableProfiling
|
out.EnableProfiling = in.EnableProfiling
|
||||||
out.EnableContentionProfiling = in.EnableContentionProfiling
|
out.EnableContentionProfiling = in.EnableContentionProfiling
|
||||||
out.FailureDomains = in.FailureDomains
|
out.FailureDomains = in.FailureDomains
|
||||||
|
out.DisablePreemption = in.DisablePreemption
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -334,6 +335,7 @@ func autoConvert_componentconfig_KubeSchedulerConfiguration_To_v1alpha1_KubeSche
|
|||||||
out.EnableProfiling = in.EnableProfiling
|
out.EnableProfiling = in.EnableProfiling
|
||||||
out.EnableContentionProfiling = in.EnableContentionProfiling
|
out.EnableContentionProfiling = in.EnableContentionProfiling
|
||||||
out.FailureDomains = in.FailureDomains
|
out.FailureDomains = in.FailureDomains
|
||||||
|
out.DisablePreemption = in.DisablePreemption
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -579,6 +579,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
|
|||||||
informerFactory.Storage().V1().StorageClasses(),
|
informerFactory.Storage().V1().StorageClasses(),
|
||||||
v1.DefaultHardPodAffinitySymmetricWeight,
|
v1.DefaultHardPodAffinitySymmetricWeight,
|
||||||
enableEquivalenceCache,
|
enableEquivalenceCache,
|
||||||
|
false,
|
||||||
).CreateFromConfig(policy); err != nil {
|
).CreateFromConfig(policy); err != nil {
|
||||||
t.Errorf("%s: Error constructing: %v", v, err)
|
t.Errorf("%s: Error constructing: %v", v, err)
|
||||||
continue
|
continue
|
||||||
|
@ -506,7 +506,18 @@ func TestGenericSchedulerWithExtenders(t *testing.T) {
|
|||||||
}
|
}
|
||||||
queue := NewSchedulingQueue()
|
queue := NewSchedulingQueue()
|
||||||
scheduler := NewGenericScheduler(
|
scheduler := NewGenericScheduler(
|
||||||
cache, nil, queue, test.predicates, algorithm.EmptyPredicateMetadataProducer, test.prioritizers, algorithm.EmptyPriorityMetadataProducer, extenders, nil, schedulertesting.FakePersistentVolumeClaimLister{}, false)
|
cache,
|
||||||
|
nil,
|
||||||
|
queue,
|
||||||
|
test.predicates,
|
||||||
|
algorithm.EmptyPredicateMetadataProducer,
|
||||||
|
test.prioritizers,
|
||||||
|
algorithm.EmptyPriorityMetadataProducer,
|
||||||
|
extenders,
|
||||||
|
nil,
|
||||||
|
schedulertesting.FakePersistentVolumeClaimLister{},
|
||||||
|
false,
|
||||||
|
false)
|
||||||
podIgnored := &v1.Pod{}
|
podIgnored := &v1.Pod{}
|
||||||
machine, err := scheduler.Schedule(podIgnored, schedulertesting.FakeNodeLister(makeNodeList(test.nodes)))
|
machine, err := scheduler.Schedule(podIgnored, schedulertesting.FakeNodeLister(makeNodeList(test.nodes)))
|
||||||
if test.expectsErr {
|
if test.expectsErr {
|
||||||
|
@ -98,6 +98,7 @@ type genericScheduler struct {
|
|||||||
cachedNodeInfoMap map[string]*schedulercache.NodeInfo
|
cachedNodeInfoMap map[string]*schedulercache.NodeInfo
|
||||||
volumeBinder *volumebinder.VolumeBinder
|
volumeBinder *volumebinder.VolumeBinder
|
||||||
pvcLister corelisters.PersistentVolumeClaimLister
|
pvcLister corelisters.PersistentVolumeClaimLister
|
||||||
|
disablePreemption bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Schedule tries to schedule the given pod to one of the nodes in the node list.
|
// Schedule tries to schedule the given pod to one of the nodes in the node list.
|
||||||
@ -1107,7 +1108,9 @@ func NewGenericScheduler(
|
|||||||
extenders []algorithm.SchedulerExtender,
|
extenders []algorithm.SchedulerExtender,
|
||||||
volumeBinder *volumebinder.VolumeBinder,
|
volumeBinder *volumebinder.VolumeBinder,
|
||||||
pvcLister corelisters.PersistentVolumeClaimLister,
|
pvcLister corelisters.PersistentVolumeClaimLister,
|
||||||
alwaysCheckAllPredicates bool) algorithm.ScheduleAlgorithm {
|
alwaysCheckAllPredicates bool,
|
||||||
|
disablePreemption bool,
|
||||||
|
) algorithm.ScheduleAlgorithm {
|
||||||
return &genericScheduler{
|
return &genericScheduler{
|
||||||
cache: cache,
|
cache: cache,
|
||||||
equivalenceCache: eCache,
|
equivalenceCache: eCache,
|
||||||
@ -1121,5 +1124,6 @@ func NewGenericScheduler(
|
|||||||
volumeBinder: volumeBinder,
|
volumeBinder: volumeBinder,
|
||||||
pvcLister: pvcLister,
|
pvcLister: pvcLister,
|
||||||
alwaysCheckAllPredicates: alwaysCheckAllPredicates,
|
alwaysCheckAllPredicates: alwaysCheckAllPredicates,
|
||||||
|
disablePreemption: disablePreemption,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -409,7 +409,18 @@ func TestGenericScheduler(t *testing.T) {
|
|||||||
pvcLister := schedulertesting.FakePersistentVolumeClaimLister(pvcs)
|
pvcLister := schedulertesting.FakePersistentVolumeClaimLister(pvcs)
|
||||||
|
|
||||||
scheduler := NewGenericScheduler(
|
scheduler := NewGenericScheduler(
|
||||||
cache, nil, NewSchedulingQueue(), test.predicates, algorithm.EmptyPredicateMetadataProducer, test.prioritizers, algorithm.EmptyPriorityMetadataProducer, []algorithm.SchedulerExtender{}, nil, pvcLister, test.alwaysCheckAllPredicates)
|
cache,
|
||||||
|
nil,
|
||||||
|
NewSchedulingQueue(),
|
||||||
|
test.predicates,
|
||||||
|
algorithm.EmptyPredicateMetadataProducer,
|
||||||
|
test.prioritizers,
|
||||||
|
algorithm.EmptyPriorityMetadataProducer,
|
||||||
|
[]algorithm.SchedulerExtender{},
|
||||||
|
nil,
|
||||||
|
pvcLister,
|
||||||
|
test.alwaysCheckAllPredicates,
|
||||||
|
false)
|
||||||
machine, err := scheduler.Schedule(test.pod, schedulertesting.FakeNodeLister(makeNodeList(test.nodes)))
|
machine, err := scheduler.Schedule(test.pod, schedulertesting.FakeNodeLister(makeNodeList(test.nodes)))
|
||||||
|
|
||||||
if !reflect.DeepEqual(err, test.wErr) {
|
if !reflect.DeepEqual(err, test.wErr) {
|
||||||
@ -1323,7 +1334,18 @@ func TestPreempt(t *testing.T) {
|
|||||||
extenders = append(extenders, extender)
|
extenders = append(extenders, extender)
|
||||||
}
|
}
|
||||||
scheduler := NewGenericScheduler(
|
scheduler := NewGenericScheduler(
|
||||||
cache, nil, NewSchedulingQueue(), map[string]algorithm.FitPredicate{"matches": algorithmpredicates.PodFitsResources}, algorithm.EmptyPredicateMetadataProducer, []algorithm.PriorityConfig{{Function: numericPriority, Weight: 1}}, algorithm.EmptyPriorityMetadataProducer, extenders, nil, schedulertesting.FakePersistentVolumeClaimLister{}, false)
|
cache,
|
||||||
|
nil,
|
||||||
|
NewSchedulingQueue(),
|
||||||
|
map[string]algorithm.FitPredicate{"matches": algorithmpredicates.PodFitsResources},
|
||||||
|
algorithm.EmptyPredicateMetadataProducer,
|
||||||
|
[]algorithm.PriorityConfig{{Function: numericPriority, Weight: 1}},
|
||||||
|
algorithm.EmptyPriorityMetadataProducer,
|
||||||
|
extenders,
|
||||||
|
nil,
|
||||||
|
schedulertesting.FakePersistentVolumeClaimLister{},
|
||||||
|
false,
|
||||||
|
false)
|
||||||
// Call Preempt and check the expected results.
|
// Call Preempt and check the expected results.
|
||||||
node, victims, _, err := scheduler.Preempt(test.pod, schedulertesting.FakeNodeLister(makeNodeList(nodeNames)), error(&FitError{Pod: test.pod, FailedPredicates: failedPredMap}))
|
node, victims, _, err := scheduler.Preempt(test.pod, schedulertesting.FakeNodeLister(makeNodeList(nodeNames)), error(&FitError{Pod: test.pod, FailedPredicates: failedPredMap}))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -133,6 +133,9 @@ type configFactory struct {
|
|||||||
|
|
||||||
// always check all predicates even if the middle of one predicate fails.
|
// always check all predicates even if the middle of one predicate fails.
|
||||||
alwaysCheckAllPredicates bool
|
alwaysCheckAllPredicates bool
|
||||||
|
|
||||||
|
// Disable pod preemption or not.
|
||||||
|
disablePreemption bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewConfigFactory initializes the default implementation of a Configurator To encourage eventual privatization of the struct type, we only
|
// NewConfigFactory initializes the default implementation of a Configurator To encourage eventual privatization of the struct type, we only
|
||||||
@ -152,6 +155,7 @@ func NewConfigFactory(
|
|||||||
storageClassInformer storageinformers.StorageClassInformer,
|
storageClassInformer storageinformers.StorageClassInformer,
|
||||||
hardPodAffinitySymmetricWeight int32,
|
hardPodAffinitySymmetricWeight int32,
|
||||||
enableEquivalenceClassCache bool,
|
enableEquivalenceClassCache bool,
|
||||||
|
disablePreemption bool,
|
||||||
) scheduler.Configurator {
|
) scheduler.Configurator {
|
||||||
stopEverything := make(chan struct{})
|
stopEverything := make(chan struct{})
|
||||||
schedulerCache := schedulercache.New(30*time.Second, stopEverything)
|
schedulerCache := schedulercache.New(30*time.Second, stopEverything)
|
||||||
@ -179,6 +183,7 @@ func NewConfigFactory(
|
|||||||
schedulerName: schedulerName,
|
schedulerName: schedulerName,
|
||||||
hardPodAffinitySymmetricWeight: hardPodAffinitySymmetricWeight,
|
hardPodAffinitySymmetricWeight: hardPodAffinitySymmetricWeight,
|
||||||
enableEquivalenceClassCache: enableEquivalenceClassCache,
|
enableEquivalenceClassCache: enableEquivalenceClassCache,
|
||||||
|
disablePreemption: disablePreemption,
|
||||||
}
|
}
|
||||||
|
|
||||||
c.scheduledPodsHasSynced = podInformer.Informer().HasSynced
|
c.scheduledPodsHasSynced = podInformer.Informer().HasSynced
|
||||||
@ -1064,7 +1069,20 @@ func (c *configFactory) CreateFromKeys(predicateKeys, priorityKeys sets.String,
|
|||||||
glog.Info("Created equivalence class cache")
|
glog.Info("Created equivalence class cache")
|
||||||
}
|
}
|
||||||
|
|
||||||
algo := core.NewGenericScheduler(c.schedulerCache, c.equivalencePodCache, c.podQueue, predicateFuncs, predicateMetaProducer, priorityConfigs, priorityMetaProducer, extenders, c.volumeBinder, c.pVCLister, c.alwaysCheckAllPredicates)
|
algo := core.NewGenericScheduler(
|
||||||
|
c.schedulerCache,
|
||||||
|
c.equivalencePodCache,
|
||||||
|
c.podQueue,
|
||||||
|
predicateFuncs,
|
||||||
|
predicateMetaProducer,
|
||||||
|
priorityConfigs,
|
||||||
|
priorityMetaProducer,
|
||||||
|
extenders,
|
||||||
|
c.volumeBinder,
|
||||||
|
c.pVCLister,
|
||||||
|
c.alwaysCheckAllPredicates,
|
||||||
|
c.disablePreemption,
|
||||||
|
)
|
||||||
|
|
||||||
podBackoff := util.CreateDefaultPodBackoff()
|
podBackoff := util.CreateDefaultPodBackoff()
|
||||||
return &scheduler.Config{
|
return &scheduler.Config{
|
||||||
|
@ -46,7 +46,10 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/scheduler/util"
|
"k8s.io/kubernetes/pkg/scheduler/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
const enableEquivalenceCache = true
|
const (
|
||||||
|
enableEquivalenceCache = true
|
||||||
|
disablePodPreemption = false
|
||||||
|
)
|
||||||
|
|
||||||
func TestCreate(t *testing.T) {
|
func TestCreate(t *testing.T) {
|
||||||
handler := utiltesting.FakeHandler{
|
handler := utiltesting.FakeHandler{
|
||||||
@ -533,6 +536,7 @@ func newConfigFactory(client *clientset.Clientset, hardPodAffinitySymmetricWeigh
|
|||||||
informerFactory.Storage().V1().StorageClasses(),
|
informerFactory.Storage().V1().StorageClasses(),
|
||||||
hardPodAffinitySymmetricWeight,
|
hardPodAffinitySymmetricWeight,
|
||||||
enableEquivalenceCache,
|
enableEquivalenceCache,
|
||||||
|
disablePodPreemption,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,6 +137,9 @@ type Config struct {
|
|||||||
|
|
||||||
// VolumeBinder handles PVC/PV binding for the pod.
|
// VolumeBinder handles PVC/PV binding for the pod.
|
||||||
VolumeBinder *volumebinder.VolumeBinder
|
VolumeBinder *volumebinder.VolumeBinder
|
||||||
|
|
||||||
|
// Disable pod preemption or not.
|
||||||
|
DisablePreemption bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewFromConfigurator returns a new scheduler that is created entirely by the Configurator. Assumes Create() is implemented.
|
// NewFromConfigurator returns a new scheduler that is created entirely by the Configurator. Assumes Create() is implemented.
|
||||||
@ -207,8 +210,9 @@ func (sched *Scheduler) schedule(pod *v1.Pod) (string, error) {
|
|||||||
// If it succeeds, it adds the name of the node where preemption has happened to the pod annotations.
|
// If it succeeds, it adds the name of the node where preemption has happened to the pod annotations.
|
||||||
// It returns the node name and an error if any.
|
// It returns the node name and an error if any.
|
||||||
func (sched *Scheduler) preempt(preemptor *v1.Pod, scheduleErr error) (string, error) {
|
func (sched *Scheduler) preempt(preemptor *v1.Pod, scheduleErr error) (string, error) {
|
||||||
if !util.PodPriorityEnabled() {
|
if !util.PodPriorityEnabled() || sched.config.DisablePreemption {
|
||||||
glog.V(3).Infof("Pod priority feature is not enabled. No preemption is performed.")
|
glog.V(3).Infof("Pod priority feature is not enabled or preemption is disabled by scheduler configuration." +
|
||||||
|
" No preemption is performed.")
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
preemptor, err := sched.config.PodPreemptor.GetUpdatedPod(preemptor)
|
preemptor, err := sched.config.PodPreemptor.GetUpdatedPod(preemptor)
|
||||||
|
@ -548,6 +548,7 @@ func setupTestScheduler(queuedPodStore *clientcache.FIFO, scache schedulercache.
|
|||||||
[]algorithm.SchedulerExtender{},
|
[]algorithm.SchedulerExtender{},
|
||||||
nil,
|
nil,
|
||||||
schedulertesting.FakePersistentVolumeClaimLister{},
|
schedulertesting.FakePersistentVolumeClaimLister{},
|
||||||
|
false,
|
||||||
false)
|
false)
|
||||||
bindingChan := make(chan *v1.Binding, 1)
|
bindingChan := make(chan *v1.Binding, 1)
|
||||||
errChan := make(chan error, 1)
|
errChan := make(chan error, 1)
|
||||||
@ -596,6 +597,7 @@ func setupTestSchedulerLongBindingWithRetry(queuedPodStore *clientcache.FIFO, sc
|
|||||||
[]algorithm.SchedulerExtender{},
|
[]algorithm.SchedulerExtender{},
|
||||||
nil,
|
nil,
|
||||||
schedulertesting.FakePersistentVolumeClaimLister{},
|
schedulertesting.FakePersistentVolumeClaimLister{},
|
||||||
|
false,
|
||||||
false)
|
false)
|
||||||
bindingChan := make(chan *v1.Binding, 2)
|
bindingChan := make(chan *v1.Binding, 2)
|
||||||
configurator := &FakeConfigurator{
|
configurator := &FakeConfigurator{
|
||||||
|
@ -85,6 +85,7 @@ func createConfiguratorWithPodInformer(
|
|||||||
informerFactory.Storage().V1().StorageClasses(),
|
informerFactory.Storage().V1().StorageClasses(),
|
||||||
v1.DefaultHardPodAffinitySymmetricWeight,
|
v1.DefaultHardPodAffinitySymmetricWeight,
|
||||||
utilfeature.DefaultFeatureGate.Enabled(features.EnableEquivalenceClassCache),
|
utilfeature.DefaultFeatureGate.Enabled(features.EnableEquivalenceClassCache),
|
||||||
|
false,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,5 +112,6 @@ func createSchedulerConfigurator(
|
|||||||
informerFactory.Storage().V1().StorageClasses(),
|
informerFactory.Storage().V1().StorageClasses(),
|
||||||
v1.DefaultHardPodAffinitySymmetricWeight,
|
v1.DefaultHardPodAffinitySymmetricWeight,
|
||||||
utilfeature.DefaultFeatureGate.Enabled(features.EnableEquivalenceClassCache),
|
utilfeature.DefaultFeatureGate.Enabled(features.EnableEquivalenceClassCache),
|
||||||
|
false,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user