Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Commit

Permalink
fix: configure multiple paths for same backend (#217)
Browse files Browse the repository at this point in the history
Signed-off-by: Lin Yang <reaver@flomesh.io>
  • Loading branch information
reaver-flomesh committed Feb 23, 2023
1 parent 114c7f0 commit 48ce74c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
31 changes: 22 additions & 9 deletions pkg/cache/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,16 @@ func (info BaseIngressInfo) TrustedCA() *route.CertificateSpec {
return info.trustedCA
}

type IngressMap map[ServicePortName]Route
type IngressMap map[RouteKey]Route

type BackendInfo struct {
ServicePortName ServicePortName
type RouteKey struct {
ServicePortName
Host string
Path string
}

func (irk *RouteKey) String() string {
return fmt.Sprintf("%s#%s#%s", irk.Host, irk.Path, irk.ServicePortName.String())
}

type ingressChange struct {
Expand Down Expand Up @@ -285,19 +291,26 @@ func (ict *IngressChangeTracker) ingressToIngressMap(ing *networkingv1.Ingress,
}
klog.V(5).Infof("ServicePortName %q", svcPortName.String())

// already exists, first one wins
if _, ok := ingressMap[*svcPortName]; ok {
baseIngInfo := ict.newBaseIngressInfo(rule, path, *svcPortName)
if baseIngInfo == nil {
continue
}

baseIngInfo := ict.newBaseIngressInfo(rule, path, *svcPortName)
if baseIngInfo == nil {
routeKey := RouteKey{
ServicePortName: *svcPortName,
Host: baseIngInfo.Host(),
Path: baseIngInfo.Path(),
}

// already exists, first one wins
if _, ok := ingressMap[routeKey]; ok {
klog.Warningf("Duplicate route for tuple: %q", routeKey.String())
continue
}

ingressMap[*svcPortName] = ict.enrichIngressInfo(&rule, ing, baseIngInfo)
ingressMap[routeKey] = ict.enrichIngressInfo(&rule, ing, baseIngInfo)

klog.V(5).Infof("ServicePort %q is linked to rule %#v", svcPortName.String(), ingressMap[*svcPortName])
klog.V(5).Infof("Route %q is linked to rule %#v", routeKey.String(), ingressMap[routeKey])
}
}

Expand Down
4 changes: 3 additions & 1 deletion pkg/cache/local_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,9 @@ func (c *LocalCache) buildIngressConfig() routepkg.IngressData {
Routes: []routepkg.IngressRouteSpec{},
}

for svcName, route := range c.ingressMap {
for _, route := range c.ingressMap {
svcName := route.Backend()

ir := routepkg.IngressRouteSpec{
RouterSpec: routepkg.RouterSpec{
Host: route.Host(),
Expand Down

0 comments on commit 48ce74c

Please sign in to comment.