From 6b7382748a7dc3d4b119f888462c57b3da954d81 Mon Sep 17 00:00:00 2001 From: Yi Tao Date: Mon, 9 Jan 2023 17:30:17 +0800 Subject: [PATCH] fix: only check if condition contained in httproute --- .../controllers/gateway/httproute_controller.go | 11 ++++------- internal/controllers/gateway/route_utils.go | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/internal/controllers/gateway/httproute_controller.go b/internal/controllers/gateway/httproute_controller.go index 2d15f1c02b..d59f62dee3 100644 --- a/internal/controllers/gateway/httproute_controller.go +++ b/internal/controllers/gateway/httproute_controller.go @@ -435,13 +435,10 @@ func (r *HTTPRouteReconciler) ensureGatewayReferenceStatusAdded(ctx context.Cont // if the reference already exists and doesn't require any changes // then just leave it alone. if existingGatewayParentStatus, exists := parentStatuses[key]; exists { - // fake the time of the existing status as this wont be equal - for i := range existingGatewayParentStatus.Conditions { - existingGatewayParentStatus.Conditions[i].LastTransitionTime = gatewayParentStatus.Conditions[0].LastTransitionTime - } - - // other than the condition timestamps, check if the statuses are equal - if reflect.DeepEqual(existingGatewayParentStatus, gatewayParentStatus) { + // check if the parentRef and controllerName are equal, and expected condition presents in conditions + if reflect.DeepEqual(existingGatewayParentStatus.ParentRef, gatewayParentStatus.ParentRef) && + existingGatewayParentStatus.ControllerName == gatewayParentStatus.ControllerName && + containsCondition(existingGatewayParentStatus.Conditions, gatewayParentStatus.Conditions[0]) { continue } } diff --git a/internal/controllers/gateway/route_utils.go b/internal/controllers/gateway/route_utils.go index a88b5be2e8..4c3b6f4a88 100644 --- a/internal/controllers/gateway/route_utils.go +++ b/internal/controllers/gateway/route_utils.go @@ -630,3 +630,17 @@ func isHTTPReferenceGranted(grantSpec gatewayv1alpha2.ReferenceGrantSpec, backen } return false } + +// containsCondition returns true if a condition with same type, status, reason and message +// of expectedCondition in conditions +func containsCondition(conditions []metav1.Condition, expectedCondition metav1.Condition) bool { + for _, condition := range conditions { + if condition.Type == expectedCondition.Type && + condition.Status == expectedCondition.Status && + condition.Reason == expectedCondition.Reason && + condition.Message == expectedCondition.Message { + return true + } + } + return false +}