Skip to content

Commit

Permalink
refactor: fetch routes accepted by a given gateway without specifying…
Browse files Browse the repository at this point in the history
… the gateway controller name

Removes the need for authorizing reading gateway classes
  • Loading branch information
guicassolato committed Apr 19, 2024
1 parent 7ec2b8a commit 78e0e42
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 36 deletions.
10 changes: 1 addition & 9 deletions bundle/manifests/kuadrant-operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ metadata:
capabilities: Basic Install
categories: Integration & Delivery
containerImage: quay.io/kuadrant/kuadrant-operator:latest
createdAt: "2024-04-19T09:46:40Z"
createdAt: "2024-04-19T18:30:03Z"
operators.operatorframework.io/builder: operator-sdk-v1.32.0
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
repository: https://github.com/Kuadrant/kuadrant-operator
Expand Down Expand Up @@ -274,14 +274,6 @@ spec:
- patch
- update
- watch
- apiGroups:
- gateway.networking.k8s.io
resources:
- gatewayclasses
verbs:
- get
- list
- watch
- apiGroups:
- gateway.networking.k8s.io
resources:
Expand Down
8 changes: 0 additions & 8 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,6 @@ rules:
- patch
- update
- watch
- apiGroups:
- gateway.networking.k8s.io
resources:
- gatewayclasses
verbs:
- get
- list
- watch
- apiGroups:
- gateway.networking.k8s.io
resources:
Expand Down
1 change: 0 additions & 1 deletion controllers/kuadrant_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ type KuadrantReconciler struct {
//+kubebuilder:rbac:groups=maistra.io,resources=servicemeshmembers,verbs=get;list;watch;create;update;delete;patch

// Common permissions required by policy controllers
//+kubebuilder:rbac:groups=gateway.networking.k8s.io,resources=gatewayclasses,verbs=get;list;watch
//+kubebuilder:rbac:groups=gateway.networking.k8s.io,resources=gateways,verbs=get;list;watch;update;patch
//+kubebuilder:rbac:groups=gateway.networking.k8s.io,resources=gateways/status,verbs=get;update;patch
//+kubebuilder:rbac:groups=gateway.networking.k8s.io,resources=gateways/finalizers,verbs=update
Expand Down
21 changes: 3 additions & 18 deletions pkg/library/reconcilers/target_ref_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
gatewayapiv1 "sigs.k8s.io/gateway-api/apis/v1"

kuadrantgatewayapi "github.com/kuadrant/kuadrant-operator/pkg/library/gatewayapi"
"github.com/kuadrant/kuadrant-operator/pkg/library/kuadrant"
"github.com/kuadrant/kuadrant-operator/pkg/library/utils"
)
Expand All @@ -40,12 +41,6 @@ func (r *TargetRefReconciler) FetchAcceptedGatewayHTTPRoutes(ctx context.Context
logger, _ := logr.FromContext(ctx)
logger = logger.WithName("FetchAcceptedGatewayHTTPRoutes").WithValues("gateway", gwKey)

gatewayClass := &gatewayapiv1.GatewayClass{}
if err := r.Client.Get(ctx, client.ObjectKey{Name: string(gateway.Spec.GatewayClassName)}, gatewayClass); err != nil {
logger.V(1).Info("failed to get controller name", "err", err)
return
}

routeList := &gatewayapiv1.HTTPRouteList{}
err := r.Client.List(ctx, routeList)
if err != nil {
Expand All @@ -55,22 +50,12 @@ func (r *TargetRefReconciler) FetchAcceptedGatewayHTTPRoutes(ctx context.Context

for idx := range routeList.Items {
route := routeList.Items[idx]
routeParentStatus, found := utils.Find(route.Status.RouteStatus.Parents, func(p gatewayapiv1.RouteParentStatus) bool {
return *p.ParentRef.Kind == ("Gateway") &&
p.ControllerName == gatewayClass.Spec.ControllerName &&
((p.ParentRef.Namespace == nil && route.GetNamespace() == gwKey.Namespace) || string(*p.ParentRef.Namespace) == gwKey.Namespace) &&
string(p.ParentRef.Name) == gwKey.Name
})
if found && meta.IsStatusConditionTrue(routeParentStatus.Conditions, string(gatewayapiv1.RouteConditionAccepted)) {
if utils.Index(kuadrantgatewayapi.GetRouteAcceptedGatewayParentKeys(&route), func(parentGatewayKey client.ObjectKey) bool { return parentGatewayKey == gwKey }) >= 0 {

Check warning on line 53 in pkg/library/reconcilers/target_ref_reconciler.go

View check run for this annotation

Codecov / codecov/patch

pkg/library/reconcilers/target_ref_reconciler.go#L53

Added line #L53 was not covered by tests
logger.V(1).Info("found route attached to gateway", "httproute", client.ObjectKeyFromObject(&route))
routes = append(routes, route)
continue
}

logger.V(1).Info("skipping route, not attached to gateway",
"httproute", client.ObjectKeyFromObject(&route),
"isChildRoute", found,
"isAccepted", routeParentStatus != nil && meta.IsStatusConditionTrue(routeParentStatus.Conditions, string(gatewayapiv1.RouteConditionAccepted)))
logger.V(1).Info("skipping route, not attached to gateway", "httproute", client.ObjectKeyFromObject(&route))

Check warning on line 58 in pkg/library/reconcilers/target_ref_reconciler.go

View check run for this annotation

Codecov / codecov/patch

pkg/library/reconcilers/target_ref_reconciler.go#L58

Added line #L58 was not covered by tests
}

return
Expand Down

0 comments on commit 78e0e42

Please sign in to comment.