mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 23:37:01 +00:00
Remove unnecessary podLister from SelectorSpreading
This commit is contained in:
parent
1ebf6e1acf
commit
daac9a1869
@ -39,19 +39,16 @@ const maxPriority float32 = 10
|
|||||||
const zoneWeighting = 2.0 / 3.0
|
const zoneWeighting = 2.0 / 3.0
|
||||||
|
|
||||||
type SelectorSpread struct {
|
type SelectorSpread struct {
|
||||||
podLister algorithm.PodLister
|
|
||||||
serviceLister algorithm.ServiceLister
|
serviceLister algorithm.ServiceLister
|
||||||
controllerLister algorithm.ControllerLister
|
controllerLister algorithm.ControllerLister
|
||||||
replicaSetLister algorithm.ReplicaSetLister
|
replicaSetLister algorithm.ReplicaSetLister
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSelectorSpreadPriority(
|
func NewSelectorSpreadPriority(
|
||||||
podLister algorithm.PodLister,
|
|
||||||
serviceLister algorithm.ServiceLister,
|
serviceLister algorithm.ServiceLister,
|
||||||
controllerLister algorithm.ControllerLister,
|
controllerLister algorithm.ControllerLister,
|
||||||
replicaSetLister algorithm.ReplicaSetLister) algorithm.PriorityFunction {
|
replicaSetLister algorithm.ReplicaSetLister) algorithm.PriorityFunction {
|
||||||
selectorSpread := &SelectorSpread{
|
selectorSpread := &SelectorSpread{
|
||||||
podLister: podLister,
|
|
||||||
serviceLister: serviceLister,
|
serviceLister: serviceLister,
|
||||||
controllerLister: controllerLister,
|
controllerLister: controllerLister,
|
||||||
replicaSetLister: replicaSetLister,
|
replicaSetLister: replicaSetLister,
|
||||||
@ -59,6 +56,32 @@ func NewSelectorSpreadPriority(
|
|||||||
return selectorSpread.CalculateSpreadPriority
|
return selectorSpread.CalculateSpreadPriority
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getSelectors(pod *api.Pod, sl algorithm.ServiceLister, cl algorithm.ControllerLister, rsl algorithm.ReplicaSetLister) []labels.Selector {
|
||||||
|
selectors := make([]labels.Selector, 0, 3)
|
||||||
|
if services, err := sl.GetPodServices(pod); err == nil {
|
||||||
|
for _, service := range services {
|
||||||
|
selectors = append(selectors, labels.SelectorFromSet(service.Spec.Selector))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if rcs, err := cl.GetPodControllers(pod); err == nil {
|
||||||
|
for _, rc := range rcs {
|
||||||
|
selectors = append(selectors, labels.SelectorFromSet(rc.Spec.Selector))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if rss, err := rsl.GetPodReplicaSets(pod); err == nil {
|
||||||
|
for _, rs := range rss {
|
||||||
|
if selector, err := unversioned.LabelSelectorAsSelector(rs.Spec.Selector); err == nil {
|
||||||
|
selectors = append(selectors, selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return selectors
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SelectorSpread) getSelectors(pod *api.Pod) []labels.Selector {
|
||||||
|
return getSelectors(pod, s.serviceLister, s.controllerLister, s.replicaSetLister)
|
||||||
|
}
|
||||||
|
|
||||||
// CalculateSpreadPriority spreads pods across hosts and zones, considering pods belonging to the same service or replication controller.
|
// CalculateSpreadPriority spreads pods across hosts and zones, considering pods belonging to the same service or replication controller.
|
||||||
// When a pod is scheduled, it looks for services or RCs that match the pod, then finds existing pods that match those selectors.
|
// When a pod is scheduled, it looks for services or RCs that match the pod, then finds existing pods that match those selectors.
|
||||||
// It favors nodes that have fewer existing matching pods.
|
// It favors nodes that have fewer existing matching pods.
|
||||||
@ -66,24 +89,7 @@ func NewSelectorSpreadPriority(
|
|||||||
// pods which match the same service selectors or RC selectors as the pod being scheduled.
|
// pods which match the same service selectors or RC selectors as the pod being scheduled.
|
||||||
// Where zone information is included on the nodes, it favors nodes in zones with fewer existing matching pods.
|
// Where zone information is included on the nodes, it favors nodes in zones with fewer existing matching pods.
|
||||||
func (s *SelectorSpread) CalculateSpreadPriority(pod *api.Pod, nodeNameToInfo map[string]*schedulercache.NodeInfo, nodes []*api.Node) (schedulerapi.HostPriorityList, error) {
|
func (s *SelectorSpread) CalculateSpreadPriority(pod *api.Pod, nodeNameToInfo map[string]*schedulercache.NodeInfo, nodes []*api.Node) (schedulerapi.HostPriorityList, error) {
|
||||||
selectors := make([]labels.Selector, 0, 3)
|
selectors := s.getSelectors(pod)
|
||||||
if services, err := s.serviceLister.GetPodServices(pod); err == nil {
|
|
||||||
for _, service := range services {
|
|
||||||
selectors = append(selectors, labels.SelectorFromSet(service.Spec.Selector))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if rcs, err := s.controllerLister.GetPodControllers(pod); err == nil {
|
|
||||||
for _, rc := range rcs {
|
|
||||||
selectors = append(selectors, labels.SelectorFromSet(rc.Spec.Selector))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if rss, err := s.replicaSetLister.GetPodReplicaSets(pod); err == nil {
|
|
||||||
for _, rs := range rss {
|
|
||||||
if selector, err := unversioned.LabelSelectorAsSelector(rs.Spec.Selector); err == nil {
|
|
||||||
selectors = append(selectors, selector)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Count similar pods by node
|
// Count similar pods by node
|
||||||
countsByNodeName := make(map[string]float32, len(nodes))
|
countsByNodeName := make(map[string]float32, len(nodes))
|
||||||
|
@ -286,7 +286,6 @@ func TestSelectorSpreadPriority(t *testing.T) {
|
|||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
nodeNameToInfo := schedulercache.CreateNodeNameToInfoMap(test.pods, nil)
|
nodeNameToInfo := schedulercache.CreateNodeNameToInfoMap(test.pods, nil)
|
||||||
selectorSpread := SelectorSpread{
|
selectorSpread := SelectorSpread{
|
||||||
podLister: algorithm.FakePodLister(test.pods),
|
|
||||||
serviceLister: algorithm.FakeServiceLister(test.services),
|
serviceLister: algorithm.FakeServiceLister(test.services),
|
||||||
controllerLister: algorithm.FakeControllerLister(test.rcs),
|
controllerLister: algorithm.FakeControllerLister(test.rcs),
|
||||||
replicaSetLister: algorithm.FakeReplicaSetLister(test.rss),
|
replicaSetLister: algorithm.FakeReplicaSetLister(test.rss),
|
||||||
@ -494,7 +493,6 @@ func TestZoneSelectorSpreadPriority(t *testing.T) {
|
|||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
nodeNameToInfo := schedulercache.CreateNodeNameToInfoMap(test.pods, nil)
|
nodeNameToInfo := schedulercache.CreateNodeNameToInfoMap(test.pods, nil)
|
||||||
selectorSpread := SelectorSpread{
|
selectorSpread := SelectorSpread{
|
||||||
podLister: algorithm.FakePodLister(test.pods),
|
|
||||||
serviceLister: algorithm.FakeServiceLister(test.services),
|
serviceLister: algorithm.FakeServiceLister(test.services),
|
||||||
controllerLister: algorithm.FakeControllerLister(test.rcs),
|
controllerLister: algorithm.FakeControllerLister(test.rcs),
|
||||||
replicaSetLister: algorithm.FakeReplicaSetLister(test.rss),
|
replicaSetLister: algorithm.FakeReplicaSetLister(test.rss),
|
||||||
|
@ -77,7 +77,7 @@ func init() {
|
|||||||
"ServiceSpreadingPriority",
|
"ServiceSpreadingPriority",
|
||||||
factory.PriorityConfigFactory{
|
factory.PriorityConfigFactory{
|
||||||
Function: func(args factory.PluginFactoryArgs) algorithm.PriorityFunction {
|
Function: func(args factory.PluginFactoryArgs) algorithm.PriorityFunction {
|
||||||
return priorities.NewSelectorSpreadPriority(args.PodLister, args.ServiceLister, algorithm.EmptyControllerLister{}, algorithm.EmptyReplicaSetLister{})
|
return priorities.NewSelectorSpreadPriority(args.ServiceLister, algorithm.EmptyControllerLister{}, algorithm.EmptyReplicaSetLister{})
|
||||||
},
|
},
|
||||||
Weight: 1,
|
Weight: 1,
|
||||||
},
|
},
|
||||||
@ -179,7 +179,7 @@ func defaultPriorities() sets.String {
|
|||||||
"SelectorSpreadPriority",
|
"SelectorSpreadPriority",
|
||||||
factory.PriorityConfigFactory{
|
factory.PriorityConfigFactory{
|
||||||
Function: func(args factory.PluginFactoryArgs) algorithm.PriorityFunction {
|
Function: func(args factory.PluginFactoryArgs) algorithm.PriorityFunction {
|
||||||
return priorities.NewSelectorSpreadPriority(args.PodLister, args.ServiceLister, args.ControllerLister, args.ReplicaSetLister)
|
return priorities.NewSelectorSpreadPriority(args.ServiceLister, args.ControllerLister, args.ReplicaSetLister)
|
||||||
},
|
},
|
||||||
Weight: 1,
|
Weight: 1,
|
||||||
},
|
},
|
||||||
|
@ -494,7 +494,6 @@ func TestZeroRequest(t *testing.T) {
|
|||||||
{Map: algorithmpriorities.BalancedResourceAllocationMap, Weight: 1},
|
{Map: algorithmpriorities.BalancedResourceAllocationMap, Weight: 1},
|
||||||
{
|
{
|
||||||
Function: algorithmpriorities.NewSelectorSpreadPriority(
|
Function: algorithmpriorities.NewSelectorSpreadPriority(
|
||||||
algorithm.FakePodLister(test.pods),
|
|
||||||
algorithm.FakeServiceLister([]*api.Service{}),
|
algorithm.FakeServiceLister([]*api.Service{}),
|
||||||
algorithm.FakeControllerLister([]*api.ReplicationController{}),
|
algorithm.FakeControllerLister([]*api.ReplicationController{}),
|
||||||
algorithm.FakeReplicaSetLister([]extensions.ReplicaSet{})),
|
algorithm.FakeReplicaSetLister([]extensions.ReplicaSet{})),
|
||||||
|
Loading…
Reference in New Issue
Block a user