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

Report proper Conditions in status of HTTPRoute and Gateway when GatewayClass is invalid or doesn't exist #576

Merged
merged 4 commits into from
Apr 17, 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
54 changes: 28 additions & 26 deletions internal/state/change_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,18 +316,20 @@ var _ = Describe("ChangeProcessor", func() {
ObservedGeneration: gw1.Generation,
ListenerStatuses: map[string]state.ListenerStatus{
"listener-80-1": {
AttachedRoutes: 1,
Conditions: append(
conditions.NewDefaultListenerConditions(),
conditions.NewTODO("GatewayClass is invalid or doesn't exist"),
),
AttachedRoutes: 0,
pleshakov marked this conversation as resolved.
Show resolved Hide resolved
Conditions: []conditions.Condition{
conditions.NewListenerResolvedRefs(),
conditions.NewListenerNoConflicts(),
conditions.NewListenerNoValidGatewayClass("GatewayClass doesn't exist"),
},
},
"listener-443-1": {
AttachedRoutes: 1,
Conditions: append(
conditions.NewDefaultListenerConditions(),
conditions.NewTODO("GatewayClass is invalid or doesn't exist"),
),
AttachedRoutes: 0,
Conditions: []conditions.Condition{
conditions.NewListenerResolvedRefs(),
conditions.NewListenerNoConflicts(),
conditions.NewListenerNoValidGatewayClass("GatewayClass doesn't exist"),
},
},
},
},
Expand All @@ -339,18 +341,16 @@ var _ = Describe("ChangeProcessor", func() {
{
GatewayNsName: client.ObjectKeyFromObject(gw1),
SectionName: helpers.GetPointer[v1beta1.SectionName]("listener-80-1"),
Conditions: append(
conditions.NewDefaultRouteConditions(),
conditions.NewTODO("GatewayClass is invalid or doesn't exist"),
),
Conditions: []conditions.Condition{
conditions.NewRouteInvalidListener(),
},
},
{
GatewayNsName: client.ObjectKeyFromObject(gw1),
SectionName: helpers.GetPointer[v1beta1.SectionName]("listener-443-1"),
Conditions: append(
conditions.NewDefaultRouteConditions(),
conditions.NewTODO("GatewayClass is invalid or doesn't exist"),
),
Conditions: []conditions.Condition{
conditions.NewRouteInvalidListener(),
},
},
},
},
Expand Down Expand Up @@ -1219,17 +1219,19 @@ var _ = Describe("ChangeProcessor", func() {
ListenerStatuses: map[string]state.ListenerStatus{
"listener-80-1": {
AttachedRoutes: 0,
Conditions: append(
conditions.NewDefaultListenerConditions(),
conditions.NewTODO("GatewayClass is invalid or doesn't exist"),
),
Conditions: []conditions.Condition{
conditions.NewListenerResolvedRefs(),
conditions.NewListenerNoConflicts(),
conditions.NewListenerNoValidGatewayClass("GatewayClass doesn't exist"),
},
},
"listener-443-1": {
AttachedRoutes: 0,
Conditions: append(
conditions.NewDefaultListenerConditions(),
conditions.NewTODO("GatewayClass is invalid or doesn't exist"),
),
Conditions: []conditions.Condition{
conditions.NewListenerResolvedRefs(),
conditions.NewListenerNoConflicts(),
conditions.NewListenerNoValidGatewayClass("GatewayClass doesn't exist"),
},
},
},
},
Expand Down
66 changes: 48 additions & 18 deletions internal/state/conditions/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ const (
// is invalid or not supported.
ListenerReasonUnsupportedValue v1beta1.ListenerConditionReason = "UnsupportedValue"

// ListenerReasonNoValidGatewayClass is used with the "Accepted" condition when there is no valid GatewayClass
// in the cluster.
ListenerReasonNoValidGatewayClass v1beta1.ListenerConditionReason = "NoValidGatewayClass"

// RouteReasonBackendRefUnsupportedValue is used with the "ResolvedRefs" condition when one of the
// Route rules has a backendRef with an unsupported value.
RouteReasonBackendRefUnsupportedValue = "UnsupportedValue"
Expand Down Expand Up @@ -129,27 +133,42 @@ func NewListenerPortUnavailable(msg string) Condition {
}
}

// NewListenerAccepted returns a Condition that indicates that the Listener is accepted.
func NewListenerAccepted() Condition {
return Condition{
Type: string(v1beta1.ListenerConditionAccepted),
Status: metav1.ConditionTrue,
Reason: string(v1beta1.ListenerReasonAccepted),
Message: "Listener is accepted",
}
}

// NewListenerResolvedRefs returns a Condition that indicates that all references in a Listener are resolved.
func NewListenerResolvedRefs() Condition {
return Condition{
Type: string(v1beta1.ListenerConditionResolvedRefs),
Status: metav1.ConditionTrue,
Reason: string(v1beta1.ListenerReasonResolvedRefs),
Message: "All references are resolved",
}
}

// NewListenerNoConflicts returns a Condition that indicates that there are no conflicts in a Listener.
func NewListenerNoConflicts() Condition {
return Condition{
Type: string(v1beta1.ListenerConditionConflicted),
Status: metav1.ConditionFalse,
Reason: string(v1beta1.ListenerReasonNoConflicts),
Message: "No conflicts",
}
}

// NewDefaultListenerConditions returns the default Conditions that must be present in the status of a Listener.
func NewDefaultListenerConditions() []Condition {
return []Condition{
{
Type: string(v1beta1.ListenerConditionAccepted),
Status: metav1.ConditionTrue,
Reason: string(v1beta1.ListenerReasonAccepted),
Message: "Listener is accepted",
},
{
Type: string(v1beta1.ListenerReasonResolvedRefs),
Status: metav1.ConditionTrue,
Reason: string(v1beta1.ListenerReasonResolvedRefs),
Message: "All references are resolved",
},
{
Type: string(v1beta1.ListenerConditionConflicted),
Status: metav1.ConditionFalse,
Reason: string(v1beta1.ListenerReasonNoConflicts),
Message: "No conflicts",
},
NewListenerAccepted(),
NewListenerResolvedRefs(),
NewListenerNoConflicts(),
}
}

Expand Down Expand Up @@ -220,6 +239,17 @@ func NewListenerUnsupportedProtocol(msg string) Condition {
}
}

// NewListenerNoValidGatewayClass returns a Condition that indicates that the Listener is not accepted because
// there is no valid GatewayClass.
func NewListenerNoValidGatewayClass(msg string) Condition {
return Condition{
Type: string(v1beta1.ListenerConditionAccepted),
Status: metav1.ConditionFalse,
Reason: string(ListenerReasonNoValidGatewayClass),
Message: msg,
}
}

// NewRouteBackendRefInvalidKind returns a Condition that indicates that the Route has a backendRef with an
// invalid kind.
func NewRouteBackendRefInvalidKind(msg string) Condition {
Expand Down
Loading