fix: issues with prometheus kubernetes pod discovery (#9605)
This commit is contained in:
parent
02ccbec348
commit
fe144e7c99
|
|
@ -111,13 +111,22 @@ func (p *Prometheus) watchPod(ctx context.Context, client *kubernetes.Clientset)
|
|||
LabelSelector: p.KubernetesLabelSelector,
|
||||
FieldSelector: p.KubernetesFieldSelector,
|
||||
})
|
||||
defer watcher.Stop()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
pod := &corev1.Pod{}
|
||||
go func() {
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return nil
|
||||
default:
|
||||
for event := range watcher.ResultChan() {
|
||||
pod = &corev1.Pod{}
|
||||
pod, ok := event.Object.(*corev1.Pod)
|
||||
if !ok {
|
||||
return fmt.Errorf("Unexpected object when getting pods")
|
||||
}
|
||||
|
||||
// If the pod is not "ready", there will be no ip associated with it.
|
||||
if pod.Annotations["prometheus.io/scrape"] != "true" ||
|
||||
!podReady(pod.Status.ContainerStatuses) {
|
||||
|
|
@ -137,9 +146,8 @@ func (p *Prometheus) watchPod(ctx context.Context, client *kubernetes.Clientset)
|
|||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Prometheus) cAdvisor(ctx context.Context, bearerToken string) error {
|
||||
|
|
|
|||
Loading…
Reference in New Issue