Skip to content

Commit f5b0777

Browse files
committed
apply review suggestions
1 parent b0e5348 commit f5b0777

File tree

8 files changed

+20
-54
lines changed

8 files changed

+20
-54
lines changed

controller/hybridgateway/route/status.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ func getSpecHostnames[T gwtypes.SupportedRoute](route T) []gwtypes.Hostname {
422422
// This function provides granular feedback for each resource type, allowing users to see exactly which
423423
// resources are not programmed and why, improving troubleshooting and status visibility.
424424
func BuildProgrammedCondition[T gwtypes.SupportedRoute, TPtr gwtypes.SupportedRoutePtr[T]](
425-
ctx context.Context, logger logr.Logger, cl client.Client, route *gwtypes.HTTPRoute,
425+
ctx context.Context, logger logr.Logger, cl client.Client, route TPtr,
426426
pRef gwtypes.ParentReference, expectedGVKs []schema.GroupVersionKind) ([]metav1.Condition, error) {
427427
var conditions []metav1.Condition
428428
am := metadata.NewAnnotationManager(logger)
@@ -453,7 +453,7 @@ func BuildProgrammedCondition[T gwtypes.SupportedRoute, TPtr gwtypes.SupportedRo
453453
// Check if the item is programmed.
454454
prog := isProgrammed(&item)
455455
log.Debug(logger, "Resource programmed status", "gvk", gvk.String(), "name", item.GetName(), "namespace", item.GetNamespace(), "programmed", prog)
456-
conditions = append(conditions, *SetConditionMeta(GetProgrammedConditionForGVK(gvk, prog), route))
456+
conditions = append(conditions, *SetConditionMeta[T](GetProgrammedConditionForGVK(gvk, prog), route))
457457
}
458458
}
459459

@@ -554,7 +554,7 @@ func BuildResolvedRefsConditionForHTTPRoute(ctx context.Context, logger logr.Log
554554
return SetConditionMeta(*cond, route), nil
555555
}
556556

557-
// backendRefResolvedCondition returns the ResolvedRefs condition of the route according to the status of the given banckendRef in the route.
557+
// backendRefResolvedCondition returns the ResolvedRefs condition of the route according to the status of the given backendRef in the route.
558558
//
559559
// Parameters:
560560
// - ctx: Context for API calls

controller/hybridgateway/route/status_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1840,7 +1840,7 @@ func TestIsRouteReferenceGranted(t *testing.T) {
18401840
t.Run(tt.name, func(t *testing.T) {
18411841
got := IsRouteReferenceGranted(tt.grantSpec, tt.backendRef.BackendRef, "HTTPRoute", tt.fromNamespace)
18421842
if got != tt.want {
1843-
t.Errorf("IsHTTPReferenceGranted() = %v, want %v", got, tt.want)
1843+
t.Errorf("IsRouteReferenceGranted() = %v, want %v", got, tt.want)
18441844
}
18451845
})
18461846
}

controller/hybridgateway/target/target.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ func filterValidBackendRefs(
303303

304304
// Check ReferenceGrant permission for cross-namespace access.
305305
if bRefNamespace != httpRoute.Namespace {
306-
permitted, found, err := route.CheckReferenceGrant(ctx, cl, &bRef.BackendRef, httpRoute.Kind, httpRoute.Namespace)
306+
permitted, found, err := route.CheckReferenceGrant(ctx, cl, &bRef.BackendRef, httpRoute.GetObjectKind().GroupVersionKind().Kind, httpRoute.Namespace)
307307
if err != nil {
308308
return nil, fmt.Errorf("error checking ReferenceGrant for BackendRef %s: %w", bRef.Name, err)
309309
}

controller/hybridgateway/watch/mapfuncs_gateway_route.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
// This file is for map functions shared by all supported routes in gateway APIs.
2121

2222
// kongResource is a type constraint that encompasses all Kong resource types
23-
// that can be mapped back to HTTPRoutes via annotations.
23+
// that can be mapped back to routes with supported type via annotations.
2424
type kongResource interface {
2525
*configurationv1alpha1.KongUpstream |
2626
*configurationv1alpha1.KongTarget |
@@ -31,7 +31,7 @@ type kongResource interface {
3131
}
3232

3333
// MapRouteForKongResource returns a handler.MapFunc that, given a Kong resource object of type T,
34-
// retrieves the routesreferenced in its annotations. It returns a slice of reconcile.Requests
34+
// retrieves the routes referenced in its annotations. It returns a slice of reconcile.Requests
3535
// for each matching route.
3636
func MapRouteForKongResource[T kongResource](cl client.Client) handler.MapFunc {
3737
return func(ctx context.Context, obj client.Object) []reconcile.Request {

controller/hybridgateway/watch/mapfuncs_gateway_route_test.go

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ func Test_MapRouteForService(t *testing.T) {
246246
BackendRef: gwtypes.BackendRef{
247247
BackendObjectReference: gwtypes.BackendObjectReference{
248248
Name: gatewayv1.ObjectName("test-svc"),
249+
Port: new(gatewayv1.PortNumber(80)),
249250
},
250251
},
251252
}},
@@ -256,19 +257,7 @@ func Test_MapRouteForService(t *testing.T) {
256257
cl := fake.NewClientBuilder().
257258
WithScheme(scheme).
258259
WithObjects(svc, httpRoute).
259-
WithIndex(&gwtypes.HTTPRoute{}, index.BackendServicesOnHTTPRouteIndex, func(obj client.Object) []string {
260-
httpRoute, ok := obj.(*gwtypes.HTTPRoute)
261-
if !ok {
262-
return nil
263-
}
264-
var keys []string
265-
for _, rule := range httpRoute.Spec.Rules {
266-
for _, ref := range rule.BackendRefs {
267-
keys = append(keys, httpRoute.Namespace+"/"+string(ref.BackendRef.Name))
268-
}
269-
}
270-
return keys
271-
}).
260+
WithIndex(&gwtypes.HTTPRoute{}, index.BackendServicesOnHTTPRouteIndex, index.BackendServicesOnHTTPRoute).
272261
Build()
273262

274263
mapFunc := MapRouteForService(cl, &gwtypes.HTTPRoute{})
@@ -293,19 +282,7 @@ func Test_MapRouteForService(t *testing.T) {
293282
clDiffNS := fake.NewClientBuilder().
294283
WithScheme(scheme).
295284
WithObjects(otherSvc, httpRoute).
296-
WithIndex(&gwtypes.HTTPRoute{}, index.BackendServicesOnHTTPRouteIndex, func(obj client.Object) []string {
297-
httpRoute, ok := obj.(*gwtypes.HTTPRoute)
298-
if !ok {
299-
return nil
300-
}
301-
var keys []string
302-
for _, rule := range httpRoute.Spec.Rules {
303-
for _, ref := range rule.BackendRefs {
304-
keys = append(keys, httpRoute.Namespace+"/"+string(ref.BackendRef.Name))
305-
}
306-
}
307-
return keys
308-
}).
285+
WithIndex(&gwtypes.HTTPRoute{}, index.BackendServicesOnHTTPRouteIndex, index.BackendServicesOnHTTPRoute).
309286
Build()
310287
mapFuncDiffNS := MapRouteForService(clDiffNS, &gwtypes.HTTPRoute{})
311288
ctx := context.Background()
@@ -356,6 +333,7 @@ func Test_MapRouteForEndpointSlice(t *testing.T) {
356333
BackendRef: gwtypes.BackendRef{
357334
BackendObjectReference: gwtypes.BackendObjectReference{
358335
Name: gatewayv1.ObjectName("test-svc"),
336+
Port: new(gatewayv1.PortNumber(80)),
359337
},
360338
},
361339
}},
@@ -376,19 +354,7 @@ func Test_MapRouteForEndpointSlice(t *testing.T) {
376354
cl := fake.NewClientBuilder().
377355
WithScheme(scheme).
378356
WithObjects(svc, httpRoute, epSlice).
379-
WithIndex(&gwtypes.HTTPRoute{}, index.BackendServicesOnHTTPRouteIndex, func(obj client.Object) []string {
380-
httpRoute, ok := obj.(*gwtypes.HTTPRoute)
381-
if !ok {
382-
return nil
383-
}
384-
var keys []string
385-
for _, rule := range httpRoute.Spec.Rules {
386-
for _, ref := range rule.BackendRefs {
387-
keys = append(keys, httpRoute.Namespace+"/"+string(ref.BackendRef.Name))
388-
}
389-
}
390-
return keys
391-
}).
357+
WithIndex(&gwtypes.HTTPRoute{}, index.BackendServicesOnHTTPRouteIndex, index.BackendServicesOnHTTPRoute).
392358
Build()
393359

394360
mapFunc := MapRouteForEndpointSlice(cl, &gwtypes.HTTPRoute{})

internal/utils/index/gateway_route_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
gwtypes "github.com/kong/kong-operator/v2/internal/types"
1212
)
1313

14-
func TestGatewaysOnRoute(t *testing.T) {
14+
func TestGatewaysOnRoute_HTTPRoute(t *testing.T) {
1515
tests := []struct {
1616
name string
1717
obj client.Object
@@ -109,7 +109,7 @@ func TestGatewaysOnRoute(t *testing.T) {
109109

110110
for _, tt := range tests {
111111
t.Run(tt.name, func(t *testing.T) {
112-
got := GatewaysOnRoute(tt.obj)
112+
got := GatewaysOnRoute[gwtypes.HTTPRoute](tt.obj)
113113
require.ElementsMatch(t, tt.want, got)
114114
})
115115
}

internal/utils/index/httproute.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func OptionsForHTTPRoute() []Option {
2828
{
2929
Object: &gwtypes.HTTPRoute{},
3030
Field: BackendServicesOnHTTPRouteIndex,
31-
ExtractValueFn: backendServicesOnHTTPRoute,
31+
ExtractValueFn: BackendServicesOnHTTPRoute,
3232
},
3333
{
3434
Object: &gwtypes.HTTPRoute{},
@@ -43,9 +43,9 @@ func OptionsForHTTPRoute() []Option {
4343
}
4444
}
4545

46-
// backendServicesOnHTTPRoute extracts and returns a list of unique Service references (in "namespace/name" format)
46+
// BackendServicesOnHTTPRoute extracts and returns a list of unique Service references (in "namespace/name" format)
4747
// from the BackendRefs of the given HTTPRoute object.
48-
func backendServicesOnHTTPRoute(o client.Object) []string {
48+
func BackendServicesOnHTTPRoute(o client.Object) []string {
4949
httpRoute, ok := o.(*gwtypes.HTTPRoute)
5050
if !ok {
5151
return nil

internal/utils/index/httproute_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func TestBackendRefOnHTTPRoute(t *testing.T) {
142142

143143
for _, tc := range testCases {
144144
t.Run(tc.name, func(t *testing.T) {
145-
got := backendServicesOnHTTPRoute(tc.obj)
145+
got := BackendServicesOnHTTPRoute(tc.obj)
146146
require.ElementsMatch(t, tc.want, got)
147147
})
148148
}
@@ -167,7 +167,7 @@ func TestKongPluginsOnHTTPRoute(t *testing.T) {
167167
want: nil,
168168
},
169169
{
170-
name: "single filter with extenstionRef type",
170+
name: "single filter with extensionRef type",
171171
obj: &gwtypes.HTTPRoute{
172172
ObjectMeta: metav1.ObjectMeta{Namespace: "ns1"},
173173
Spec: gwtypes.HTTPRouteSpec{
@@ -213,7 +213,7 @@ func TestKongPluginsOnHTTPRoute(t *testing.T) {
213213
want: nil,
214214
},
215215
{
216-
name: "multiple exensionRefs with duplicate names",
216+
name: "multiple extensionRefs with duplicate names",
217217
obj: &gwtypes.HTTPRoute{
218218
ObjectMeta: metav1.ObjectMeta{Namespace: "ns1"},
219219
Spec: gwtypes.HTTPRouteSpec{

0 commit comments

Comments
 (0)