Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix status for parentRef with invalid listener in HTTPRoute #350

Merged
merged 2 commits into from
Jan 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions internal/state/conditions/httproute.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import (
"sigs.k8s.io/gateway-api/apis/v1beta1"
)

// RouteReasonInvalidListener is used with the "Accepted" condition when the route references an invalid listener.
const RouteReasonInvalidListener v1beta1.RouteConditionReason = "InvalidListener"

// RouteCondition defines a condition to be reported in the status of an HTTPRoute.
type RouteCondition struct {
Type v1beta1.RouteConditionType
Expand Down Expand Up @@ -70,3 +73,14 @@ func NewRouteTODO(msg string) RouteCondition {
Message: fmt.Sprintf("The condition for this has not been implemented yet: %s", msg),
}
}

// NewRouteInvalidListener returns a RouteCondition that indicates that the HTTPRoute is not accepted because of an
// invalid listener.
func NewRouteInvalidListener() RouteCondition {
return RouteCondition{
Type: v1beta1.RouteConditionAccepted,
Status: metav1.ConditionFalse,
Reason: RouteReasonInvalidListener,
Message: "The listener is invalid for this parent ref",
}
}
5 changes: 5 additions & 0 deletions internal/state/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,11 @@ func bindHTTPRouteToListeners(
continue
}

if !l.Valid {
r.InvalidSectionNameRefs[name] = conditions.NewRouteInvalidListener()
continue
}

accepted := findAcceptedHostnames(l.Source.Hostname, ghr.Spec.Hostnames)

if len(accepted) > 0 {
Expand Down
24 changes: 24 additions & 0 deletions internal/state/graph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,30 @@ func TestBindRouteToListeners(t *testing.T) {
expectedListeners: nil,
msg: "HTTPRoute when no gateway exists",
},
{
httpRoute: hrFoo,
gw: gw,
ignoredGws: nil,
listeners: map[string]*listener{
"listener-80-1": createModifiedListener(func(l *listener) {
l.Valid = false
}),
},
expectedIgnored: false,
expectedRoute: &route{
Source: hrFoo,
ValidSectionNameRefs: map[string]struct{}{},
InvalidSectionNameRefs: map[string]conditions.RouteCondition{
"listener-80-1": conditions.NewRouteInvalidListener(),
},
},
expectedListeners: map[string]*listener{
"listener-80-1": createModifiedListener(func(l *listener) {
l.Valid = false
}),
},
msg: "HTTPRoute with invalid listener parentRef",
},
}

for _, test := range tests {
Expand Down