@@ -280,32 +280,78 @@ func (r *gatewayAPIReconciler) isOIDCHMACSecret(nsName *types.NamespacedName) bo
280280 return * nsName == oidcHMACSecret
281281}
282282
283- // validateServiceForReconcile tries finding the owning Gateway of the Service
284- // if it exists, finds the Gateway's Deployment, and further updates the Gateway
285- // status Ready condition. All Services are pushed for reconciliation.
286- func (r * gatewayAPIReconciler ) validateServiceForReconcile (obj client.Object ) bool {
283+ // isServiceOwnedByGateway returns true if the Service belongs to a Gateway.
284+ func (r * gatewayAPIReconciler ) isServiceOwnedByGateway (svc * corev1.Service , updateStatus bool ) bool {
287285 ctx := context .Background ()
288- svc , ok := obj .(* corev1.Service )
289- if ! ok {
290- r .log .Info ("unexpected object type, bypassing reconciliation" , "object" , obj )
291- return false
292- }
293286 labels := svc .GetLabels ()
294287
295288 // Check if the Service belongs to a Gateway, if so, update the Gateway status.
296- gtw := r .findOwningGateway (ctx , labels )
289+ gtw := r .findOwningGateway (context . Background () , labels )
297290 if gtw != nil {
298- r .updateGatewayStatus (gtw )
299- return false
291+ if updateStatus {
292+ r .updateGatewayStatus (gtw )
293+ }
294+ return true
300295 }
301296
302297 // Merged gateways will have only this label, update status of all Gateways under found GatewayClass.
303298 gcName , ok := labels [gatewayapi .OwningGatewayClassLabel ]
304299 if ok && r .mergeGateways .Has (gcName ) {
305- if err := r .updateStatusForGatewaysUnderGatewayClass (ctx , gcName ); err != nil {
306- r .log .Info ("no Gateways found under GatewayClass" , "name" , gcName )
307- return false
300+ if updateStatus {
301+ if err := r .updateStatusForGatewaysUnderGatewayClass (ctx , gcName ); err != nil {
302+ r .log .Info ("no Gateways found under GatewayClass" , "name" , gcName )
303+ return true
304+ }
308305 }
306+ return true
307+ }
308+
309+ return false
310+ }
311+
312+ // validateServiceUpdateForReconcile checks whether a Service update should trigger a reconcile.
313+ // Returns false when the backend does not have endpoint routing and the service of type clusterIP
314+ // does not have a new IP address.
315+ func (r * gatewayAPIReconciler ) validateServiceUpdateForReconcile (oldObj client.Object , newObj client.Object ) bool {
316+ oldSvc , ok := oldObj .(* corev1.Service )
317+ if ! ok {
318+ r .log .Info ("unexpected object type, bypassing reconciliation" , "object" , oldObj )
319+ return true
320+ }
321+ newSvc , ok := newObj .(* corev1.Service )
322+ if ! ok {
323+ r .log .Info ("unexpected object type, bypassing reconciliation" , "object" , newObj )
324+ return true
325+ }
326+
327+ if r .isServiceOwnedByGateway (newSvc , false ) {
328+ return true
329+ }
330+
331+ if (newSvc .Spec .Type != corev1 .ServiceTypeClusterIP ) || (oldSvc .Spec .Type != corev1 .ServiceTypeClusterIP ) || (newSvc .Spec .ClusterIP != oldSvc .Spec .ClusterIP ) {
332+ return true
333+ }
334+
335+ nsName := utils .NamespacedName (newSvc )
336+ if ! r .hasRouteWithEndpointRouting (& nsName ) {
337+ r .log .Info ("validateServiceUpdateForReconcile -- Service is not referenced by backend with endpoint routing" , "service" , nsName )
338+ return false
339+ }
340+
341+ return true
342+ }
343+
344+ // validateServiceForReconcile tries finding the owning Gateway of the Service
345+ // if it exists, finds the Gateway's Deployment, and further updates the Gateway
346+ // status Ready condition. All Services are pushed for reconciliation.
347+ func (r * gatewayAPIReconciler ) validateServiceForReconcile (obj client.Object ) bool {
348+ svc , ok := obj .(* corev1.Service )
349+ if ! ok {
350+ r .log .Info ("unexpected object type, bypassing reconciliation" , "object" , obj )
351+ return false
352+ }
353+
354+ if r .isServiceOwnedByGateway (svc , true ) {
309355 return false
310356 }
311357
@@ -437,6 +483,7 @@ func (r *gatewayAPIReconciler) isRouteReferencingBackend(nsName *types.Namespace
437483 if len (tlsRouteList .Items ) > 0 {
438484 // we don't know the old value of the service clusterIP here, so we can't avoid reconciling on service change.
439485 return true
486+
440487 }
441488 }
442489
0 commit comments