1
0
mirror of https://github.com/kubernetes-sigs/descheduler.git synced 2026-01-25 20:59:28 +01:00

feat(prometheus): allow different url schemes

as per prometheus golang client implementation: the only url validation
done is by means of an `url.Parse()` call. we should do the same and not
enforce the usage of https scheme.

our readme even shows an example of descheduler config using http
prometheus url scheme.
This commit is contained in:
Ricardo Maraschini
2025-06-12 11:23:09 +02:00
parent a1ddb3f28f
commit a2b899aa15
2 changed files with 2 additions and 21 deletions

View File

@@ -172,13 +172,8 @@ func validateDeschedulerConfiguration(in api.DeschedulerPolicy, registry pluginr
} else {
if prometheusConfig.Prometheus.URL == "" {
errorsInPolicy = append(errorsInPolicy, fmt.Errorf("prometheus URL is required when prometheus is enabled"))
} else {
u, err := url.Parse(prometheusConfig.Prometheus.URL)
if err != nil {
errorsInPolicy = append(errorsInPolicy, fmt.Errorf("error parsing prometheus URL: %v", err))
} else if u.Scheme != "https" {
errorsInPolicy = append(errorsInPolicy, fmt.Errorf("prometheus URL's scheme is not https, got %q instead", u.Scheme))
}
} else if _, err := url.Parse(prometheusConfig.Prometheus.URL); err != nil {
errorsInPolicy = append(errorsInPolicy, fmt.Errorf("error parsing prometheus URL: %v", err))
}
if prometheusConfig.Prometheus.AuthToken != nil {

View File

@@ -259,20 +259,6 @@ func TestValidateDeschedulerConfiguration(t *testing.T) {
},
result: fmt.Errorf("error parsing prometheus URL: parse \"http://example.com:-80\": invalid port \":-80\" after host"),
},
{
description: "prometheus url does not have https error",
deschedulerPolicy: api.DeschedulerPolicy{
MetricsProviders: []api.MetricsProvider{
{
Source: api.PrometheusMetrics,
Prometheus: &api.Prometheus{
URL: "http://example.com:80",
},
},
},
},
result: fmt.Errorf("prometheus URL's scheme is not https, got \"http\" instead"),
},
{
description: "prometheus authtoken with no secret reference error",
deschedulerPolicy: api.DeschedulerPolicy{