Skip to content

Commit

Permalink
fixup: address comments
Browse files Browse the repository at this point in the history
Signed-off-by: KevFan <[email protected]>
  • Loading branch information
KevFan committed Aug 15, 2024
1 parent 791eee4 commit 2326be8
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 39 deletions.
20 changes: 4 additions & 16 deletions controller/topology_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,22 @@ type gatewayAPITopologyBuilder struct {
func (t *gatewayAPITopologyBuilder) Build(objs Store) *machinery.Topology {
gatewayClasses := lo.FilterMap(lo.Values(objs[machinery.GatewayClassGroupKind]), func(obj RuntimeObject, _ int) (*gwapiv1.GatewayClass, bool) {
gc, ok := obj.(*gwapiv1.GatewayClass)
if !ok {
return nil, false
}
return gc, true
return gc, ok
})

gateways := lo.FilterMap(lo.Values(objs[machinery.GatewayGroupKind]), func(obj RuntimeObject, _ int) (*gwapiv1.Gateway, bool) {
gw, ok := obj.(*gwapiv1.Gateway)
if !ok {
return nil, false
}
return gw, true
return gw, ok
})

httpRoutes := lo.FilterMap(lo.Values(objs[machinery.HTTPRouteGroupKind]), func(obj RuntimeObject, _ int) (*gwapiv1.HTTPRoute, bool) {
httpRoute, ok := obj.(*gwapiv1.HTTPRoute)
if !ok {
return nil, false
}
return httpRoute, true
return httpRoute, ok
})

services := lo.FilterMap(lo.Values(objs[machinery.ServiceGroupKind]), func(obj RuntimeObject, _ int) (*core.Service, bool) {
service, ok := obj.(*core.Service)
if !ok {
return nil, false
}
return service, true
return service, ok
})

linkFuncs := lo.Map(t.objectLinks, func(linkFunc RuntimeLinkFunc, _ int) machinery.LinkFunc {
Expand Down
5 changes: 5 additions & 0 deletions machinery/core_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import (
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
)

var (
ServiceGroupKind = schema.GroupKind{Kind: "Service"}
ServicePortGroupKind = schema.GroupKind{Kind: "ServicePort"}
)

// These are wrappers for Core API types so instances can be used as targetables in the topology.

type Namespace struct {
Expand Down
19 changes: 0 additions & 19 deletions machinery/gateway_api_topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,11 @@ import (

"github.com/samber/lo"
core "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/utils/ptr"
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
gwapiv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
)

var (
GatewayClassGroupKind = schema.GroupKind{Group: gwapiv1.GroupVersion.Group, Kind: "GatewayClass"}
GatewayGroupKind = schema.GroupKind{Group: gwapiv1.GroupVersion.Group, Kind: "Gateway"}
ListenerGroupKind = schema.GroupKind{Group: gwapiv1.GroupVersion.Group, Kind: "Listener"}
HTTPRouteGroupKind = schema.GroupKind{Group: gwapiv1.GroupVersion.Group, Kind: "HTTPRoute"}
HTTPRouteRuleGroupKind = schema.GroupKind{Group: gwapiv1.GroupVersion.Group, Kind: "HTTPRouteRule"}
GRPCRouteGroupKind = schema.GroupKind{Group: gwapiv1.GroupVersion.Group, Kind: "GRPCRoute"}
GRPCRouteRuleGroupKind = schema.GroupKind{Group: gwapiv1.GroupVersion.Group, Kind: "GRPCRouteRule"}
TCPRouteGroupKind = schema.GroupKind{Group: gwapiv1alpha2.GroupVersion.Group, Kind: "TCPRoute"}
TCPRouteRuleGroupKind = schema.GroupKind{Group: gwapiv1alpha2.GroupVersion.Group, Kind: "TCPRouteRule"}
TLSRouteGroupKind = schema.GroupKind{Group: gwapiv1alpha2.GroupVersion.Group, Kind: "TLSRoute"}
TLSRouteRuleGroupKind = schema.GroupKind{Group: gwapiv1alpha2.GroupVersion.Group, Kind: "TLSRouteRule"}
UDPRouteGroupKind = schema.GroupKind{Group: gwapiv1alpha2.GroupVersion.Group, Kind: "UDPRoute"}
UDPRouteRuleGroupKind = schema.GroupKind{Group: gwapiv1alpha2.GroupVersion.Group, Kind: "UDPRouteRule"}
ServiceGroupKind = schema.GroupKind{Kind: "Service"}
ServicePortGroupKind = schema.GroupKind{Kind: "ServicePort"}
)

type GatewayAPITopologyOptions struct {
GatewayClasses []*GatewayClass
Gateways []*Gateway
Expand Down
8 changes: 4 additions & 4 deletions machinery/gateway_api_topology_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import (
// This results in a topology with the following scheme:
//
// GatewayClass -> Gateway -> HTTPRoute -> Service
// ∟> GRPCRoute ⤴
// ∟> TCPRoute ⤴
// ∟> TLSRoute ⤴
// ∟> UDPRoute ⤴
// ∟> GRPCRoute ⤴
// ∟> TCPRoute ⤴
// ∟> TLSRoute ⤴
// ∟> UDPRoute ⤴
func TestGatewayAPITopology(t *testing.T) {
testCases := []struct {
name string
Expand Down
16 changes: 16 additions & 0 deletions machinery/gateway_api_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@ import (
gwapiv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"
)

var (
GatewayClassGroupKind = schema.GroupKind{Group: gwapiv1.GroupVersion.Group, Kind: "GatewayClass"}
GatewayGroupKind = schema.GroupKind{Group: gwapiv1.GroupVersion.Group, Kind: "Gateway"}
ListenerGroupKind = schema.GroupKind{Group: gwapiv1.GroupVersion.Group, Kind: "Listener"}
HTTPRouteGroupKind = schema.GroupKind{Group: gwapiv1.GroupVersion.Group, Kind: "HTTPRoute"}
HTTPRouteRuleGroupKind = schema.GroupKind{Group: gwapiv1.GroupVersion.Group, Kind: "HTTPRouteRule"}
GRPCRouteGroupKind = schema.GroupKind{Group: gwapiv1.GroupVersion.Group, Kind: "GRPCRoute"}
GRPCRouteRuleGroupKind = schema.GroupKind{Group: gwapiv1.GroupVersion.Group, Kind: "GRPCRouteRule"}
TCPRouteGroupKind = schema.GroupKind{Group: gwapiv1alpha2.GroupVersion.Group, Kind: "TCPRoute"}
TCPRouteRuleGroupKind = schema.GroupKind{Group: gwapiv1alpha2.GroupVersion.Group, Kind: "TCPRouteRule"}
TLSRouteGroupKind = schema.GroupKind{Group: gwapiv1alpha2.GroupVersion.Group, Kind: "TLSRoute"}
TLSRouteRuleGroupKind = schema.GroupKind{Group: gwapiv1alpha2.GroupVersion.Group, Kind: "TLSRouteRule"}
UDPRouteGroupKind = schema.GroupKind{Group: gwapiv1alpha2.GroupVersion.Group, Kind: "UDPRoute"}
UDPRouteRuleGroupKind = schema.GroupKind{Group: gwapiv1alpha2.GroupVersion.Group, Kind: "UDPRouteRule"}
)

const nameSectionNameURLSeparator = '#'

// These are wrappers for Gateway API types so instances can be used as targetables in the topology.
Expand Down

0 comments on commit 2326be8

Please sign in to comment.