diff --git a/internal/gatewayapi/contexts.go b/internal/gatewayapi/contexts.go index 23523401c7..3b1aec98c5 100644 --- a/internal/gatewayapi/contexts.go +++ b/internal/gatewayapi/contexts.go @@ -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 { + if l.Name == listenerName { + return l + } } var listener *v1beta1.Listener @@ -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 } diff --git a/internal/gatewayapi/helpers.go b/internal/gatewayapi/helpers.go index f4313c93b2..4b54b61071 100644 --- a/internal/gatewayapi/helpers.go +++ b/internal/gatewayapi/helpers.go @@ -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) } } diff --git a/internal/gatewayapi/testdata/httproute-attaching-to-gateway-with-more-different-listeners.in.yaml b/internal/gatewayapi/testdata/httproute-attaching-to-gateway-with-more-different-listeners.in.yaml new file mode 100644 index 0000000000..7ec5ee3833 --- /dev/null +++ b/internal/gatewayapi/testdata/httproute-attaching-to-gateway-with-more-different-listeners.in.yaml @@ -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 diff --git a/internal/gatewayapi/testdata/httproute-attaching-to-gateway-with-more-different-listeners.out.yaml b/internal/gatewayapi/testdata/httproute-attaching-to-gateway-with-more-different-listeners.out.yaml new file mode 100644 index 0000000000..c93b03ed7d --- /dev/null +++ b/internal/gatewayapi/testdata/httproute-attaching-to-gateway-with-more-different-listeners.out.yaml @@ -0,0 +1,326 @@ +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 + status: + listeners: + - name: http-1 + supportedKinds: + - group: gateway.networking.k8s.io + kind: HTTPRoute + attachedRoutes: 1 + conditions: + - type: Ready + status: "True" + reason: Ready + message: Listener is ready + - name: http-2 + supportedKinds: + - group: gateway.networking.k8s.io + kind: HTTPRoute + attachedRoutes: 1 + conditions: + - type: Ready + status: "True" + reason: Ready + message: Listener is ready + - name: http-3 + supportedKinds: + - group: gateway.networking.k8s.io + kind: HTTPRoute + attachedRoutes: 1 + conditions: + - type: Ready + status: "True" + reason: Ready + message: Listener is ready + - name: http-4 + supportedKinds: + - group: gateway.networking.k8s.io + kind: HTTPRoute + attachedRoutes: 1 + conditions: + - type: Ready + status: "True" + reason: Ready + message: Listener is ready + - name: http-5 + supportedKinds: + - group: gateway.networking.k8s.io + kind: HTTPRoute + attachedRoutes: 1 + conditions: + - type: Ready + status: "True" + reason: Ready + message: Listener is ready + - name: http-6 + supportedKinds: + - group: gateway.networking.k8s.io + kind: HTTPRoute + attachedRoutes: 1 + conditions: + - type: Ready + status: "True" + reason: Ready + message: Listener is ready + - name: http-7 + supportedKinds: + - group: gateway.networking.k8s.io + kind: HTTPRoute + attachedRoutes: 1 + conditions: + - type: Ready + status: "True" + reason: Ready + message: Listener is ready + - name: http-8 + supportedKinds: + - group: gateway.networking.k8s.io + kind: HTTPRoute + attachedRoutes: 1 + conditions: + - type: Ready + status: "True" + reason: Ready + message: Listener is ready +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 + status: + parents: + - parentRef: + namespace: envoy-gateway + name: gateway-1 + controllerName: gateway.envoyproxy.io/gatewayclass-controller + conditions: + - type: Accepted + status: "True" + reason: Accepted + message: Route is accepted +xdsIR: + envoy-gateway-gateway-1: + http: + - name: envoy-gateway-gateway-1-http-1 + address: 0.0.0.0 + port: 10081 + hostnames: + - foo.com + routes: + - name: default-httproute-1-rule-0-match-0-foo.com + pathMatch: + prefix: "/" + destinations: + - host: 7.7.7.7 + port: 8080 + weight: 1 + - name: envoy-gateway-gateway-1-http-2 + address: 0.0.0.0 + port: 10082 + hostnames: + - bar.com + routes: + - name: default-httproute-1-rule-0-match-0-bar.com + pathMatch: + prefix: "/" + destinations: + - host: 7.7.7.7 + port: 8080 + weight: 1 + - name: envoy-gateway-gateway-1-http-3 + address: 0.0.0.0 + port: 10083 + hostnames: + - foo1.com + routes: + - name: default-httproute-1-rule-0-match-0-foo1.com + pathMatch: + prefix: "/" + destinations: + - host: 7.7.7.7 + port: 8080 + weight: 1 + - name: envoy-gateway-gateway-1-http-4 + address: 0.0.0.0 + port: 10084 + hostnames: + - bar1.com + routes: + - name: default-httproute-1-rule-0-match-0-bar1.com + pathMatch: + prefix: "/" + destinations: + - host: 7.7.7.7 + port: 8080 + weight: 1 + - name: envoy-gateway-gateway-1-http-5 + address: 0.0.0.0 + port: 10085 + hostnames: + - foo2.com + routes: + - name: default-httproute-1-rule-0-match-0-foo2.com + pathMatch: + prefix: "/" + destinations: + - host: 7.7.7.7 + port: 8080 + weight: 1 + - name: envoy-gateway-gateway-1-http-6 + address: 0.0.0.0 + port: 10086 + hostnames: + - bar2.com + routes: + - name: default-httproute-1-rule-0-match-0-bar2.com + pathMatch: + prefix: "/" + destinations: + - host: 7.7.7.7 + port: 8080 + weight: 1 + - name: envoy-gateway-gateway-1-http-7 + address: 0.0.0.0 + port: 10087 + hostnames: + - foo3.com + routes: + - name: default-httproute-1-rule-0-match-0-foo3.com + pathMatch: + prefix: "/" + destinations: + - host: 7.7.7.7 + port: 8080 + weight: 1 + - name: envoy-gateway-gateway-1-http-8 + address: 0.0.0.0 + port: 10088 + hostnames: + - bar3.com + routes: + - name: default-httproute-1-rule-0-match-0-bar3.com + pathMatch: + prefix: "/" + destinations: + - host: 7.7.7.7 + port: 8080 + weight: 1 +infraIR: + envoy-gateway-gateway-1: + proxy: + metadata: + labels: + gateway.envoyproxy.io/owning-gateway-namespace: envoy-gateway + gateway.envoyproxy.io/owning-gateway-name: gateway-1 + name: envoy-gateway-gateway-1 + image: envoyproxy/envoy:v1.23-latest + listeners: + - address: "" + ports: + - name: http-1 + protocol: "HTTP" + servicePort: 81 + containerPort: 10081 + - name: http-2 + protocol: "HTTP" + servicePort: 82 + containerPort: 10082 + - name: http-3 + protocol: "HTTP" + servicePort: 83 + containerPort: 10083 + - name: http-4 + protocol: "HTTP" + servicePort: 84 + containerPort: 10084 + - name: http-5 + protocol: "HTTP" + servicePort: 85 + containerPort: 10085 + - name: http-6 + protocol: "HTTP" + servicePort: 86 + containerPort: 10086 + - name: http-7 + protocol: "HTTP" + servicePort: 87 + containerPort: 10087 + - name: http-8 + protocol: "HTTP" + servicePort: 88 + containerPort: 10088 diff --git a/internal/gatewayapi/testdata/httproute-attaching-to-gateway-with-more-listeners.in.yaml b/internal/gatewayapi/testdata/httproute-attaching-to-gateway-with-more-listeners.in.yaml new file mode 100644 index 0000000000..6d6d34395d --- /dev/null +++ b/internal/gatewayapi/testdata/httproute-attaching-to-gateway-with-more-listeners.in.yaml @@ -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: 80 + hostname: foo.com + allowedRoutes: + namespaces: + from: All + - name: http-2 + protocol: HTTP + port: 80 + hostname: bar.com + allowedRoutes: + namespaces: + from: All + - name: http-3 + protocol: HTTP + port: 80 + hostname: foo1.com + allowedRoutes: + namespaces: + from: All + - name: http-4 + protocol: HTTP + port: 80 + hostname: bar1.com + allowedRoutes: + namespaces: + from: All + - name: http-5 + protocol: HTTP + port: 80 + hostname: foo2.com + allowedRoutes: + namespaces: + from: All + - name: http-6 + protocol: HTTP + port: 80 + hostname: bar2.com + allowedRoutes: + namespaces: + from: All + - name: http-7 + protocol: HTTP + port: 80 + hostname: foo3.com + allowedRoutes: + namespaces: + from: All + - name: http-8 + protocol: HTTP + port: 80 + 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 diff --git a/internal/gatewayapi/testdata/httproute-attaching-to-gateway-with-more-listeners.out.yaml b/internal/gatewayapi/testdata/httproute-attaching-to-gateway-with-more-listeners.out.yaml new file mode 100644 index 0000000000..b0c96ad796 --- /dev/null +++ b/internal/gatewayapi/testdata/httproute-attaching-to-gateway-with-more-listeners.out.yaml @@ -0,0 +1,298 @@ +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: 80 + hostname: foo.com + allowedRoutes: + namespaces: + from: All + - name: http-2 + protocol: HTTP + port: 80 + hostname: bar.com + allowedRoutes: + namespaces: + from: All + - name: http-3 + protocol: HTTP + port: 80 + hostname: foo1.com + allowedRoutes: + namespaces: + from: All + - name: http-4 + protocol: HTTP + port: 80 + hostname: bar1.com + allowedRoutes: + namespaces: + from: All + - name: http-5 + protocol: HTTP + port: 80 + hostname: foo2.com + allowedRoutes: + namespaces: + from: All + - name: http-6 + protocol: HTTP + port: 80 + hostname: bar2.com + allowedRoutes: + namespaces: + from: All + - name: http-7 + protocol: HTTP + port: 80 + hostname: foo3.com + allowedRoutes: + namespaces: + from: All + - name: http-8 + protocol: HTTP + port: 80 + hostname: bar3.com + allowedRoutes: + namespaces: + from: All + status: + listeners: + - name: http-1 + supportedKinds: + - group: gateway.networking.k8s.io + kind: HTTPRoute + attachedRoutes: 1 + conditions: + - type: Ready + status: "True" + reason: Ready + message: Listener is ready + - name: http-2 + supportedKinds: + - group: gateway.networking.k8s.io + kind: HTTPRoute + attachedRoutes: 1 + conditions: + - type: Ready + status: "True" + reason: Ready + message: Listener is ready + - name: http-3 + supportedKinds: + - group: gateway.networking.k8s.io + kind: HTTPRoute + attachedRoutes: 1 + conditions: + - type: Ready + status: "True" + reason: Ready + message: Listener is ready + - name: http-4 + supportedKinds: + - group: gateway.networking.k8s.io + kind: HTTPRoute + attachedRoutes: 1 + conditions: + - type: Ready + status: "True" + reason: Ready + message: Listener is ready + - name: http-5 + supportedKinds: + - group: gateway.networking.k8s.io + kind: HTTPRoute + attachedRoutes: 1 + conditions: + - type: Ready + status: "True" + reason: Ready + message: Listener is ready + - name: http-6 + supportedKinds: + - group: gateway.networking.k8s.io + kind: HTTPRoute + attachedRoutes: 1 + conditions: + - type: Ready + status: "True" + reason: Ready + message: Listener is ready + - name: http-7 + supportedKinds: + - group: gateway.networking.k8s.io + kind: HTTPRoute + attachedRoutes: 1 + conditions: + - type: Ready + status: "True" + reason: Ready + message: Listener is ready + - name: http-8 + supportedKinds: + - group: gateway.networking.k8s.io + kind: HTTPRoute + attachedRoutes: 1 + conditions: + - type: Ready + status: "True" + reason: Ready + message: Listener is ready +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 + status: + parents: + - parentRef: + namespace: envoy-gateway + name: gateway-1 + controllerName: gateway.envoyproxy.io/gatewayclass-controller + conditions: + - type: Accepted + status: "True" + reason: Accepted + message: Route is accepted +xdsIR: + envoy-gateway-gateway-1: + http: + - name: envoy-gateway-gateway-1-http-1 + address: 0.0.0.0 + port: 10080 + hostnames: + - foo.com + routes: + - name: default-httproute-1-rule-0-match-0-foo.com + pathMatch: + prefix: "/" + destinations: + - host: 7.7.7.7 + port: 8080 + weight: 1 + - name: envoy-gateway-gateway-1-http-2 + address: 0.0.0.0 + port: 10080 + hostnames: + - bar.com + routes: + - name: default-httproute-1-rule-0-match-0-bar.com + pathMatch: + prefix: "/" + destinations: + - host: 7.7.7.7 + port: 8080 + weight: 1 + - name: envoy-gateway-gateway-1-http-3 + address: 0.0.0.0 + port: 10080 + hostnames: + - foo1.com + routes: + - name: default-httproute-1-rule-0-match-0-foo1.com + pathMatch: + prefix: "/" + destinations: + - host: 7.7.7.7 + port: 8080 + weight: 1 + - name: envoy-gateway-gateway-1-http-4 + address: 0.0.0.0 + port: 10080 + hostnames: + - bar1.com + routes: + - name: default-httproute-1-rule-0-match-0-bar1.com + pathMatch: + prefix: "/" + destinations: + - host: 7.7.7.7 + port: 8080 + weight: 1 + - name: envoy-gateway-gateway-1-http-5 + address: 0.0.0.0 + port: 10080 + hostnames: + - foo2.com + routes: + - name: default-httproute-1-rule-0-match-0-foo2.com + pathMatch: + prefix: "/" + destinations: + - host: 7.7.7.7 + port: 8080 + weight: 1 + - name: envoy-gateway-gateway-1-http-6 + address: 0.0.0.0 + port: 10080 + hostnames: + - bar2.com + routes: + - name: default-httproute-1-rule-0-match-0-bar2.com + pathMatch: + prefix: "/" + destinations: + - host: 7.7.7.7 + port: 8080 + weight: 1 + - name: envoy-gateway-gateway-1-http-7 + address: 0.0.0.0 + port: 10080 + hostnames: + - foo3.com + routes: + - name: default-httproute-1-rule-0-match-0-foo3.com + pathMatch: + prefix: "/" + destinations: + - host: 7.7.7.7 + port: 8080 + weight: 1 + - name: envoy-gateway-gateway-1-http-8 + address: 0.0.0.0 + port: 10080 + hostnames: + - bar3.com + routes: + - name: default-httproute-1-rule-0-match-0-bar3.com + pathMatch: + prefix: "/" + destinations: + - host: 7.7.7.7 + port: 8080 + weight: 1 +infraIR: + envoy-gateway-gateway-1: + proxy: + metadata: + labels: + gateway.envoyproxy.io/owning-gateway-namespace: envoy-gateway + gateway.envoyproxy.io/owning-gateway-name: gateway-1 + name: envoy-gateway-gateway-1 + image: envoyproxy/envoy:v1.23-latest + listeners: + - address: "" + ports: + - name: http-1 + protocol: "HTTP" + servicePort: 80 + containerPort: 10080