Skip to content

Commit

Permalink
BUG/MINOR: prevents clash on custom routes names to avoid unecessary …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
fabianonunes committed Sep 4, 2023
1 parent 6d18884 commit 5bf5c24
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
9 changes: 9 additions & 0 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"fmt"
"os"

"github.com/go-test/deep"

"github.com/haproxytech/client-native/v3/models"
"github.com/haproxytech/kubernetes-ingress/pkg/annotations"
gateway "github.com/haproxytech/kubernetes-ingress/pkg/gateways"
Expand Down Expand Up @@ -140,6 +142,13 @@ func (c *HAProxyController) updateHAProxy() {
}
}

updated := deep.Equal(route.CurentCustomRoutes, route.CustomRoutes, deep.FLAG_IGNORE_SLICE_ORDER)
if len(updated) != 0 {
route.CurentCustomRoutes = route.CustomRoutes
logger.Debugf("Custom Routes changed: %s, reload required", updated)
c.reload = true
}

gatewayReload := c.gatewayManager.ManageGateway()
c.reload = gatewayReload || c.reload

Expand Down
5 changes: 0 additions & 5 deletions pkg/ingress/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,6 @@ func (i *Ingress) handlePath(k store.K8s, h haproxy.HAProxy, host string, path *

routeACLAnn := a.String("route-acl", svc.GetResource().Annotations)
if routeACLAnn == "" {
if _, ok := route.CustomRoutes[backendName]; ok {
delete(route.CustomRoutes, backendName)
logger.Debugf("Custom Route to backend '%s' deleted, reload required", backendName)
routeReload = true
}
err = route.AddHostPathRoute(ingRoute, h.Maps)
} else {
routeReload, err = route.AddCustomRoute(ingRoute, routeACLAnn, h)
Expand Down
12 changes: 5 additions & 7 deletions pkg/route/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ const (
)

var (
CustomRoutes = make(map[string]string)
logger = utils.GetLogger()
CurentCustomRoutes = make([]string, 0)
CustomRoutes = make([]string, 0)
)

type Route struct {
Expand Down Expand Up @@ -125,11 +125,8 @@ func AddCustomRoute(route Route, routeACLAnn string, api api.HAProxyClient) (rel
return
}
}
if acl := CustomRoutes[route.BackendName]; acl != routeCond {
CustomRoutes[route.BackendName] = routeCond
reload = true
logger.Debugf("Custom Route to backend '%s' added, reload required", route.BackendName)
}

CustomRoutes = append(CustomRoutes, routeCond)
return reload, err
}

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

0 comments on commit 5bf5c24

Please sign in to comment.