@@ -22,7 +22,6 @@ import (
22
22
"time"
23
23
24
24
v1 "k8s.io/api/core/v1"
25
- "k8s.io/apimachinery/pkg/labels"
26
25
"k8s.io/apimachinery/pkg/util/sets"
27
26
"k8s.io/apimachinery/pkg/util/wait"
28
27
utilfeature "k8s.io/apiserver/pkg/util/feature"
@@ -315,7 +314,9 @@ func (cache *schedulerCache) removeDeletedNodesFromSnapshot(snapshot *Snapshot)
315
314
}
316
315
}
317
316
318
- func (cache * schedulerCache ) ListPods (selector labels.Selector ) ([]* v1.Pod , error ) {
317
+ // PodCount returns the number of pods in the cache (including those from deleted nodes).
318
+ // DO NOT use outside of tests.
319
+ func (cache * schedulerCache ) PodCount () (int , error ) {
319
320
cache .mu .RLock ()
320
321
defer cache .mu .RUnlock ()
321
322
// podFilter is expected to return true for most or all of the pods. We
@@ -325,15 +326,11 @@ func (cache *schedulerCache) ListPods(selector labels.Selector) ([]*v1.Pod, erro
325
326
for _ , n := range cache .nodes {
326
327
maxSize += len (n .info .Pods )
327
328
}
328
- pods := make ([] * v1. Pod , 0 , maxSize )
329
+ count := 0
329
330
for _ , n := range cache .nodes {
330
- for _ , p := range n .info .Pods {
331
- if selector .Matches (labels .Set (p .Pod .Labels )) {
332
- pods = append (pods , p .Pod )
333
- }
334
- }
331
+ count += len (n .info .Pods )
335
332
}
336
- return pods , nil
333
+ return count , nil
337
334
}
338
335
339
336
func (cache * schedulerCache ) AssumePod (pod * v1.Pod ) error {
@@ -736,19 +733,6 @@ func (cache *schedulerCache) expirePod(key string, ps *podState) error {
736
733
return nil
737
734
}
738
735
739
- // GetNodeInfo returns cached data for the node name.
740
- func (cache * schedulerCache ) GetNodeInfo (nodeName string ) (* v1.Node , error ) {
741
- cache .mu .RLock ()
742
- defer cache .mu .RUnlock ()
743
-
744
- n , ok := cache .nodes [nodeName ]
745
- if ! ok {
746
- return nil , fmt .Errorf ("node %q not found in cache" , nodeName )
747
- }
748
-
749
- return n .info .Node (), nil
750
- }
751
-
752
736
// updateMetrics updates cache size metric values for pods, assumed pods, and nodes
753
737
func (cache * schedulerCache ) updateMetrics () {
754
738
metrics .CacheSize .WithLabelValues ("assumed_pods" ).Set (float64 (len (cache .assumedPods )))
0 commit comments