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
  • Loading branch information
fabianonunes committed Sep 2, 2023
1 parent 6d18884 commit e490d62
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
8 changes: 5 additions & 3 deletions pkg/ingress/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package ingress

import (
"fmt"
"path/filepath"

"github.com/haproxytech/kubernetes-ingress/pkg/annotations"
Expand Down Expand Up @@ -109,17 +110,18 @@ func (i *Ingress) handlePath(k store.K8s, h haproxy.HAProxy, host string, path *
BackendName: backendName,
SSLPassthrough: i.sslPassthrough,
}
customRouteID := fmt.Sprintf("%s_%s:%s", i.resource.Namespace, i.resource.Name, backendName)

routeACLAnn := a.String("route-acl", svc.GetResource().Annotations)
if routeACLAnn == "" {
if _, ok := route.CustomRoutes[backendName]; ok {
delete(route.CustomRoutes, backendName)
if _, ok := route.CustomRoutes[customRouteID]; ok {
delete(route.CustomRoutes, customRouteID)
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)
routeReload, err = route.AddCustomRoute(customRouteID, ingRoute, routeACLAnn, h)
}
if err != nil {
return
Expand Down
6 changes: 3 additions & 3 deletions pkg/route/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func AddHostPathRoute(route Route, mapFiles maps.Maps) error {
}

// AddCustomRoute adds an ingress route with specific ACL via use_backend haproxy directive
func AddCustomRoute(route Route, routeACLAnn string, api api.HAProxyClient) (reload bool, err error) {
func AddCustomRoute(customRouteID string, route Route, routeACLAnn string, api api.HAProxyClient) (reload bool, err error) {
var routeCond string
if route.Host != "" {
routeCond = fmt.Sprintf("{ var(txn.host) -m str %s } ", route.Host)
Expand All @@ -125,8 +125,8 @@ func AddCustomRoute(route Route, routeACLAnn string, api api.HAProxyClient) (rel
return
}
}
if acl := CustomRoutes[route.BackendName]; acl != routeCond {
CustomRoutes[route.BackendName] = routeCond
if acl := CustomRoutes[customRouteID]; acl != routeCond {
CustomRoutes[customRouteID] = routeCond
reload = true
logger.Debugf("Custom Route to backend '%s' added, reload required", route.BackendName)
}
Expand Down

0 comments on commit e490d62

Please sign in to comment.