@@ -276,39 +276,48 @@ func (r *HTTPRouteReconciler) reconcileHTTPRouteResource(ctx context.Context, ht
276276func (r * HTTPRouteReconciler ) updateHTTPRouteStatus (ctx context.Context , dns string , httproute * gateway_api.HTTPRoute ) error {
277277 glog .V (6 ).Infof ("updateHTTPRouteStatus: httproute %v, dns %v\n " , httproute , dns )
278278 httprouteOld := httproute .DeepCopy ()
279+ compare := true
279280
280281 if len (httproute .ObjectMeta .Annotations ) == 0 {
281282 httproute .ObjectMeta .Annotations = make (map [string ]string )
283+ compare = false
282284 }
283285
284286 httproute .ObjectMeta .Annotations [LatticeAssignedDomainName ] = dns
285-
286287 if err := r .Client .Patch (ctx , httproute , client .MergeFrom (httprouteOld )); err != nil {
287288 glog .V (2 ).Infof ("updateHTTPRouteStatus: Patch() received err %v \n " , err )
288289 return errors .Wrapf (err , "failed to update httproute status" )
289290 }
290-
291291 httprouteOld = httproute .DeepCopy ()
292+
292293 if len (httproute .Status .RouteStatus .Parents ) == 0 {
293294 httproute .Status .RouteStatus .Parents = make ([]gateway_api.RouteParentStatus , 1 )
295+ compare = false
294296 }
295297
296298 httproute .Status .RouteStatus .Parents [0 ].ParentRef = httproute .Spec .ParentRefs [0 ]
297299 httproute .Status .RouteStatus .Parents [0 ].ControllerName = config .LatticeGatewayControllerName
298300
301+ timeNow := metav1 .NewTime (time .Now ())
302+ if httprouteOld .Status .RouteStatus .Parents != nil {
303+ if len (httprouteOld .Status .RouteStatus .Parents [0 ].Conditions ) > 0 {
304+ timeNow = httprouteOld .Status .Parents [0 ].Conditions [0 ].LastTransitionTime
305+ }
306+ }
307+
299308 accepted := metav1.Condition {
300309 Type : string (gateway_api .RouteConditionAccepted ),
301310 Status : metav1 .ConditionTrue ,
302311 ObservedGeneration : httproute .Generation ,
303- LastTransitionTime : metav1 . NewTime ( time . Now ()) ,
312+ LastTransitionTime : timeNow ,
304313 Reason : string (gateway_api .RouteReasonAccepted ),
305314 Message : fmt .Sprintf ("DNS Name: %s" , dns ),
306315 }
307316 resolvedRefs := metav1.Condition {
308317 Type : string (gateway_api .RouteConditionResolvedRefs ),
309318 Status : metav1 .ConditionTrue ,
310319 ObservedGeneration : httproute .Generation ,
311- LastTransitionTime : metav1 . NewTime ( time . Now ()) ,
320+ LastTransitionTime : timeNow ,
312321 Reason : string (gateway_api .RouteReasonResolvedRefs ),
313322 Message : fmt .Sprintf ("DNS Name: %s" , dns ),
314323 }
@@ -320,16 +329,47 @@ func (r *HTTPRouteReconciler) updateHTTPRouteStatus(ctx context.Context, dns str
320329 // Update listener Status
321330 UpdateHTTPRouteListenerStatus (ctx , r .Client , httproute )
322331
332+ if compare && r .compareHttproutes (httproute , httprouteOld ) {
333+ glog .V (6 ).Infof ("updateHTTPRouteStatus: httproute is already up-to-date %v, dns %v\n " , httproute , dns )
334+ return nil
335+ }
336+
323337 if err := r .Client .Status ().Patch (ctx , httproute , client .MergeFrom (httprouteOld )); err != nil {
324338 glog .V (2 ).Infof ("updateHTTPRouteStatus: Patch() received err %v \n " , err )
325339 return errors .Wrapf (err , "failed to update httproute status" )
326340 }
327-
328341 glog .V (6 ).Infof ("updateHTTPRouteStatus patched dns %v \n " , dns )
329342
330343 return nil
331344}
332345
346+ func (r * HTTPRouteReconciler ) compareHttproutes (httproute1 * gateway_api.HTTPRoute , httproute2 * gateway_api.HTTPRoute ) bool {
347+
348+ result := false
349+
350+ if httproute1 == httproute2 {
351+ return true
352+ }
353+
354+ if (httproute1 .Name == httproute2 .Name ) && (httproute1 .Namespace == httproute2 .Namespace ) &&
355+ (len (httproute1 .Status .RouteStatus .Parents [0 ].Conditions ) == len (httproute2 .Status .RouteStatus .Parents [0 ].Conditions )) &&
356+ (httproute1 .Status .RouteStatus .Parents [0 ].ParentRef .Name == httproute2 .Status .RouteStatus .Parents [0 ].ParentRef .Name ) &&
357+ (httproute1 .Status .RouteStatus .Parents [0 ].ControllerName == httproute2 .Status .RouteStatus .Parents [0 ].ControllerName ) &&
358+ (httproute1 .ObjectMeta .Annotations [LatticeAssignedDomainName ] == httproute2 .ObjectMeta .Annotations [LatticeAssignedDomainName ]) {
359+ i := 0
360+ for _ , condition := range httproute1 .Status .RouteStatus .Parents [0 ].Conditions {
361+ if condition != httproute2 .Status .RouteStatus .Parents [0 ].Conditions [i ] {
362+ result = false
363+ break
364+ }
365+ i ++
366+ }
367+ result = true
368+ }
369+
370+ return result
371+ }
372+
333373// SetupWithManager sets up the controller with the Manager.
334374func (r * HTTPRouteReconciler ) SetupWithManager (mgr ctrl.Manager ) error {
335375 gwEventHandler := eventhandlers .NewEnqueueRequestGatewayEvent (r .Client )
0 commit comments