mirror of
https://github.com/prometheus/prometheus.git
synced 2025-07-03 11:03:25 +00:00
Index pods by node name
Signed-off-by: fpetkovski <filip.petkovsky@gmail.com>
This commit is contained in:
parent
eb5512555d
commit
16bd0d7d5c
2 changed files with 29 additions and 8 deletions
|
@ -511,7 +511,7 @@ func (d *Discovery) Run(ctx context.Context, ch chan<- []*targetgroup.Group) {
|
|||
}
|
||||
pod := NewPod(
|
||||
log.With(d.logger, "role", "pod"),
|
||||
cache.NewSharedInformer(plw, &apiv1.Pod{}, resyncPeriod),
|
||||
d.newPodsByNodeInformer(plw),
|
||||
nodeInformer,
|
||||
)
|
||||
d.discoverers = append(d.discoverers, pod)
|
||||
|
@ -679,3 +679,18 @@ func (d *Discovery) newNodeInformer(ctx context.Context) cache.SharedInformer {
|
|||
}
|
||||
return cache.NewSharedInformer(nlw, &apiv1.Node{}, resyncPeriod)
|
||||
}
|
||||
|
||||
func (d *Discovery) newPodsByNodeInformer(plw *cache.ListWatch) cache.SharedIndexInformer {
|
||||
indexers := make(map[string]cache.IndexFunc)
|
||||
if d.attachMetadata.Node {
|
||||
indexers[nodeIndex] = func(obj interface{}) ([]string, error) {
|
||||
pod, ok := obj.(*apiv1.Pod)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("object is not a pod")
|
||||
}
|
||||
return []string{pod.Spec.NodeName}, nil
|
||||
}
|
||||
}
|
||||
|
||||
return cache.NewSharedIndexInformer(plw, &apiv1.Pod{}, resyncPeriod, indexers)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue