mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-03-11 15:34:56 +00:00
lib/promscrape/discovery/kubernetes: avoid possible panic if given caFile under kubernetes.SDConfig.HTTPClientConfig is not exist (#5243)
follow up d5a599badc
This commit is contained in:
parent
20aeb8b65d
commit
a37125d043
2 changed files with 5 additions and 0 deletions
|
@ -90,6 +90,10 @@ func newAPIConfig(sdc *SDConfig, baseDir string, swcFunc ScrapeWorkConstructorFu
|
||||||
for strings.HasSuffix(apiServer, "/") {
|
for strings.HasSuffix(apiServer, "/") {
|
||||||
apiServer = apiServer[:len(apiServer)-1]
|
apiServer = apiServer[:len(apiServer)-1]
|
||||||
}
|
}
|
||||||
|
// pre-check tls config
|
||||||
|
if _, err := ac.NewTLSConfig(); err != nil {
|
||||||
|
return nil, fmt.Errorf("cannot initialize tls config: %w", err)
|
||||||
|
}
|
||||||
aw := newAPIWatcher(apiServer, ac, sdc, swcFunc)
|
aw := newAPIWatcher(apiServer, ac, sdc, swcFunc)
|
||||||
cfg := &apiConfig{
|
cfg := &apiConfig{
|
||||||
aw: aw,
|
aw: aw,
|
||||||
|
|
|
@ -234,6 +234,7 @@ func newGroupWatcher(apiServer string, ac *promauth.Config, namespaces []string,
|
||||||
proxy = http.ProxyURL(proxyURL)
|
proxy = http.ProxyURL(proxyURL)
|
||||||
}
|
}
|
||||||
tlsConfig, err := ac.NewTLSConfig()
|
tlsConfig, err := ac.NewTLSConfig()
|
||||||
|
// we should always check tlsconfig in advance to avoid panic here
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Panicf("FATAL: cannot initialize tls config: %s", err)
|
logger.Panicf("FATAL: cannot initialize tls config: %s", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue