mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
Merge pull request #130864 from xigang/factor-out-index-helper
controller: factor out pod node name indexer helper function
This commit is contained in:
commit
eec06b4169
@ -83,6 +83,9 @@ const (
|
|||||||
// The number of batches is given by:
|
// The number of batches is given by:
|
||||||
// 1+floor(log_2(ceil(N/SlowStartInitialBatchSize)))
|
// 1+floor(log_2(ceil(N/SlowStartInitialBatchSize)))
|
||||||
SlowStartInitialBatchSize = 1
|
SlowStartInitialBatchSize = 1
|
||||||
|
|
||||||
|
// PodNodeNameKeyIndex is the name of the index used by PodInformer to index pods by their node name.
|
||||||
|
PodNodeNameKeyIndex = "spec.nodeName"
|
||||||
)
|
)
|
||||||
|
|
||||||
var UpdateTaintBackoff = wait.Backoff{
|
var UpdateTaintBackoff = wait.Backoff{
|
||||||
@ -1051,6 +1054,28 @@ func FilterReplicaSets(RSes []*apps.ReplicaSet, filterFn filterRS) []*apps.Repli
|
|||||||
return filtered
|
return filtered
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddPodNodeNameIndexer adds an indexer for Pod's nodeName to the given PodInformer.
|
||||||
|
// This indexer is used to efficiently look up pods by their node name.
|
||||||
|
func AddPodNodeNameIndexer(podInformer cache.SharedIndexInformer) error {
|
||||||
|
if _, exists := podInformer.GetIndexer().GetIndexers()[PodNodeNameKeyIndex]; exists {
|
||||||
|
// indexer already exists, do nothing
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return podInformer.AddIndexers(cache.Indexers{
|
||||||
|
PodNodeNameKeyIndex: func(obj interface{}) ([]string, error) {
|
||||||
|
pod, ok := obj.(*v1.Pod)
|
||||||
|
if !ok {
|
||||||
|
return []string{}, nil
|
||||||
|
}
|
||||||
|
if len(pod.Spec.NodeName) == 0 {
|
||||||
|
return []string{}, nil
|
||||||
|
}
|
||||||
|
return []string{pod.Spec.NodeName}, nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// PodKey returns a key unique to the given pod within a cluster.
|
// PodKey returns a key unique to the given pod within a cluster.
|
||||||
// It's used so we consistently use the same key scheme in this module.
|
// It's used so we consistently use the same key scheme in this module.
|
||||||
// It does exactly what cache.MetaNamespaceKeyFunc would have done
|
// It does exactly what cache.MetaNamespaceKeyFunc would have done
|
||||||
|
@ -125,8 +125,7 @@ const (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
// The amount of time the nodecontroller should sleep between retrying node health updates
|
// The amount of time the nodecontroller should sleep between retrying node health updates
|
||||||
retrySleepTime = 20 * time.Millisecond
|
retrySleepTime = 20 * time.Millisecond
|
||||||
nodeNameKeyIndex = "spec.nodeName"
|
|
||||||
// podUpdateWorkerSizes assumes that in most cases pod will be handled by monitorNodeHealth pass.
|
// podUpdateWorkerSizes assumes that in most cases pod will be handled by monitorNodeHealth pass.
|
||||||
// Pod update workers will only handle lagging cache pods. 4 workers should be enough.
|
// Pod update workers will only handle lagging cache pods. 4 workers should be enough.
|
||||||
podUpdateWorkerSize = 4
|
podUpdateWorkerSize = 4
|
||||||
@ -388,22 +387,10 @@ func NewNodeLifecycleController(
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
nc.podInformerSynced = podInformer.Informer().HasSynced
|
nc.podInformerSynced = podInformer.Informer().HasSynced
|
||||||
podInformer.Informer().AddIndexers(cache.Indexers{
|
controller.AddPodNodeNameIndexer(podInformer.Informer())
|
||||||
nodeNameKeyIndex: func(obj interface{}) ([]string, error) {
|
|
||||||
pod, ok := obj.(*v1.Pod)
|
|
||||||
if !ok {
|
|
||||||
return []string{}, nil
|
|
||||||
}
|
|
||||||
if len(pod.Spec.NodeName) == 0 {
|
|
||||||
return []string{}, nil
|
|
||||||
}
|
|
||||||
return []string{pod.Spec.NodeName}, nil
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
podIndexer := podInformer.Informer().GetIndexer()
|
podIndexer := podInformer.Informer().GetIndexer()
|
||||||
nc.getPodsAssignedToNode = func(nodeName string) ([]*v1.Pod, error) {
|
nc.getPodsAssignedToNode = func(nodeName string) ([]*v1.Pod, error) {
|
||||||
objs, err := podIndexer.ByIndex(nodeNameKeyIndex, nodeName)
|
objs, err := podIndexer.ByIndex(controller.PodNodeNameKeyIndex, nodeName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user