Skip to content

Commit

Permalink
Fix package import for HTTPRouteFilterExtensionRef (#821)
Browse files Browse the repository at this point in the history
* Fix package import for HTTPRouteFilterExtensionRef

Caused by merging #791
without rebasing #816

Signed-off-by: Arko Dasgupta <arko@tetrate.io>

* fix test

was failing with below error
```
    --- FAIL: TestProcessHTTPRoutes/httproute_with_one_authenticationfilter (0.00s)
        routes_test.go:221:
            	Error Trace:	/Users/arkodebdasgupta/go-workspace/src/github.com/envoyproxy/gateway/internal/provider/kubernetes/routes_test.go:221
            	Error:      	Received unexpected error:
            	            	List on GroupVersionKind gateway.networking.k8s.io/v1beta1, Kind=HTTPRoute specifies selector on field gatewayHTTPRouteIndex, but no index with name gatewayHTTPRouteIndex has been registered for GroupVersionKind gateway.networking.k8s.io/v1beta1, Kind=HTTPRoute
            	Test:       	TestProcessHTTPRoutes/httproute_with_one_authenticationfilter
```

Signed-off-by: Arko Dasgupta <arko@tetrate.io>

Signed-off-by: Arko Dasgupta <arko@tetrate.io>
  • Loading branch information
arkodg committed Dec 19, 2022
1 parent f420fe1 commit 1762820
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
38 changes: 20 additions & 18 deletions internal/provider/kubernetes/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,23 +520,7 @@ func addReferenceGrantIndexers(ctx context.Context, mgr manager.Manager) error {
// `.spec.rules[].filters`. This helps in querying for HTTPRoutes that are affected by a
// particular AuthenticationFilter CRUD.
func addHTTPRouteIndexers(ctx context.Context, mgr manager.Manager) error {
if err := mgr.GetFieldIndexer().IndexField(ctx, &gwapiv1b1.HTTPRoute{}, gatewayHTTPRouteIndex, func(rawObj client.Object) []string {
httproute := rawObj.(*gwapiv1b1.HTTPRoute)
var gateways []string
for _, parent := range httproute.Spec.ParentRefs {
if string(*parent.Kind) == gatewayapi.KindGateway {
// If an explicit Gateway namespace is not provided, use the HTTPRoute namespace to
// lookup the provided Gateway Name.
gateways = append(gateways,
types.NamespacedName{
Namespace: gatewayapi.NamespaceDerefOr(parent.Namespace, httproute.Namespace),
Name: string(parent.Name),
}.String(),
)
}
}
return gateways
}); err != nil {
if err := mgr.GetFieldIndexer().IndexField(ctx, &gwapiv1b1.HTTPRoute{}, gatewayHTTPRouteIndex, gatewayHTTPRouteIndexFunc); err != nil {
return err
}

Expand All @@ -550,7 +534,7 @@ func addHTTPRouteIndexers(ctx context.Context, mgr manager.Manager) error {
for _, rule := range httproute.Spec.Rules {
for i := range rule.Filters {
filter := rule.Filters[i]
if filter.Type == gwapiv1a2.HTTPRouteFilterExtensionRef {
if filter.Type == gwapiv1b1.HTTPRouteFilterExtensionRef {
if err := gatewayapi.ValidateHTTPRouteFilter(&filter); err != nil {
filters = append(filters,
types.NamespacedName{
Expand All @@ -570,6 +554,24 @@ func addHTTPRouteIndexers(ctx context.Context, mgr manager.Manager) error {
return nil
}

func gatewayHTTPRouteIndexFunc(rawObj client.Object) []string {
httproute := rawObj.(*gwapiv1b1.HTTPRoute)
var gateways []string
for _, parent := range httproute.Spec.ParentRefs {
if parent.Kind == nil || string(*parent.Kind) == gatewayapi.KindGateway {
// If an explicit Gateway namespace is not provided, use the HTTPRoute namespace to
// lookup the provided Gateway Name.
gateways = append(gateways,
types.NamespacedName{
Namespace: gatewayapi.NamespaceDerefOr(parent.Namespace, httproute.Namespace),
Name: string(parent.Name),
}.String(),
)
}
}
return gateways
}

func serviceHTTPRouteIndexFunc(rawObj client.Object) []string {
httproute := rawObj.(*gwapiv1b1.HTTPRoute)
var services []string
Expand Down
6 changes: 5 additions & 1 deletion internal/provider/kubernetes/routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,11 @@ func TestProcessHTTPRoutes(t *testing.T) {
for _, filter := range tc.filters {
objs = append(objs, filter)
}
r.client = fakeclient.NewClientBuilder().WithScheme(envoygateway.GetScheme()).WithObjects(objs...).Build()
r.client = fakeclient.NewClientBuilder().
WithScheme(envoygateway.GetScheme()).
WithObjects(objs...).
WithIndex(&gwapiv1b1.HTTPRoute{}, gatewayHTTPRouteIndex, gatewayHTTPRouteIndexFunc).
Build()

// Process the test case httproutes.
resourceTree := gatewayapi.NewResources()
Expand Down

0 comments on commit 1762820

Please sign in to comment.