Skip to content

Commit 5fd01ad

Browse files
hdurand0710oktalz
authored andcommitted
BUG/MEDIUM: fix constant reloads due to Prometheus
This fixes 2 issues: - constant reloads (each time there is an update is the k8s cluster) to Prometheus when the Ingress Controller is started with a --namespace-whitelist option and the namespace where the controller is running is not part of the white listed namespaces. In this situation, the prometheus backend was never created but we kept trying to create it - do not try to create the Prometheus backend if the flag --prometheus is not set
1 parent 2f61fd4 commit 5fd01ad

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

pkg/controller/controller.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,14 @@ func (c *HAProxyController) updateHAProxy() {
149149
}
150150

151151
for _, namespace := range c.store.Namespaces {
152-
if !namespace.Relevant {
153-
continue
154-
}
155152
c.store.SecretsProcessed = map[string]struct{}{}
156153
for _, ingResource := range namespace.Ingresses {
154+
if !namespace.Relevant && !ingResource.Faked {
155+
// As we watch only for white-listed namespaces, we should not worry about iterating over
156+
// many ingresses in irrelevant namespaces.
157+
// There should only be fake ingresses in irrelevant namespaces so loop should be whithin small amount of ingresses (Prometheus)
158+
continue
159+
}
157160
i := ingress.New(ingResource, c.osArgs.IngressClass, c.osArgs.EmptyIngressClass, c.annotations)
158161
if !i.Supported(c.store, c.annotations) {
159162
logger.Debugf("ingress '%s/%s' ignored: no matching", ingResource.Namespace, ingResource.Name)

pkg/controller/handler.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,13 @@ func (c *HAProxyController) initHandlers() {
5757

5858
defer func() { c.updateHandlers = append(c.updateHandlers, handler.Refresh{}) }()
5959

60-
c.beforeUpdateHandlers = []UpdateHandler{
61-
handler.PrometheusEndpoint{
62-
EventChan: c.eventChan,
63-
PodNs: c.podNamespace,
64-
},
60+
if c.osArgs.PrometheusEnabled {
61+
c.beforeUpdateHandlers = []UpdateHandler{
62+
handler.PrometheusEndpoint{
63+
EventChan: c.eventChan,
64+
PodNs: c.podNamespace,
65+
},
66+
}
6567
}
6668
// Need to be before Refresh. If after, maps are refreshed without pprof content
6769
if c.osArgs.PprofEnabled {

0 commit comments

Comments
 (0)