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:
Hui Wang 2023-10-28 02:20:22 +08:00 committed by GitHub
parent 632d788b63
commit 90427abc65
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 0 deletions

View file

@ -90,6 +90,10 @@ func newAPIConfig(sdc *SDConfig, baseDir string, swcFunc ScrapeWorkConstructorFu
for strings.HasSuffix(apiServer, "/") {
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)
cfg := &apiConfig{
aw: aw,

View file

@ -234,6 +234,7 @@ func newGroupWatcher(apiServer string, ac *promauth.Config, namespaces []string,
proxy = http.ProxyURL(proxyURL)
}
tlsConfig, err := ac.NewTLSConfig()
// we should always check tlsconfig in advance to avoid panic here
if err != nil {
logger.Panicf("FATAL: cannot initialize tls config: %s", err)
}