diff --git a/cmd/kube-scheduler/app/options/options_test.go b/cmd/kube-scheduler/app/options/options_test.go index 34cd2404231..b20fb0b0f8c 100644 --- a/cmd/kube-scheduler/app/options/options_test.go +++ b/cmd/kube-scheduler/app/options/options_test.go @@ -225,8 +225,7 @@ users: Burst: 100, ContentType: "application/vnd.kubernetes.protobuf", }, - PercentageOfNodesToScore: 50, - BindTimeoutSeconds: &defaultBindTimeoutSeconds, + BindTimeoutSeconds: &defaultBindTimeoutSeconds, }, }, { @@ -306,8 +305,7 @@ users: Burst: 100, ContentType: "application/vnd.kubernetes.protobuf", }, - PercentageOfNodesToScore: 50, - BindTimeoutSeconds: &defaultBindTimeoutSeconds, + BindTimeoutSeconds: &defaultBindTimeoutSeconds, }, }, { diff --git a/pkg/scheduler/apis/config/types.go b/pkg/scheduler/apis/config/types.go index 1c5fee16b8b..b0d36cd31b2 100644 --- a/pkg/scheduler/apis/config/types.go +++ b/pkg/scheduler/apis/config/types.go @@ -79,7 +79,8 @@ type KubeSchedulerConfiguration struct { // at least "minFeasibleNodesToFind" feasible nodes no matter what the value of this flag is. // Example: if the cluster size is 500 nodes and the value of this flag is 30, // then scheduler stops finding further feasible nodes once it finds 150 feasible ones. - // When the value is 0, default percentage (50%) of the nodes will be scored. + // When the value is 0, default percentage (5%--50% based on the size of the cluster) of the + // nodes will be scored. PercentageOfNodesToScore int32 // DEPRECATED. diff --git a/pkg/scheduler/apis/config/v1alpha1/defaults.go b/pkg/scheduler/apis/config/v1alpha1/defaults.go index e212dcf4370..5768d2334b7 100644 --- a/pkg/scheduler/apis/config/v1alpha1/defaults.go +++ b/pkg/scheduler/apis/config/v1alpha1/defaults.go @@ -81,11 +81,6 @@ func SetDefaults_KubeSchedulerConfiguration(obj *kubescedulerconfigv1alpha1.Kube obj.LeaderElection.LockObjectName = kubescedulerconfigv1alpha1.SchedulerDefaultLockObjectName } - if obj.PercentageOfNodesToScore == 0 { - // by default, stop finding feasible nodes once the number of feasible nodes is 50% of the cluster. - obj.PercentageOfNodesToScore = 50 - } - if len(obj.FailureDomains) == 0 { obj.FailureDomains = kubeletapis.DefaultFailureDomains } diff --git a/pkg/scheduler/core/generic_scheduler.go b/pkg/scheduler/core/generic_scheduler.go index c7bbbe47b8e..6e28e3c348b 100644 --- a/pkg/scheduler/core/generic_scheduler.go +++ b/pkg/scheduler/core/generic_scheduler.go @@ -54,6 +54,11 @@ const ( // certain minimum of nodes are checked for feasibility. This in turn helps // ensure a minimum level of spreading. minFeasibleNodesToFind = 100 + // minFeasibleNodesPercentageToFind is the minimum percentage of nodes that + // would be scored in each scheduling cycle. This is a semi-arbitrary value + // to ensure that a certain minimum of nodes are checked for feasibility. + // This in turn helps ensure a minimum level of spreading. + minFeasibleNodesPercentageToFind = 5 ) // FailedPredicateMap declares a map[string][]algorithm.PredicateFailureReason type. @@ -375,15 +380,24 @@ func (g *genericScheduler) getLowerPriorityNominatedPods(pod *v1.Pod, nodeName s // numFeasibleNodesToFind returns the number of feasible nodes that once found, the scheduler stops // its search for more feasible nodes. -func (g *genericScheduler) numFeasibleNodesToFind(numAllNodes int32) int32 { - if numAllNodes < minFeasibleNodesToFind || g.percentageOfNodesToScore <= 0 || - g.percentageOfNodesToScore >= 100 { +func (g *genericScheduler) numFeasibleNodesToFind(numAllNodes int32) (numNodes int32) { + if numAllNodes < minFeasibleNodesToFind || g.percentageOfNodesToScore >= 100 { return numAllNodes } - numNodes := numAllNodes * g.percentageOfNodesToScore / 100 + + adaptivePercentage := g.percentageOfNodesToScore + if adaptivePercentage <= 0 { + adaptivePercentage = schedulerapi.DefaultPercentageOfNodesToScore - numAllNodes/125 + if adaptivePercentage < minFeasibleNodesPercentageToFind { + adaptivePercentage = minFeasibleNodesPercentageToFind + } + } + + numNodes = numAllNodes * adaptivePercentage / 100 if numNodes < minFeasibleNodesToFind { return minFeasibleNodesToFind } + return numNodes } diff --git a/pkg/scheduler/core/generic_scheduler_test.go b/pkg/scheduler/core/generic_scheduler_test.go index fc168e3b13f..7680a3aba13 100644 --- a/pkg/scheduler/core/generic_scheduler_test.go +++ b/pkg/scheduler/core/generic_scheduler_test.go @@ -1483,3 +1483,56 @@ func TestPreempt(t *testing.T) { }) } } + +func TestNumFeasibleNodesToFind(t *testing.T) { + tests := []struct { + name string + percentageOfNodesToScore int32 + numAllNodes int32 + wantNumNodes int32 + }{ + { + name: "not set percentageOfNodesToScore and nodes number not more than 50", + numAllNodes: 10, + wantNumNodes: 10, + }, + { + name: "set percentageOfNodesToScore and nodes number not more than 50", + percentageOfNodesToScore: 40, + numAllNodes: 10, + wantNumNodes: 10, + }, + { + name: "not set percentageOfNodesToScore and nodes number more than 50", + numAllNodes: 1000, + wantNumNodes: 420, + }, + { + name: "set percentageOfNodesToScore and nodes number more than 50", + percentageOfNodesToScore: 40, + numAllNodes: 1000, + wantNumNodes: 400, + }, + { + name: "not set percentageOfNodesToScore and nodes number more than 50*125", + numAllNodes: 6000, + wantNumNodes: 300, + }, + { + name: "set percentageOfNodesToScore and nodes number more than 50*125", + percentageOfNodesToScore: 40, + numAllNodes: 6000, + wantNumNodes: 2400, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + g := &genericScheduler{ + percentageOfNodesToScore: tt.percentageOfNodesToScore, + } + if gotNumNodes := g.numFeasibleNodesToFind(tt.numAllNodes); gotNumNodes != tt.wantNumNodes { + t.Errorf("genericScheduler.numFeasibleNodesToFind() = %v, want %v", gotNumNodes, tt.wantNumNodes) + } + }) + } +} diff --git a/staging/src/k8s.io/kube-scheduler/config/v1alpha1/types.go b/staging/src/k8s.io/kube-scheduler/config/v1alpha1/types.go index 811e4062ae9..6bdb5500d6d 100644 --- a/staging/src/k8s.io/kube-scheduler/config/v1alpha1/types.go +++ b/staging/src/k8s.io/kube-scheduler/config/v1alpha1/types.go @@ -75,7 +75,8 @@ type KubeSchedulerConfiguration struct { // at least "minFeasibleNodesToFind" feasible nodes no matter what the value of this flag is. // Example: if the cluster size is 500 nodes and the value of this flag is 30, // then scheduler stops finding further feasible nodes once it finds 150 feasible ones. - // When the value is 0, default percentage (50%) of the nodes will be scored. + // When the value is 0, default percentage (5%--50% based on the size of the cluster) of the + // nodes will be scored. PercentageOfNodesToScore int32 `json:"percentageOfNodesToScore"` // DEPRECATED.