From 5a979782d8fab98c709eb650a5dda32d970f01a1 Mon Sep 17 00:00:00 2001 From: Eguzki Astiz Lezaun Date: Tue, 10 Oct 2023 10:38:35 +0200 Subject: [PATCH] wip --- pkg/common/gatewayapi_utils.go | 27 +++++++++++++++++++++++++++ pkg/common/kuadrant_topology.go | 15 +++++++++++---- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/pkg/common/gatewayapi_utils.go b/pkg/common/gatewayapi_utils.go index eed66d91e..d693dcf7b 100644 --- a/pkg/common/gatewayapi_utils.go +++ b/pkg/common/gatewayapi_utils.go @@ -657,3 +657,30 @@ func AddHTTPRouteByGatewayIndexer(mgr ctrl.Manager, logger logr.Logger) error { return nil } + +func GetRouteAcceptedGatewayParentKeys(route *gatewayapiv1beta1.HTTPRoute) []client.ObjectKey { + if route == nil { + return nil + } + + acceptedRouteParentStatus := Filter(route.Status.RouteStatus.Parents, func(p gatewayapiv1beta1.RouteParentStatus) bool { + // Only gateway parents + if IsParentGateway(p.ParentRef) { + return false + } + + // Only gateways that accepted this route + if meta.IsStatusConditionFalse(p.Conditions, "Accepted") { + return false + } + + return true + }) + + return Map(acceptedRouteParentStatus, func(p gatewayapiv1beta1.RouteParentStatus) client.ObjectKey { + return client.ObjectKey{ + Name: string(p.ParentRef.Name), + Namespace: string(ptr.Deref(p.ParentRef.Namespace, gatewayapiv1beta1.Namespace(route.Namespace))), + } + }) +} diff --git a/pkg/common/kuadrant_topology.go b/pkg/common/kuadrant_topology.go index 676de1c82..563220b58 100644 --- a/pkg/common/kuadrant_topology.go +++ b/pkg/common/kuadrant_topology.go @@ -158,13 +158,20 @@ func (g *gatewayAPITopology) RouteFromPolicy(policy KuadrantPolicy) *gatewayapiv } func (g *gatewayAPITopology) GetRouteParents(route *gatewayapiv1beta1.HTTPRoute) []*gatewayapiv1beta1.Gateway { - // TODO - return nil + parentKeys := GetRouteAcceptedGatewayParentKeys(route) + gatewaysWithNils := Map(parentKeys, func(key client.ObjectKey) *gatewayapiv1beta1.Gateway { + return g.gatewaysIndex[key] + }) + + return Filter(gatewaysWithNils, func(g *gatewayapiv1beta1.Gateway) bool { return g != nil }) } func (g *gatewayAPITopology) GetGateways() []*gatewayapiv1beta1.Gateway { - // TODO - return nil + gateways := make([]*gatewayapiv1beta1.Gateway, 0, len(g.gatewaysIndex)) + for _, val := range g.gatewaysIndex { + gateways = append(gateways, val) + } + return gateways } func (g *gatewayAPITopology) GetGatewayRoutes(gateway *gatewayapiv1beta1.Gateway) []*gatewayapiv1beta1.HTTPRoute {