fix(inputs.prometheus): Add namespace option in k8s informer factory (#13063)

Co-authored-by: ivayloi2 <ivayloi2@vmware.com>
This commit is contained in:
Ivaylo Ivanov 2023-04-12 18:00:57 +03:00 committed by GitHub
parent 5f2142a6cc
commit 14c84a00ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 1 deletions

View File

@ -135,7 +135,11 @@ func (p *Prometheus) watchPod(ctx context.Context, clientset *kubernetes.Clients
}
if informerfactory == nil {
informerfactory = informers.NewSharedInformerFactory(clientset, resyncinterval)
var informerOptions []informers.SharedInformerOption
if p.PodNamespace != "" {
informerOptions = append(informerOptions, informers.WithNamespace(p.PodNamespace))
}
informerfactory = informers.NewSharedInformerFactoryWithOptions(clientset, resyncinterval, informerOptions...)
}
p.nsStore = informerfactory.Core().V1().Namespaces().Informer().GetStore()