Remove duplicate and unused index from PodIndexer

DaemonSetsController adds a "nodeName" index to PodIndexer, which is
redundant with the "spec.nodeName" index of NodeLifecycleController.
However, DaemonSetsController hasn't been using this index since #86730.
This patch removes the redundant and unused index to reduce memory and
CPU spent on it.

Signed-off-by: Quan Tian <qtian@vmware.com>
This commit is contained in:
Quan Tian 2022-08-02 01:16:23 +08:00
parent d46742b387
commit f40067a8cc
2 changed files with 1 additions and 22 deletions

View File

@ -114,8 +114,6 @@ type DaemonSetsController struct {
historyStoreSynced cache.InformerSynced
// podLister get list/get pods from the shared informers's store
podLister corelisters.PodLister
// podNodeIndex indexes pods by their nodeName
podNodeIndex cache.Indexer
// podStoreSynced returns true if the pod store has been synced at least once.
// Added as a member to the struct to allow injection for testing.
podStoreSynced cache.InformerSynced
@ -187,12 +185,6 @@ func NewDaemonSetsController(
DeleteFunc: dsc.deletePod,
})
dsc.podLister = podInformer.Lister()
// This custom indexer will index pods based on their NodeName which will decrease the amount of pods we need to get in simulate() call.
podInformer.Informer().GetIndexer().AddIndexers(cache.Indexers{
"nodeName": indexByPodNodeName,
})
dsc.podNodeIndex = podInformer.Informer().GetIndexer()
dsc.podStoreSynced = podInformer.Informer().HasSynced
nodeInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
@ -211,18 +203,6 @@ func NewDaemonSetsController(
return dsc, nil
}
func indexByPodNodeName(obj interface{}) ([]string, error) {
pod, ok := obj.(*v1.Pod)
if !ok {
return []string{}, nil
}
// We are only interested in active pods with nodeName set
if len(pod.Spec.NodeName) == 0 || pod.Status.Phase == v1.PodSucceeded || pod.Status.Phase == v1.PodFailed {
return []string{}, nil
}
return []string{pod.Spec.NodeName}, nil
}
func (dsc *DaemonSetsController) addDaemonset(obj interface{}) {
ds := obj.(*apps.DaemonSet)
klog.V(4).Infof("Adding daemon set %s", ds.Name)

View File

@ -2234,9 +2234,8 @@ func TestNodeShouldRunDaemonPod(t *testing.T) {
}
manager.nodeStore.Add(node)
for _, p := range c.podsOnNode {
manager.podStore.Add(p)
p.Spec.NodeName = "test-node"
manager.podNodeIndex.Add(p)
manager.podStore.Add(p)
}
c.ds.Spec.UpdateStrategy = *strategy
shouldRun, shouldContinueRunning := NodeShouldRunDaemonPod(node, c.ds)