config: fix Kubernetes config with empty API server (#5256)

Signed-off-by: Simon Pasquier <spasquie@redhat.com>
This commit is contained in:
Simon Pasquier 2019-02-22 15:51:47 +01:00 committed by GitHub
parent 362873f72b
commit e72c875e63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 2 deletions

View File

@ -632,6 +632,11 @@ func TestLoadConfigRuleFilesAbsolutePath(t *testing.T) {
testutil.Equals(t, ruleFilesExpectedConf, c)
}
func TestKubernetesEmptyAPIServer(t *testing.T) {
_, err := LoadFile("testdata/kubernetes_empty_apiserver.good.yml")
testutil.Ok(t, err)
}
var expectedErrors = []struct {
filename string
errMsg string

View File

@ -0,0 +1,4 @@
scrape_configs:
- job_name: prometheus
kubernetes_sd_configs:
- role: endpoints

View File

@ -1,6 +1,5 @@
scrape_configs:
- job_name: prometheus
kubernetes_sd_configs:
- role: pod
bearer_token: 1234

View File

@ -107,7 +107,7 @@ func (c *SDConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
if err != nil {
return err
}
if c.APIServer.URL == nil && !reflect.DeepEqual(c.HTTPClientConfig, &config_util.HTTPClientConfig{}) {
if c.APIServer.URL == nil && !reflect.DeepEqual(c.HTTPClientConfig, config_util.HTTPClientConfig{}) {
return fmt.Errorf("to use custom HTTP client configuration please provide the 'api_server' URL explicitly")
}
return nil