Skip to content

Commit 8965291

Browse files
authored
Fix prometheus cadvisor authentication (#9497)
1 parent 2eb0ee2 commit 8965291

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

plugins/inputs/prometheus/kubernetes.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func (p *Prometheus) start(ctx context.Context) error {
8888
return
8989
case <-time.After(time.Second):
9090
if p.isNodeScrapeScope {
91-
err = p.cAdvisor(ctx)
91+
err = p.cAdvisor(ctx, config.BearerToken)
9292
if err != nil {
9393
p.Log.Errorf("Unable to monitor pods with node scrape scope: %s", err.Error())
9494
}
@@ -145,10 +145,13 @@ func (p *Prometheus) watchPod(ctx context.Context, client *kubernetes.Clientset)
145145
return nil
146146
}
147147

148-
func (p *Prometheus) cAdvisor(ctx context.Context) error {
148+
func (p *Prometheus) cAdvisor(ctx context.Context, bearerToken string) error {
149149
// The request will be the same each time
150150
podsURL := fmt.Sprintf("https://%s:10250/pods", p.NodeIP)
151151
req, err := http.NewRequest("GET", podsURL, nil)
152+
req.Header.Set("Authorization", "Bearer "+bearerToken)
153+
req.Header.Add("Accept", "application/json")
154+
152155
if err != nil {
153156
return fmt.Errorf("error when creating request to %s to get pod list: %w", podsURL, err)
154157
}

0 commit comments

Comments
 (0)