From 4ee6def68bdfe2b08dcff36d3fbbd5fe26e76ef0 Mon Sep 17 00:00:00 2001 From: Lu Jiajing Date: Tue, 6 Apr 2021 03:25:31 +0800 Subject: [PATCH] fix access to nil *url.URL (#1180) * fix access to nil *url.URL Signed-off-by: Megrez Lu * Update lib/promscrape/discovery/kubernetes/api_watcher.go Co-authored-by: Aliaksandr Valialkin --- lib/promscrape/discovery/kubernetes/api_watcher.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/promscrape/discovery/kubernetes/api_watcher.go b/lib/promscrape/discovery/kubernetes/api_watcher.go index c78b334f8..d5def2f29 100644 --- a/lib/promscrape/discovery/kubernetes/api_watcher.go +++ b/lib/promscrape/discovery/kubernetes/api_watcher.go @@ -190,8 +190,12 @@ func newGroupWatcher(apiServer string, ac *promauth.Config, namespaces []string, } func getGroupWatcher(apiServer string, ac *promauth.Config, namespaces []string, selectors []Selector, proxyURL *url.URL) *groupWatcher { - key := fmt.Sprintf("apiServer=%s, namespaces=%s, selectors=%s, proxyURL=%v, authConfig=%s", - apiServer, namespaces, selectorsKey(selectors), proxyURL, ac.String()) + proxyURLStr := "" + if proxyURL != nil { + proxyURLStr = proxyURL.String() + } + key := fmt.Sprintf("apiServer=%s, namespaces=%s, selectors=%s, proxyURL=%s, authConfig=%s", + apiServer, namespaces, selectorsKey(selectors), proxyURLStr, ac.String()) groupWatchersLock.Lock() gw := groupWatchers[key] if gw == nil {