Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
eguzki committed Oct 10, 2023
1 parent 97672db commit 5a97978
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
27 changes: 27 additions & 0 deletions pkg/common/gatewayapi_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))),
}
})
}
15 changes: 11 additions & 4 deletions pkg/common/kuadrant_topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 5a97978

Please sign in to comment.