Skip to content

Commit 5ef7e18

Browse files
fabianonunesoktalz
authored andcommitted
BUG/MINOR: prevents unconditional reloads when prometheus is enabled
When the --prometheus flag is passed, the Prometheus backend check always fails if the controller namespace isn't haproxy-controller. Consequently, all events received by the controller trigger a reload of HAProxy. Since the backend name depends on the namespace, it shouldn't be hardcoded.
1 parent 3705522 commit 5ef7e18

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

pkg/handler/prometheus.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package handler
22

33
import (
4+
"fmt"
45
"strings"
56

67
"github.com/haproxytech/kubernetes-ingress/pkg/annotations"
@@ -17,18 +18,20 @@ type PrometheusEndpoint struct {
1718

1819
//nolint:golint, stylecheck
1920
const (
20-
PROMETHEUS_BACKEND_NAME = "haproxy-controller_prometheus_http"
21-
PROMETHEUS_URL_PATH = "/metrics"
21+
PROMETHEUS_URL_PATH = "/metrics"
2222
)
2323

2424
func (handler PrometheusEndpoint) Update(k store.K8s, h haproxy.HAProxy, a annotations.Annotations) (err error) {
2525
if handler.PodNs == "" {
2626
return
2727
}
2828

29+
prometheusSvcName := "prometheus"
30+
prometheusBackendName := fmt.Sprintf("%s_%s_http", handler.PodNs, prometheusSvcName)
31+
2932
status := store.EMPTY
3033
var secret *store.Secret
31-
_, errBackend := h.BackendGet(PROMETHEUS_BACKEND_NAME)
34+
_, errBackend := h.BackendGet(prometheusBackendName)
3235
backendExists := errBackend == nil
3336

3437
annSecret := annotations.String("prometheus-endpoint-auth-secret", k.ConfigMaps.Main.Annotations)
@@ -59,7 +62,6 @@ func (handler PrometheusEndpoint) Update(k store.K8s, h haproxy.HAProxy, a annot
5962
return
6063
}
6164

62-
prometheusSvcName := "prometheus"
6365
svc := &store.Service{
6466
Namespace: handler.PodNs,
6567
Name: prometheusSvcName,

0 commit comments

Comments
 (0)