@@ -23,10 +23,8 @@ import (
23
23
utilfeature "k8s.io/apiserver/pkg/util/feature"
24
24
25
25
"k8s.io/kubernetes/pkg/features"
26
- "k8s.io/kubernetes/pkg/scheduler/algorithm"
27
26
"k8s.io/kubernetes/pkg/scheduler/algorithm/predicates"
28
27
"k8s.io/kubernetes/pkg/scheduler/algorithm/priorities"
29
- "k8s.io/kubernetes/pkg/scheduler/core"
30
28
"k8s.io/kubernetes/pkg/scheduler/factory"
31
29
)
32
30
@@ -36,139 +34,25 @@ const (
36
34
)
37
35
38
36
func init () {
39
- // Register functions that extract metadata used by predicates and priorities computations.
40
- factory .RegisterPredicateMetadataProducerFactory (
41
- func (args factory.PluginFactoryArgs ) predicates.PredicateMetadataProducer {
42
- return predicates .NewPredicateMetadataFactory (args .PodLister )
43
- })
44
- factory .RegisterPriorityMetadataProducerFactory (
45
- func (args factory.PluginFactoryArgs ) algorithm.PriorityMetadataProducer {
46
- return priorities .NewPriorityMetadataFactory (args .ServiceLister , args .ControllerLister , args .ReplicaSetLister , args .StatefulSetLister )
47
- })
48
-
49
37
registerAlgorithmProvider (defaultPredicates (), defaultPriorities ())
50
-
51
- // IMPORTANT NOTES for predicate developers:
52
- // Registers predicates and priorities that are not enabled by default, but user can pick when creating their
53
- // own set of priorities/predicates.
54
-
55
- // PodFitsPorts has been replaced by PodFitsHostPorts for better user understanding.
56
- // For backwards compatibility with 1.0, PodFitsPorts is registered as well.
57
- factory .RegisterFitPredicate ("PodFitsPorts" , predicates .PodFitsHostPorts )
58
- // Fit is defined based on the absence of port conflicts.
59
- // This predicate is actually a default predicate, because it is invoked from
60
- // predicates.GeneralPredicates()
61
- factory .RegisterFitPredicate (predicates .PodFitsHostPortsPred , predicates .PodFitsHostPorts )
62
- // Fit is determined by resource availability.
63
- // This predicate is actually a default predicate, because it is invoked from
64
- // predicates.GeneralPredicates()
65
- factory .RegisterFitPredicate (predicates .PodFitsResourcesPred , predicates .PodFitsResources )
66
- // Fit is determined by the presence of the Host parameter and a string match
67
- // This predicate is actually a default predicate, because it is invoked from
68
- // predicates.GeneralPredicates()
69
- factory .RegisterFitPredicate (predicates .HostNamePred , predicates .PodFitsHost )
70
- // Fit is determined by node selector query.
71
- factory .RegisterFitPredicate (predicates .MatchNodeSelectorPred , predicates .PodMatchNodeSelector )
72
-
73
- // ServiceSpreadingPriority is a priority config factory that spreads pods by minimizing
74
- // the number of pods (belonging to the same service) on the same node.
75
- // Register the factory so that it's available, but do not include it as part of the default priorities
76
- // Largely replaced by "SelectorSpreadPriority", but registered for backward compatibility with 1.0
77
- factory .RegisterPriorityConfigFactory (
78
- "ServiceSpreadingPriority" ,
79
- factory.PriorityConfigFactory {
80
- MapReduceFunction : func (args factory.PluginFactoryArgs ) (algorithm.PriorityMapFunction , algorithm.PriorityReduceFunction ) {
81
- return priorities .NewSelectorSpreadPriority (args .ServiceLister , algorithm.EmptyControllerLister {}, algorithm.EmptyReplicaSetLister {}, algorithm.EmptyStatefulSetLister {})
82
- },
83
- Weight : 1 ,
84
- },
85
- )
86
- // EqualPriority is a prioritizer function that gives an equal weight of one to all nodes
87
- // Register the priority function so that its available
88
- // but do not include it as part of the default priorities
89
- factory .RegisterPriorityFunction2 ("EqualPriority" , core .EqualPriorityMap , nil , 1 )
90
- // Optional, cluster-autoscaler friendly priority function - give used nodes higher priority.
91
- factory .RegisterPriorityFunction2 ("MostRequestedPriority" , priorities .MostRequestedPriorityMap , nil , 1 )
92
- factory .RegisterPriorityFunction2 (
93
- "RequestedToCapacityRatioPriority" ,
94
- priorities .RequestedToCapacityRatioResourceAllocationPriorityDefault ().PriorityMap ,
95
- nil ,
96
- 1 )
97
38
}
98
39
99
40
func defaultPredicates () sets.String {
100
41
return sets .NewString (
101
- // Fit is determined by volume zone requirements.
102
- factory .RegisterFitPredicateFactory (
103
- predicates .NoVolumeZoneConflictPred ,
104
- func (args factory.PluginFactoryArgs ) predicates.FitPredicate {
105
- return predicates .NewVolumeZonePredicate (args .PVInfo , args .PVCInfo , args .StorageClassInfo )
106
- },
107
- ),
108
- // Fit is determined by whether or not there would be too many AWS EBS volumes attached to the node
109
- factory .RegisterFitPredicateFactory (
110
- predicates .MaxEBSVolumeCountPred ,
111
- func (args factory.PluginFactoryArgs ) predicates.FitPredicate {
112
- return predicates .NewMaxPDVolumeCountPredicate (predicates .EBSVolumeFilterType , args .PVInfo , args .PVCInfo )
113
- },
114
- ),
115
- // Fit is determined by whether or not there would be too many GCE PD volumes attached to the node
116
- factory .RegisterFitPredicateFactory (
117
- predicates .MaxGCEPDVolumeCountPred ,
118
- func (args factory.PluginFactoryArgs ) predicates.FitPredicate {
119
- return predicates .NewMaxPDVolumeCountPredicate (predicates .GCEPDVolumeFilterType , args .PVInfo , args .PVCInfo )
120
- },
121
- ),
122
- // Fit is determined by whether or not there would be too many Azure Disk volumes attached to the node
123
- factory .RegisterFitPredicateFactory (
124
- predicates .MaxAzureDiskVolumeCountPred ,
125
- func (args factory.PluginFactoryArgs ) predicates.FitPredicate {
126
- return predicates .NewMaxPDVolumeCountPredicate (predicates .AzureDiskVolumeFilterType , args .PVInfo , args .PVCInfo )
127
- },
128
- ),
129
- factory .RegisterFitPredicateFactory (
130
- predicates .MaxCSIVolumeCountPred ,
131
- func (args factory.PluginFactoryArgs ) predicates.FitPredicate {
132
- return predicates .NewCSIMaxVolumeLimitPredicate (args .PVInfo , args .PVCInfo )
133
- },
134
- ),
135
- // Fit is determined by inter-pod affinity.
136
- factory .RegisterFitPredicateFactory (
137
- predicates .MatchInterPodAffinityPred ,
138
- func (args factory.PluginFactoryArgs ) predicates.FitPredicate {
139
- return predicates .NewPodAffinityPredicate (args .NodeInfo , args .PodLister )
140
- },
141
- ),
142
-
143
- // Fit is determined by non-conflicting disk volumes.
144
- factory .RegisterFitPredicate (predicates .NoDiskConflictPred , predicates .NoDiskConflict ),
145
-
146
- // GeneralPredicates are the predicates that are enforced by all Kubernetes components
147
- // (e.g. kubelet and all schedulers)
148
- factory .RegisterFitPredicate (predicates .GeneralPred , predicates .GeneralPredicates ),
149
-
150
- // Fit is determined by node memory pressure condition.
151
- factory .RegisterFitPredicate (predicates .CheckNodeMemoryPressurePred , predicates .CheckNodeMemoryPressurePredicate ),
152
-
153
- // Fit is determined by node disk pressure condition.
154
- factory .RegisterFitPredicate (predicates .CheckNodeDiskPressurePred , predicates .CheckNodeDiskPressurePredicate ),
155
-
156
- // Fit is determined by node pid pressure condition.
157
- factory .RegisterFitPredicate (predicates .CheckNodePIDPressurePred , predicates .CheckNodePIDPressurePredicate ),
158
-
159
- // Fit is determined by node conditions: not ready, network unavailable or out of disk.
160
- factory .RegisterMandatoryFitPredicate (predicates .CheckNodeConditionPred , predicates .CheckNodeConditionPredicate ),
161
-
162
- // Fit is determined based on whether a pod can tolerate all of the node's taints
163
- factory .RegisterFitPredicate (predicates .PodToleratesNodeTaintsPred , predicates .PodToleratesNodeTaints ),
164
-
165
- // Fit is determined by volume topology requirements.
166
- factory .RegisterFitPredicateFactory (
167
- predicates .CheckVolumeBindingPred ,
168
- func (args factory.PluginFactoryArgs ) predicates.FitPredicate {
169
- return predicates .NewVolumeBindingPredicate (args .VolumeBinder )
170
- },
171
- ),
42
+ predicates .NoVolumeZoneConflictPred ,
43
+ predicates .MaxEBSVolumeCountPred ,
44
+ predicates .MaxGCEPDVolumeCountPred ,
45
+ predicates .MaxAzureDiskVolumeCountPred ,
46
+ predicates .MaxCSIVolumeCountPred ,
47
+ predicates .MatchInterPodAffinityPred ,
48
+ predicates .NoDiskConflictPred ,
49
+ predicates .GeneralPred ,
50
+ predicates .CheckNodeMemoryPressurePred ,
51
+ predicates .CheckNodeDiskPressurePred ,
52
+ predicates .CheckNodePIDPressurePred ,
53
+ predicates .CheckNodeConditionPred ,
54
+ predicates .PodToleratesNodeTaintsPred ,
55
+ predicates .CheckVolumeBindingPred ,
172
56
)
173
57
}
174
58
@@ -206,9 +90,9 @@ func ApplyFeatureGates() {
206
90
// Prioritizes nodes that satisfy pod's resource limits
207
91
if utilfeature .DefaultFeatureGate .Enabled (features .ResourceLimitsPriorityFunction ) {
208
92
klog .Infof ("Registering resourcelimits priority function" )
209
- factory .RegisterPriorityFunction2 (" ResourceLimitsPriority" , priorities .ResourceLimitsPriorityMap , nil , 1 )
93
+ factory .RegisterPriorityFunction2 (priorities . ResourceLimitsPriority , priorities .ResourceLimitsPriorityMap , nil , 1 )
210
94
// Register the priority function to specific provider too.
211
- factory .InsertPriorityKeyToAlgorithmProviderMap (factory .RegisterPriorityFunction2 (" ResourceLimitsPriority" , priorities .ResourceLimitsPriorityMap , nil , 1 ))
95
+ factory .InsertPriorityKeyToAlgorithmProviderMap (factory .RegisterPriorityFunction2 (priorities . ResourceLimitsPriority , priorities .ResourceLimitsPriorityMap , nil , 1 ))
212
96
}
213
97
}
214
98
@@ -218,51 +102,19 @@ func registerAlgorithmProvider(predSet, priSet sets.String) {
218
102
factory .RegisterAlgorithmProvider (factory .DefaultProvider , predSet , priSet )
219
103
// Cluster autoscaler friendly scheduling algorithm.
220
104
factory .RegisterAlgorithmProvider (ClusterAutoscalerProvider , predSet ,
221
- copyAndReplace (priSet , " LeastRequestedPriority" , " MostRequestedPriority" ))
105
+ copyAndReplace (priSet , priorities . LeastRequestedPriority , priorities . MostRequestedPriority ))
222
106
}
223
107
224
108
func defaultPriorities () sets.String {
225
109
return sets .NewString (
226
- // spreads pods by minimizing the number of pods (belonging to the same service or replication controller) on the same node.
227
- factory .RegisterPriorityConfigFactory (
228
- "SelectorSpreadPriority" ,
229
- factory.PriorityConfigFactory {
230
- MapReduceFunction : func (args factory.PluginFactoryArgs ) (algorithm.PriorityMapFunction , algorithm.PriorityReduceFunction ) {
231
- return priorities .NewSelectorSpreadPriority (args .ServiceLister , args .ControllerLister , args .ReplicaSetLister , args .StatefulSetLister )
232
- },
233
- Weight : 1 ,
234
- },
235
- ),
236
- // pods should be placed in the same topological domain (e.g. same node, same rack, same zone, same power domain, etc.)
237
- // as some other pods, or, conversely, should not be placed in the same topological domain as some other pods.
238
- factory .RegisterPriorityConfigFactory (
239
- "InterPodAffinityPriority" ,
240
- factory.PriorityConfigFactory {
241
- Function : func (args factory.PluginFactoryArgs ) algorithm.PriorityFunction {
242
- return priorities .NewInterPodAffinityPriority (args .NodeInfo , args .NodeLister , args .PodLister , args .HardPodAffinitySymmetricWeight )
243
- },
244
- Weight : 1 ,
245
- },
246
- ),
247
-
248
- // Prioritize nodes by least requested utilization.
249
- factory .RegisterPriorityFunction2 ("LeastRequestedPriority" , priorities .LeastRequestedPriorityMap , nil , 1 ),
250
-
251
- // Prioritizes nodes to help achieve balanced resource usage
252
- factory .RegisterPriorityFunction2 ("BalancedResourceAllocation" , priorities .BalancedResourceAllocationMap , nil , 1 ),
253
-
254
- // Set this weight large enough to override all other priority functions.
255
- // TODO: Figure out a better way to do this, maybe at same time as fixing #24720.
256
- factory .RegisterPriorityFunction2 ("NodePreferAvoidPodsPriority" , priorities .CalculateNodePreferAvoidPodsPriorityMap , nil , 10000 ),
257
-
258
- // Prioritizes nodes that have labels matching NodeAffinity
259
- factory .RegisterPriorityFunction2 ("NodeAffinityPriority" , priorities .CalculateNodeAffinityPriorityMap , priorities .CalculateNodeAffinityPriorityReduce , 1 ),
260
-
261
- // Prioritizes nodes that marked with taint which pod can tolerate.
262
- factory .RegisterPriorityFunction2 ("TaintTolerationPriority" , priorities .ComputeTaintTolerationPriorityMap , priorities .ComputeTaintTolerationPriorityReduce , 1 ),
263
-
264
- // ImageLocalityPriority prioritizes nodes that have images requested by the pod present.
265
- factory .RegisterPriorityFunction2 ("ImageLocalityPriority" , priorities .ImageLocalityPriorityMap , nil , 1 ),
110
+ priorities .SelectorSpreadPriority ,
111
+ priorities .InterPodAffinityPriority ,
112
+ priorities .LeastRequestedPriority ,
113
+ priorities .BalancedResourceAllocation ,
114
+ priorities .NodePreferAvoidPodsPriority ,
115
+ priorities .NodeAffinityPriority ,
116
+ priorities .TaintTolerationPriority ,
117
+ priorities .ImageLocalityPriority ,
266
118
)
267
119
}
268
120
0 commit comments