Skip to content

Commit a1857e3

Browse files
fabianonunesoktalz
authored andcommitted
BUG/MINOR: prevents clash on custom routes names to avoid unecessary restarts
All custom routes are stored in the `routes.CustomRoutes` map using the backend name as the key (`ServiceNS_ServiceName_PortName`). When we encounter two distinct IngressRules, whether they are within the same Ingress or not, and they utilize different hosts or paths while pointing to the same Service, they end up sharing the same key in `CustomRoutes`. This similarity in keys results in comparison failures during every synchronization, requiring a hard reload of HAProxy. Rather than storing the custom routes in a map keyed by backend name, this commit stores all the resulting use_backend directives in a slice and compares them between syncs.
1 parent 9f71ca8 commit a1857e3

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

pkg/controller/controller.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import (
1818
"fmt"
1919
"os"
2020

21+
"github.com/go-test/deep"
22+
2123
"github.com/haproxytech/client-native/v3/models"
2224
"github.com/haproxytech/kubernetes-ingress/pkg/annotations"
2325
gateway "github.com/haproxytech/kubernetes-ingress/pkg/gateways"
@@ -131,6 +133,13 @@ func (c *HAProxyController) updateHAProxy() {
131133
}
132134
}
133135

136+
updated := deep.Equal(route.CurentCustomRoutes, route.CustomRoutes, deep.FLAG_IGNORE_SLICE_ORDER)
137+
if len(updated) != 0 {
138+
route.CurentCustomRoutes = route.CustomRoutes
139+
logger.Debugf("Custom Routes changed: %s, reload required", updated)
140+
c.reload = true
141+
}
142+
134143
gatewayReload := c.gatewayManager.ManageGateway()
135144
c.reload = gatewayReload || c.reload
136145

pkg/ingress/ingress.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,6 @@ func (i *Ingress) handlePath(k store.K8s, h haproxy.HAProxy, host string, path *
112112

113113
routeACLAnn := a.String("route-acl", svc.GetResource().Annotations)
114114
if routeACLAnn == "" {
115-
if _, ok := route.CustomRoutes[backendName]; ok {
116-
delete(route.CustomRoutes, backendName)
117-
logger.Debugf("Custom Route to backend '%s' deleted, reload required", backendName)
118-
routeReload = true
119-
}
120115
err = route.AddHostPathRoute(ingRoute, h.Maps)
121116
} else {
122117
routeReload, err = route.AddCustomRoute(ingRoute, routeACLAnn, h)

pkg/route/route.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ const (
4040
)
4141

4242
var (
43-
CustomRoutes = make(map[string]string)
44-
logger = utils.GetLogger()
43+
CurentCustomRoutes = make([]string, 0)
44+
CustomRoutes = make([]string, 0)
4545
)
4646

4747
type Route struct {
@@ -125,11 +125,8 @@ func AddCustomRoute(route Route, routeACLAnn string, api api.HAProxyClient) (rel
125125
return
126126
}
127127
}
128-
if acl := CustomRoutes[route.BackendName]; acl != routeCond {
129-
CustomRoutes[route.BackendName] = routeCond
130-
reload = true
131-
logger.Debugf("Custom Route to backend '%s' added, reload required", route.BackendName)
132-
}
128+
129+
CustomRoutes = append(CustomRoutes, routeCond)
133130
return reload, err
134131
}
135132

@@ -147,5 +144,6 @@ func CustomRoutesReset(api api.HAProxyClient) (err error) {
147144
return fmt.Errorf("unable to create main backendSwitching rule !!: %w", err)
148145
}
149146
}
147+
CustomRoutes = make([]string, 0)
150148
return
151149
}

0 commit comments

Comments
 (0)