Skip to content

Commit

Permalink
Scope down Gateway to routes from the same namespace (#45)
Browse files Browse the repository at this point in the history
Signed-off-by: Waleed Malik <[email protected]>
  • Loading branch information
ahmedwaleedmalik authored Aug 12, 2024
1 parent b436a7f commit 0da6f4c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions internal/resources/gatewayapi/gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

"k8s.io/apimachinery/pkg/api/equality"
kerrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/utils/ptr"
ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
)
Expand Down Expand Up @@ -61,6 +62,14 @@ func CreateOrUpdateGateway(ctx context.Context, log logr.Logger, client ctrlclie
return fmt.Errorf("multiple Gateway objects are not supported")
}

// We scope the listeners for the gateway down to the same namespace
for i, listener := range object.Spec.Listeners {
if listener.AllowedRoutes != nil && listener.AllowedRoutes.Namespaces != nil {
object.Spec.Listeners[i].AllowedRoutes.Namespaces.Selector = nil
object.Spec.Listeners[i].AllowedRoutes.Namespaces.From = ptr.To(gwapiv1.NamespacesFromSame)
}
}

// Process annotations.
object.Annotations = kubelb.PropagateAnnotations(object.Annotations, annotations)
object.Namespace = namespace
Expand Down

0 comments on commit 0da6f4c

Please sign in to comment.