Skip to content

Commit

Permalink
disable HTTPRoute indexer when CRDs not present (#623)
Browse files Browse the repository at this point in the history
  • Loading branch information
eguzki authored May 7, 2024
1 parent 25c738d commit 37ff046
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
10 changes: 10 additions & 0 deletions controllers/rate_limiting_wasmplugin_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,16 @@ func (r *RateLimitingWASMPluginReconciler) routeFromRLP(ctx context.Context, t *
// to prevent creating the same index field multiple times, the function is declared private to be
// called only by this controller
func addHTTPRouteByGatewayIndexer(mgr ctrl.Manager, baseLogger logr.Logger) error {
ok, err := kuadrantgatewayapi.IsGatewayAPIInstalled(mgr.GetRESTMapper())
if err != nil {
return nil

Check warning on line 348 in controllers/rate_limiting_wasmplugin_controller.go

View check run for this annotation

Codecov / codecov/patch

controllers/rate_limiting_wasmplugin_controller.go#L348

Added line #L348 was not covered by tests
}

if !ok {
baseLogger.Info("GatewayAPI CRDs not found. Disabling HTTPRoute indexer")
return nil

Check warning on line 353 in controllers/rate_limiting_wasmplugin_controller.go

View check run for this annotation

Codecov / codecov/patch

controllers/rate_limiting_wasmplugin_controller.go#L352-L353

Added lines #L352 - L353 were not covered by tests
}

if err := mgr.GetFieldIndexer().IndexField(context.Background(), &gatewayapiv1.HTTPRoute{}, HTTPRouteGatewayParentField, func(rawObj client.Object) []string {
// grab the route object, extract the parents
route, assertionOk := rawObj.(*gatewayapiv1.HTTPRoute)
Expand Down
18 changes: 18 additions & 0 deletions pkg/library/gatewayapi/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/client"
gatewayapiv1 "sigs.k8s.io/gateway-api/apis/v1"
Expand Down Expand Up @@ -148,3 +149,20 @@ func FilterValidSubdomains(domains, subdomains []gatewayapiv1.Hostname) []gatewa
}
return arr
}

func IsGatewayAPIInstalled(restMapper meta.RESTMapper) (bool, error) {
_, err := restMapper.RESTMapping(
schema.GroupKind{Group: gatewayapiv1.GroupName, Kind: "HTTPRoute"},
gatewayapiv1.SchemeGroupVersion.Version,
)

if err == nil {
return true, nil
}

if meta.IsNoMatchError(err) {
return false, nil

Check warning on line 164 in pkg/library/gatewayapi/utils.go

View check run for this annotation

Codecov / codecov/patch

pkg/library/gatewayapi/utils.go#L163-L164

Added lines #L163 - L164 were not covered by tests
}

return false, err

Check warning on line 167 in pkg/library/gatewayapi/utils.go

View check run for this annotation

Codecov / codecov/patch

pkg/library/gatewayapi/utils.go#L167

Added line #L167 was not covered by tests
}

0 comments on commit 37ff046

Please sign in to comment.