Skip to content

Commit

Permalink
ensuring that gateway_checks for the operator respects the hostname c…
Browse files Browse the repository at this point in the history
…onfig in httproute and gateway
  • Loading branch information
cjvirtucio87 committed Feb 8, 2024
1 parent f44e000 commit 72eb9e8
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions operator/pkg/gateway-api/routechecks/gateway_checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ func CheckGatewayAllowedForNamespace(input Input, parentRef gatewayv1.ParentRefe

return false, nil
}

hostnames := input.GetHostnames()
allHostnames := make(map[string]bool)
for _, hostname := range hostnames {
allHostnames[string(hostname)] = true
}

hasNamespaceRestriction := false
for _, listener := range gw.Spec.Listeners {

Expand All @@ -34,9 +41,22 @@ func CheckGatewayAllowedForNamespace(input Input, parentRef gatewayv1.ParentRefe
if listener.AllowedRoutes.Namespaces == nil {
continue
}

if parentRef.SectionName != nil && listener.Name != *parentRef.SectionName {
continue
}

if len(allHostnames) > 0 {
if listener.Hostname == nil {
continue
}

listenerHostname := string(*listener.Hostname)
if _, ok := allHostnames[listenerHostname]; !ok {
continue
}
}

// if gateway allows all namespaces, we do not need to check anything here
if *listener.AllowedRoutes.Namespaces.From == gatewayv1.NamespacesFromAll {
return true, nil
Expand Down

0 comments on commit 72eb9e8

Please sign in to comment.