register_priorities.go 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. Copyright 2018 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package defaults
  14. import (
  15. "k8s.io/kubernetes/pkg/scheduler/algorithm"
  16. "k8s.io/kubernetes/pkg/scheduler/algorithm/priorities"
  17. "k8s.io/kubernetes/pkg/scheduler/core"
  18. "k8s.io/kubernetes/pkg/scheduler/factory"
  19. )
  20. func init() {
  21. // Register functions that extract metadata used by priorities computations.
  22. factory.RegisterPriorityMetadataProducerFactory(
  23. func(args factory.PluginFactoryArgs) priorities.PriorityMetadataProducer {
  24. return priorities.NewPriorityMetadataFactory(args.ServiceLister, args.ControllerLister, args.ReplicaSetLister, args.StatefulSetLister)
  25. })
  26. // ServiceSpreadingPriority is a priority config factory that spreads pods by minimizing
  27. // the number of pods (belonging to the same service) on the same node.
  28. // Register the factory so that it's available, but do not include it as part of the default priorities
  29. // Largely replaced by "SelectorSpreadPriority", but registered for backward compatibility with 1.0
  30. factory.RegisterPriorityConfigFactory(
  31. priorities.ServiceSpreadingPriority,
  32. factory.PriorityConfigFactory{
  33. MapReduceFunction: func(args factory.PluginFactoryArgs) (priorities.PriorityMapFunction, priorities.PriorityReduceFunction) {
  34. return priorities.NewSelectorSpreadPriority(args.ServiceLister, algorithm.EmptyControllerLister{}, algorithm.EmptyReplicaSetLister{}, algorithm.EmptyStatefulSetLister{})
  35. },
  36. Weight: 1,
  37. },
  38. )
  39. // EqualPriority is a prioritizer function that gives an equal weight of one to all nodes
  40. // Register the priority function so that its available
  41. // but do not include it as part of the default priorities
  42. factory.RegisterPriorityFunction2(priorities.EqualPriority, core.EqualPriorityMap, nil, 1)
  43. // Optional, cluster-autoscaler friendly priority function - give used nodes higher priority.
  44. factory.RegisterPriorityFunction2(priorities.MostRequestedPriority, priorities.MostRequestedPriorityMap, nil, 1)
  45. factory.RegisterPriorityFunction2(
  46. priorities.RequestedToCapacityRatioPriority,
  47. priorities.RequestedToCapacityRatioResourceAllocationPriorityDefault().PriorityMap,
  48. nil,
  49. 1)
  50. // spreads pods by minimizing the number of pods (belonging to the same service or replication controller) on the same node.
  51. factory.RegisterPriorityConfigFactory(
  52. priorities.SelectorSpreadPriority,
  53. factory.PriorityConfigFactory{
  54. MapReduceFunction: func(args factory.PluginFactoryArgs) (priorities.PriorityMapFunction, priorities.PriorityReduceFunction) {
  55. return priorities.NewSelectorSpreadPriority(args.ServiceLister, args.ControllerLister, args.ReplicaSetLister, args.StatefulSetLister)
  56. },
  57. Weight: 1,
  58. },
  59. )
  60. // pods should be placed in the same topological domain (e.g. same node, same rack, same zone, same power domain, etc.)
  61. // as some other pods, or, conversely, should not be placed in the same topological domain as some other pods.
  62. factory.RegisterPriorityConfigFactory(
  63. priorities.InterPodAffinityPriority,
  64. factory.PriorityConfigFactory{
  65. Function: func(args factory.PluginFactoryArgs) priorities.PriorityFunction {
  66. return priorities.NewInterPodAffinityPriority(args.NodeInfo, args.NodeLister, args.PodLister, args.HardPodAffinitySymmetricWeight)
  67. },
  68. Weight: 1,
  69. },
  70. )
  71. // Prioritize nodes by least requested utilization.
  72. factory.RegisterPriorityFunction2(priorities.LeastRequestedPriority, priorities.LeastRequestedPriorityMap, nil, 1)
  73. // Prioritize nodes by custom function from custom metrics
  74. factory.CustomRegisterPriorityFunction2(priorities.CustomRequestedPriority, priorities.CustomRequestedPriorityMap, nil, 1000000)
  75. // Prioritizes nodes to help achieve balanced resource usage
  76. factory.RegisterPriorityFunction2(priorities.BalancedResourceAllocation, priorities.BalancedResourceAllocationMap, nil, 1)
  77. // Set this weight large enough to override all other priority functions.
  78. // TODO: Figure out a better way to do this, maybe at same time as fixing #24720.
  79. factory.RegisterPriorityFunction2(priorities.NodePreferAvoidPodsPriority, priorities.CalculateNodePreferAvoidPodsPriorityMap, nil, 10000)
  80. // Prioritizes nodes that have labels matching NodeAffinity
  81. factory.RegisterPriorityFunction2(priorities.NodeAffinityPriority, priorities.CalculateNodeAffinityPriorityMap, priorities.CalculateNodeAffinityPriorityReduce, 1)
  82. // Prioritizes nodes that marked with taint which pod can tolerate.
  83. factory.RegisterPriorityFunction2(priorities.TaintTolerationPriority, priorities.ComputeTaintTolerationPriorityMap, priorities.ComputeTaintTolerationPriorityReduce, 1)
  84. // ImageLocalityPriority prioritizes nodes that have images requested by the pod present.
  85. factory.RegisterPriorityFunction2(priorities.ImageLocalityPriority, priorities.ImageLocalityPriorityMap, nil, 1)
  86. }