Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions internal/gatewayapi/contexts.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@ import (
type GatewayContext struct {
*v1beta1.Gateway

listeners map[v1beta1.SectionName]*ListenerContext
listeners []*ListenerContext
}

func (g *GatewayContext) GetListenerContext(listenerName v1beta1.SectionName) *ListenerContext {
if g.listeners == nil {
g.listeners = make(map[v1beta1.SectionName]*ListenerContext)
g.listeners = make([]*ListenerContext, 0)
}

if ctx := g.listeners[listenerName]; ctx != nil {
return ctx
for _, l := range g.listeners {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we take this approach of implicitly relying on input listener order, we'll no longer need to sort the listener Names in the o/p, can you also rm

sort.SliceStable(ir.HTTP, func(i, j int) bool { return ir.HTTP[i].Name < ir.HTTP[j].Name })

if l.Name == listenerName {
return l
}
}

var listener *v1beta1.Listener
Expand Down Expand Up @@ -57,7 +59,7 @@ func (g *GatewayContext) GetListenerContext(listenerName v1beta1.SectionName) *L
gateway: g.Gateway,
listenerStatusIdx: listenerStatusIdx,
}
g.listeners[listenerName] = ctx
g.listeners = append(g.listeners, ctx)
return ctx
}

Expand Down
4 changes: 2 additions & 2 deletions internal/gatewayapi/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ func GetReferencedListeners(parentRef v1beta1.ParentReference, gateways []*Gatew
selectsGateway = true

// The parentRef may be to the entire Gateway, or to a specific listener.
for listenerName, listener := range gateway.listeners {
if parentRef.SectionName == nil || *parentRef.SectionName == listenerName {
for _, listener := range gateway.listeners {
if parentRef.SectionName == nil || *parentRef.SectionName == listener.Name {
referencedListeners = append(referencedListeners, listener)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
gateways:
- apiVersion: gateway.networking.k8s.io/v1beta1
kind: Gateway
metadata:
namespace: envoy-gateway
name: gateway-1
spec:
gatewayClassName: envoy-gateway-class
listeners:
- name: http-1
protocol: HTTP
port: 81
hostname: foo.com
allowedRoutes:
namespaces:
from: All
- name: http-2
protocol: HTTP
port: 82
hostname: bar.com
allowedRoutes:
namespaces:
from: All
- name: http-3
protocol: HTTP
port: 83
hostname: foo1.com
allowedRoutes:
namespaces:
from: All
- name: http-4
protocol: HTTP
port: 84
hostname: bar1.com
allowedRoutes:
namespaces:
from: All
- name: http-5
protocol: HTTP
port: 85
hostname: foo2.com
allowedRoutes:
namespaces:
from: All
- name: http-6
protocol: HTTP
port: 86
hostname: bar2.com
allowedRoutes:
namespaces:
from: All
- name: http-7
protocol: HTTP
port: 87
hostname: foo3.com
allowedRoutes:
namespaces:
from: All
- name: http-8
protocol: HTTP
port: 88
hostname: bar3.com
allowedRoutes:
namespaces:
from: All
httpRoutes:
- apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
namespace: default
name: httproute-1
spec:
parentRefs:
- namespace: envoy-gateway
name: gateway-1
rules:
- matches:
- path:
value: "/"
backendRefs:
- name: service-1
port: 8080
Loading