Skip to content

Commit 7662eef

Browse files
committed
fix: r
Signed-off-by: ashing <[email protected]>
1 parent b3fa2a3 commit 7662eef

File tree

2 files changed

+37
-18
lines changed

2 files changed

+37
-18
lines changed

internal/controller/httproute_controller.go

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,6 @@ func (r *HTTPRouteReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
170170
}
171171
}
172172

173-
filteredHTTPRoute, err := filterHostnames(gateways, hr.DeepCopy())
174-
if err != nil {
175-
acceptStatus.status = false
176-
acceptStatus.msg = err.Error()
177-
}
178-
179173
var httpRouteErr error
180174
if err := r.processHTTPRoute(tctx, hr); err != nil {
181175
httpRouteErr = err
@@ -207,17 +201,24 @@ func (r *HTTPRouteReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
207201
}
208202
ProcessBackendTrafficPolicy(r.Client, r.Log, tctx)
209203

210-
routeToUpdate := hr
211-
if err == nil && filteredHTTPRoute != nil {
212-
r.Log.Info("filteredHTTPRoute", "filteredHTTPRoute", filteredHTTPRoute)
213-
routeToUpdate = filteredHTTPRoute
214-
}
215-
216-
if err := r.Provider.Update(ctx, tctx, routeToUpdate); err != nil {
204+
filteredHTTPRoute, err := filterHostnames(gateways, hr.DeepCopy())
205+
if err != nil {
217206
acceptStatus.status = false
218207
acceptStatus.msg = err.Error()
219208
}
220209

210+
if isRouteAccepted(gateways) && err == nil {
211+
routeToUpdate := hr
212+
if filteredHTTPRoute != nil {
213+
r.Log.Info("filteredHTTPRoute", "filteredHTTPRoute", filteredHTTPRoute)
214+
routeToUpdate = filteredHTTPRoute
215+
}
216+
if err := r.Provider.Update(ctx, tctx, routeToUpdate); err != nil {
217+
acceptStatus.status = false
218+
acceptStatus.msg = err.Error()
219+
}
220+
}
221+
221222
// TODO: diff the old and new status
222223
hr.Status.Parents = make([]gatewayv1.RouteParentStatus, 0, len(gateways))
223224
for _, gateway := range gateways {
@@ -226,9 +227,6 @@ func (r *HTTPRouteReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
226227
for _, condition := range gateway.Conditions {
227228
parentStatus.Conditions = MergeCondition(parentStatus.Conditions, condition)
228229
}
229-
if gateway.ListenerName == "" {
230-
continue
231-
}
232230
SetRouteConditionAccepted(&parentStatus, hr.GetGeneration(), acceptStatus.status, acceptStatus.msg)
233231
SetRouteConditionResolvedRefs(&parentStatus, hr.GetGeneration(), resolveRefStatus.status, resolveRefStatus.msg)
234232
hr.Status.Parents = append(hr.Status.Parents, parentStatus)

internal/controller/utils.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ package controller
1414

1515
import (
1616
"context"
17+
"errors"
1718
"fmt"
1819
"path"
1920
"reflect"
@@ -48,6 +49,10 @@ const (
4849

4950
const defaultIngressClassAnnotation = "ingressclass.kubernetes.io/is-default-class"
5051

52+
var (
53+
ErrNoMatchingListenerHostname = errors.New("no matching hostnames in listener")
54+
)
55+
5156
// IsDefaultIngressClass returns whether an IngressClass is the default IngressClass.
5257
func IsDefaultIngressClass(obj client.Object) bool {
5358
if ingressClass, ok := obj.(*networkingv1.IngressClass); ok {
@@ -229,10 +234,15 @@ func SetRouteConditionAccepted(routeParentStatus *gatewayv1.RouteParentStatus, g
229234
conditionStatus = metav1.ConditionFalse
230235
}
231236

237+
reason := gatewayv1.RouteReasonAccepted
238+
if message == ErrNoMatchingListenerHostname.Error() {
239+
reason = gatewayv1.RouteReasonNoMatchingListenerHostname
240+
}
241+
232242
condition := metav1.Condition{
233243
Type: string(gatewayv1.RouteConditionAccepted),
234244
Status: conditionStatus,
235-
Reason: string(gatewayv1.RouteReasonAccepted),
245+
Reason: string(reason),
236246
ObservedGeneration: generation,
237247
Message: message,
238248
LastTransitionTime: metav1.Now(),
@@ -926,7 +936,7 @@ func filterHostnames(gateways []RouteParentRefContext, httpRoute *gatewayv1.HTTP
926936
}
927937
}
928938
if len(filteredHostnames) == 0 {
929-
return httpRoute, fmt.Errorf("no matching hostnames in listener")
939+
return httpRoute, ErrNoMatchingListenerHostname
930940
}
931941
}
932942

@@ -1005,3 +1015,14 @@ func isListenerHostnameEffective(listener gatewayv1.Listener) bool {
10051015
listener.Protocol == gatewayv1.HTTPSProtocolType ||
10061016
listener.Protocol == gatewayv1.TLSProtocolType
10071017
}
1018+
1019+
func isRouteAccepted(gateways []RouteParentRefContext) bool {
1020+
for _, gateway := range gateways {
1021+
for _, condition := range gateway.Conditions {
1022+
if condition.Type == string(gatewayv1.RouteConditionAccepted) && condition.Status == metav1.ConditionTrue {
1023+
return true
1024+
}
1025+
}
1026+
}
1027+
return false
1028+
}

0 commit comments

Comments
 (0)