Skip to content

Commit

Permalink
BUG/MINOR: prevents unconditional reloads when prometheus is enabled
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
fabianonunes authored and oktalz committed Mar 22, 2024
1 parent 5d21cdb commit f8e12cd
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pkg/handler/prometheus.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package handler

import (
"fmt"
"strings"

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

//nolint:golint, stylecheck
const (
PROMETHEUS_BACKEND_NAME = "haproxy-controller_prometheus_http"
PROMETHEUS_URL_PATH = "/metrics"
PROMETHEUS_URL_PATH = "/metrics"
)

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

prometheusSvcName := "prometheus"
prometheusBackendName := fmt.Sprintf("%s_%s_http", handler.PodNs, prometheusSvcName)

status := store.EMPTY
var secret *store.Secret
_, errBackend := h.BackendGet(PROMETHEUS_BACKEND_NAME)
_, errBackend := h.BackendGet(prometheusBackendName)
backendExists := errBackend == nil

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

prometheusSvcName := "prometheus"
svc := &store.Service{
Namespace: handler.PodNs,
Name: prometheusSvcName,
Expand Down

0 comments on commit f8e12cd

Please sign in to comment.