diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d05ead1cf..55832b5ca4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -71,6 +71,9 @@ Adding a new version? You'll need three changes: - Disabled non-functioning mesh reporting when `--watch-namespaces` flag set. [#3336](https://github.com/Kong/kubernetes-ingress-controller/pull/3336) +- Fixed the duplicate update of status of `HTTPRoute` caused by incorrect check + of whether status is changed. + [#3346](https://github.com/Kong/kubernetes-ingress-controller/pull/3346) ### Deprecated diff --git a/internal/controllers/gateway/httproute_controller.go b/internal/controllers/gateway/httproute_controller.go index 2d15f1c02b..d3ff29533b 100644 --- a/internal/controllers/gateway/httproute_controller.go +++ b/internal/controllers/gateway/httproute_controller.go @@ -435,13 +435,12 @@ 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 whether the new condition is present in existing conditions + if reflect.DeepEqual(existingGatewayParentStatus.ParentRef, gatewayParentStatus.ParentRef) && + existingGatewayParentStatus.ControllerName == gatewayParentStatus.ControllerName && + lo.ContainsBy(existingGatewayParentStatus.Conditions, func(condition metav1.Condition) bool { + return sameCondition(gatewayParentStatus.Conditions[0], condition) + }) { continue } } diff --git a/internal/controllers/gateway/route_utils.go b/internal/controllers/gateway/route_utils.go index a88b5be2e8..8327b038cb 100644 --- a/internal/controllers/gateway/route_utils.go +++ b/internal/controllers/gateway/route_utils.go @@ -630,3 +630,11 @@ func isHTTPReferenceGranted(grantSpec gatewayv1alpha2.ReferenceGrantSpec, backen } return false } + +// sameCondition returns true if the conditions in parameter has the same type, status, reason and message. +func sameCondition(a, b metav1.Condition) bool { + return a.Type == b.Type && + a.Status == b.Status && + a.Reason == b.Reason && + a.Message == b.Message +}