Skip to content
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
1 change: 1 addition & 0 deletions changelogs/unreleased/5131-izturn-small.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Gateway API: for routes, always set ResolvedRefs condition, even if true to match the spec.
18 changes: 10 additions & 8 deletions internal/dag/gatewayapi_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,17 +254,19 @@ func (p *GatewayAPIProcessor) processRoute(
)
}

// Check for an existing "Accepted" condition, add one if one does
// Check for an existing "ResolvedRefs" condition, add one if one does
// not already exist.
hasAccepted := false
for _, cond := range routeParentStatus.ConditionsForParentRef(routeParentRef) {
if cond.Type == string(gatewayapi_v1beta1.RouteConditionAccepted) {
hasAccepted = true
break
}
if !routeParentStatus.ConditionExists(gatewayapi_v1beta1.RouteConditionResolvedRefs) {
routeParentStatus.AddCondition(
gatewayapi_v1beta1.RouteConditionResolvedRefs,
metav1.ConditionTrue,
gatewayapi_v1beta1.RouteReasonResolvedRefs,
"References resolved")
}

if !hasAccepted {
// Check for an existing "Accepted" condition, add one if one does
// not already exist.
if !routeParentStatus.ConditionExists(gatewayapi_v1beta1.RouteConditionAccepted) {
routeParentStatus.AddCondition(
gatewayapi_v1beta1.RouteConditionAccepted,
metav1.ConditionTrue,
Expand Down
65 changes: 52 additions & 13 deletions internal/dag/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4480,12 +4480,14 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) {
RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{
{
ParentRef: gatewayapi.GatewayParentRef("projectcontour", "contour"),
Conditions: []metav1.Condition{{
Type: string(gatewayapi_v1beta1.RouteConditionAccepted),
Status: contour_api_v1.ConditionTrue,
Reason: string(gatewayapi_v1beta1.RouteReasonAccepted),
Message: "Accepted HTTPRoute",
}},
Conditions: []metav1.Condition{
routeResolvedRefsCondition(),
{
Type: string(gatewayapi_v1beta1.RouteConditionAccepted),
Status: contour_api_v1.ConditionTrue,
Reason: string(gatewayapi_v1beta1.RouteReasonAccepted),
Message: "Accepted HTTPRoute",
}},
},
},
}},
Expand Down Expand Up @@ -4533,6 +4535,7 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) {
RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{{
ParentRef: gatewayapi.GatewayParentRef("projectcontour", "contour"),
Conditions: []metav1.Condition{
routeResolvedRefsCondition(),
{
Type: string(gatewayapi_v1beta1.RouteConditionAccepted),
Status: contour_api_v1.ConditionTrue,
Expand Down Expand Up @@ -4591,6 +4594,7 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) {
{
ParentRef: gatewayapi.GatewayParentRef("projectcontour", "contour"),
Conditions: []metav1.Condition{
routeResolvedRefsCondition(),
{
Type: string(gatewayapi_v1beta1.RouteConditionAccepted),
Status: contour_api_v1.ConditionTrue,
Expand All @@ -4607,6 +4611,7 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) {
{
ParentRef: gatewayapi.GatewayParentRef("projectcontour", "contour"),
Conditions: []metav1.Condition{
routeResolvedRefsCondition(),
{
Type: string(gatewayapi_v1beta1.RouteConditionAccepted),
Status: contour_api_v1.ConditionTrue,
Expand Down Expand Up @@ -4668,13 +4673,13 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) {
Reason: string(status.ReasonInvalidPathMatch),
Message: "Match.Path.Value must start with '/'.",
},
routeResolvedRefsCondition(),
},
},
},
}},
wantGatewayStatusUpdate: validGatewayStatusUpdate("http", "HTTPRoute", 0),
})

run(t, "exact path match not starting with '/' for httproute", testcase{
objs: []interface{}{
kuardService,
Expand Down Expand Up @@ -4710,6 +4715,7 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) {
{
ParentRef: gatewayapi.GatewayParentRef("projectcontour", "contour"),
Conditions: []metav1.Condition{
routeResolvedRefsCondition(),
{
Type: string(gatewayapi_v1beta1.RouteConditionAccepted),
Status: contour_api_v1.ConditionTrue,
Expand Down Expand Up @@ -4764,6 +4770,7 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) {
{
ParentRef: gatewayapi.GatewayParentRef("projectcontour", "contour"),
Conditions: []metav1.Condition{
routeResolvedRefsCondition(),
{
Type: string(gatewayapi_v1beta1.RouteConditionAccepted),
Status: contour_api_v1.ConditionTrue,
Expand Down Expand Up @@ -4818,6 +4825,7 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) {
{
ParentRef: gatewayapi.GatewayParentRef("projectcontour", "contour"),
Conditions: []metav1.Condition{
routeResolvedRefsCondition(),
{
Type: string(gatewayapi_v1beta1.RouteConditionAccepted),
Status: contour_api_v1.ConditionTrue,
Expand Down Expand Up @@ -4872,6 +4880,7 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) {
{
ParentRef: gatewayapi.GatewayParentRef("projectcontour", "contour"),
Conditions: []metav1.Condition{
routeResolvedRefsCondition(),
{
Type: string(gatewayapi_v1beta1.RouteConditionAccepted),
Status: contour_api_v1.ConditionFalse,
Expand Down Expand Up @@ -4915,6 +4924,7 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) {
{
ParentRef: gatewayapi.GatewayParentRef("projectcontour", "contour"),
Conditions: []metav1.Condition{
routeResolvedRefsCondition(),
{
Type: string(gatewayapi_v1beta1.RouteConditionAccepted),
Status: contour_api_v1.ConditionFalse,
Expand Down Expand Up @@ -4970,6 +4980,7 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) {
{
ParentRef: gatewayapi.GatewayParentRef("projectcontour", "contour"),
Conditions: []metav1.Condition{
routeResolvedRefsCondition(),
{
Type: string(gatewayapi_v1beta1.RouteConditionAccepted),
Status: contour_api_v1.ConditionFalse,
Expand Down Expand Up @@ -5022,6 +5033,7 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) {
{
ParentRef: gatewayapi.GatewayParentRef("projectcontour", "contour"),
Conditions: []metav1.Condition{
routeResolvedRefsCondition(),
{
Type: string(gatewayapi_v1beta1.RouteConditionAccepted),
Status: contour_api_v1.ConditionFalse,
Expand Down Expand Up @@ -5080,6 +5092,7 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) {
Reason: string(status.ReasonDegraded),
Message: "Spec.Rules.BackendRef.Name must be specified",
},

{
Type: string(gatewayapi_v1beta1.RouteConditionAccepted),
Status: contour_api_v1.ConditionTrue,
Expand Down Expand Up @@ -6194,6 +6207,7 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) {
{
ParentRef: gatewayapi.GatewayParentRef("projectcontour", "contour"),
Conditions: []metav1.Condition{
routeResolvedRefsCondition(),
{
Type: string(gatewayapi_v1beta1.RouteConditionAccepted),
Status: contour_api_v1.ConditionTrue,
Expand Down Expand Up @@ -6323,6 +6337,7 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) {
{
ParentRef: gatewayapi.GatewayParentRef("projectcontour", "contour"),
Conditions: []metav1.Condition{
routeResolvedRefsCondition(),
{
Type: string(gatewayapi_v1beta1.RouteConditionAccepted),
Status: contour_api_v1.ConditionFalse,
Expand Down Expand Up @@ -6699,6 +6714,7 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) {
{
ParentRef: gatewayapi.GatewayListenerParentRef("projectcontour", "contour", "listener-1", 80),
Conditions: []metav1.Condition{
routeResolvedRefsCondition(),
{
Type: string(gatewayapi_v1beta1.RouteConditionAccepted),
Status: contour_api_v1.ConditionTrue,
Expand Down Expand Up @@ -6793,6 +6809,7 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) {
{
ParentRef: gatewayapi.GatewayParentRef("projectcontour", "contour"),
Conditions: []metav1.Condition{
routeResolvedRefsCondition(),
{
Type: string(gatewayapi_v1beta1.RouteConditionAccepted),
Status: contour_api_v1.ConditionTrue,
Expand Down Expand Up @@ -7114,6 +7131,7 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) {
Reason: string(gatewayapi_v1beta1.RouteReasonUnsupportedValue),
Message: "HTTPRoute.Spec.Rules.BackendRef.Filters: Only RequestHeaderModifier and ResponseHeaderModifier type is supported.",
},
routeResolvedRefsCondition(),
},
},
},
Expand Down Expand Up @@ -7160,6 +7178,7 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) {
{
ParentRef: gatewayapi.GatewayParentRef("projectcontour", "contour"),
Conditions: []metav1.Condition{
routeResolvedRefsCondition(),
{
Type: string(gatewayapi_v1beta1.RouteConditionAccepted),
Status: metav1.ConditionFalse,
Expand Down Expand Up @@ -7453,6 +7472,7 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) {
{
ParentRef: gatewayapi.GatewayParentRef("projectcontour", "contour"),
Conditions: []metav1.Condition{
routeResolvedRefsCondition(),
{
Type: string(gatewayapi_v1beta1.RouteConditionAccepted),
Status: metav1.ConditionFalse,
Expand Down Expand Up @@ -8889,6 +8909,7 @@ func TestGatewayAPITLSRouteDAGStatus(t *testing.T) {
Reason: string(status.ReasonAllBackendRefsHaveZeroWeights),
Message: "At least one Spec.Rules.BackendRef must have a non-zero weight.",
},
routeResolvedRefsCondition(),
{
Type: string(gatewayapi_v1beta1.RouteConditionAccepted),
Status: contour_api_v1.ConditionTrue,
Expand Down Expand Up @@ -9093,12 +9114,14 @@ func TestGatewayAPIGRPCRouteDAGStatus(t *testing.T) {
RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{
{
ParentRef: gatewayapi.GatewayParentRef("projectcontour", "contour"),
Conditions: []metav1.Condition{{
Type: string(gatewayapi_v1beta1.RouteConditionAccepted),
Status: contour_api_v1.ConditionTrue,
Reason: string(gatewayapi_v1beta1.RouteReasonAccepted),
Message: "Accepted GRPCRoute",
}},
Conditions: []metav1.Condition{
routeResolvedRefsCondition(),
{
Type: string(gatewayapi_v1beta1.RouteConditionAccepted),
Status: contour_api_v1.ConditionTrue,
Reason: string(gatewayapi_v1beta1.RouteReasonAccepted),
Message: "Accepted GRPCRoute",
}},
},
},
}},
Expand Down Expand Up @@ -9138,6 +9161,7 @@ func TestGatewayAPIGRPCRouteDAGStatus(t *testing.T) {
{
ParentRef: gatewayapi.GatewayParentRef("projectcontour", "contour"),
Conditions: []metav1.Condition{
routeResolvedRefsCondition(),
{
Type: string(gatewayapi_v1beta1.RouteConditionAccepted),
Status: contour_api_v1.ConditionFalse,
Expand Down Expand Up @@ -9183,6 +9207,7 @@ func TestGatewayAPIGRPCRouteDAGStatus(t *testing.T) {
{
ParentRef: gatewayapi.GatewayParentRef("projectcontour", "contour"),
Conditions: []metav1.Condition{
routeResolvedRefsCondition(),
{
Type: string(gatewayapi_v1beta1.RouteConditionAccepted),
Status: contour_api_v1.ConditionFalse,
Expand Down Expand Up @@ -9228,6 +9253,7 @@ func TestGatewayAPIGRPCRouteDAGStatus(t *testing.T) {
{
ParentRef: gatewayapi.GatewayParentRef("projectcontour", "contour"),
Conditions: []metav1.Condition{
routeResolvedRefsCondition(),
{
Type: string(gatewayapi_v1beta1.RouteConditionAccepted),
Status: contour_api_v1.ConditionFalse,
Expand Down Expand Up @@ -9286,6 +9312,7 @@ func TestGatewayAPIGRPCRouteDAGStatus(t *testing.T) {
{
ParentRef: gatewayapi.GatewayParentRef("projectcontour", "contour"),
Conditions: []metav1.Condition{
routeResolvedRefsCondition(),
{
Type: string(gatewayapi_v1beta1.RouteConditionAccepted),
Status: contour_api_v1.ConditionFalse,
Expand Down Expand Up @@ -9468,6 +9495,7 @@ func TestGatewayAPIGRPCRouteDAGStatus(t *testing.T) {
{
ParentRef: gatewayapi.GatewayParentRef("projectcontour", "contour"),
Conditions: []metav1.Condition{
routeResolvedRefsCondition(),
{
Type: string(gatewayapi_v1beta1.RouteConditionAccepted),
Status: contour_api_v1.ConditionTrue,
Expand Down Expand Up @@ -9581,6 +9609,7 @@ func TestGatewayAPIGRPCRouteDAGStatus(t *testing.T) {
{
ParentRef: gatewayapi.GatewayParentRef("projectcontour", "contour"),
Conditions: []metav1.Condition{
routeResolvedRefsCondition(),
{
Type: string(gatewayapi_v1beta1.RouteConditionAccepted),
Status: metav1.ConditionFalse,
Expand Down Expand Up @@ -9781,6 +9810,7 @@ func TestGatewayAPIGRPCRouteDAGStatus(t *testing.T) {
// Invalid filters still result in an attached route.
wantGatewayStatusUpdate: validGatewayStatusUpdate("http", "GRPCRoute", 1),
})

}

func gatewayAcceptedCondition() metav1.Condition {
Expand All @@ -9791,3 +9821,12 @@ func gatewayAcceptedCondition() metav1.Condition {
Message: "Gateway is accepted",
}
}

func routeResolvedRefsCondition() metav1.Condition {
return metav1.Condition{
Type: string(gatewayapi_v1beta1.RouteConditionResolvedRefs),
Status: contour_api_v1.ConditionTrue,
Reason: string(gatewayapi_v1beta1.RouteReasonResolvedRefs),
Message: "References resolved",
}
}
10 changes: 10 additions & 0 deletions internal/status/routeconditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,16 @@ func (r *RouteParentStatusUpdate) AddCondition(conditionType gatewayapi_v1beta1.
return cond
}

// ConditionExists returns whether or not a condition with the given type exists.
func (r *RouteParentStatusUpdate) ConditionExists(conditionType gatewayapi_v1beta1.RouteConditionType) bool {
for _, c := range r.ConditionsForParentRef(r.parentRef) {
if c.Type == string(conditionType) {
return true
}
}
return false
}

func (r *RouteStatusUpdate) ConditionsForParentRef(parentRef gatewayapi_v1beta1.ParentReference) []metav1.Condition {
for _, rps := range r.RouteParentStatuses {
if rps.ParentRef == parentRef {
Expand Down