Skip to content

Commit e58d625

Browse files
committed
cleanup debug and comments
1 parent 93279ad commit e58d625

File tree

2 files changed

+31
-49
lines changed

2 files changed

+31
-49
lines changed

internal/provider/kubernetes/controller.go

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ package kubernetes
88
import (
99
"context"
1010
"fmt"
11-
"strings"
1211
"time"
1312

1413
appsv1 "k8s.io/api/apps/v1"
@@ -1358,40 +1357,30 @@ func (r *gatewayAPIReconciler) watchResources(ctx context.Context, mgr manager.M
13581357
}
13591358
}
13601359

1361-
// // create service predicate with additonal logic for update events
1362-
servicePredicateFuncs := predicate.TypedFuncs[*corev1.Service]{
1363-
CreateFunc: func(e event.TypedCreateEvent[*corev1.Service]) bool {
1364-
return true
1365-
},
1366-
UpdateFunc: func(e event.TypedUpdateEvent[*corev1.Service]) bool {
1367-
retVal := r.validateServiceUpdateForReconcile(e.ObjectOld, e.ObjectNew)
1368-
if strings.HasPrefix(e.ObjectOld.Name, "brendan") {
1369-
r.log.Info(fmt.Sprintf("predicate -- validateServiceUpdateForReconcile=%v",retVal), "name", e.ObjectOld.Name)
1370-
}
1371-
return retVal
1372-
1373-
},
1374-
DeleteFunc: func(e event.TypedDeleteEvent[*corev1.Service]) bool {
1375-
return true
1376-
},
1377-
GenericFunc: func(e event.TypedGenericEvent[*corev1.Service]) bool {
1378-
return true
1379-
},
1380-
}
1381-
1360+
// composable predicate functions - service updates do not require a reconcile when the
1361+
// service is not referenced by any endpoint-routed backend and ClusterIP is unchanged.
1362+
skipServiceUpdatesWithoutEndpointRouting := predicate.TypedFuncs[*corev1.Service]{
1363+
CreateFunc: func(e event.TypedCreateEvent[*corev1.Service]) bool {
1364+
return true
1365+
},
1366+
UpdateFunc: func(e event.TypedUpdateEvent[*corev1.Service]) bool {
1367+
return r.validateServiceUpdateForReconcile(e.ObjectOld, e.ObjectNew)
1368+
},
1369+
DeleteFunc: func(e event.TypedDeleteEvent[*corev1.Service]) bool {
1370+
return true
1371+
},
1372+
GenericFunc: func(e event.TypedGenericEvent[*corev1.Service]) bool {
1373+
return true
1374+
},
1375+
}
13821376

13831377
// Watch Service CRUDs and process affected *Route objects.
13841378
servicePredicates := []predicate.TypedPredicate[*corev1.Service]{predicate.And[*corev1.Service](
1385-
servicePredicateFuncs,
1379+
skipServiceUpdatesWithoutEndpointRouting,
13861380
predicate.NewTypedPredicateFuncs[*corev1.Service](func(svc *corev1.Service) bool {
1387-
validateService := r.validateServiceForReconcile(svc)
1388-
if strings.HasPrefix(svc.Namespace, "dev-blue-cloud-teleportinfra-dev") {
1389-
r.log.Info(fmt.Sprintf("predicate -- validateServiceForReconcile=%v",validateService), "namespace", svc.Namespace, "name", svc.Name)
1390-
}
1391-
return validateService
1381+
return r.validateServiceForReconcile(svc)
13921382
}),
1393-
),}
1394-
1383+
)}
13951384
if r.namespaceLabel != nil {
13961385
servicePredicates = append(servicePredicates, predicate.NewTypedPredicateFuncs[*corev1.Service](func(svc *corev1.Service) bool {
13971386
return r.hasMatchingNamespaceLabels(svc)
@@ -1828,7 +1817,6 @@ func (r *gatewayAPIReconciler) watchResources(ctx context.Context, mgr manager.M
18281817
}
18291818

18301819
func (r *gatewayAPIReconciler) enqueueClass(_ context.Context, o client.Object) []reconcile.Request {
1831-
r.log.Info("enqueueClass executed", "objectName", o.GetName(), "objectNamespace", o.GetNamespace(), "objectKind", o.GetObjectKind().GroupVersionKind().Kind)
18321820
return []reconcile.Request{{NamespacedName: types.NamespacedName{
18331821
Name: string(r.classController),
18341822
}}}

internal/provider/kubernetes/predicates.go

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -280,13 +280,13 @@ func (r *gatewayAPIReconciler) isOIDCHMACSecret(nsName *types.NamespacedName) bo
280280
return *nsName == oidcHMACSecret
281281
}
282282

283-
// isServiceOwnedByGateway returns true if the Service belongs to a Gateway.
284-
func (r *gatewayAPIReconciler) isServiceOwnedByGateway(svc *corev1.Service) bool {
283+
// validateServiceOwnedByGateway returns true if the Service belongs to a Gateway.
284+
func (r *gatewayAPIReconciler) validateServiceOwnedByGateway(svc *corev1.Service) bool {
285285
ctx := context.Background()
286286
labels := svc.GetLabels()
287287

288288
// Check if the Service belongs to a Gateway, if so, update the Gateway status.
289-
gtw := r.findOwningGateway(context.Background(), labels)
289+
gtw := r.findOwningGateway(ctx, labels)
290290
if gtw != nil {
291291
r.updateGatewayStatus(gtw)
292292
return true
@@ -306,32 +306,29 @@ func (r *gatewayAPIReconciler) isServiceOwnedByGateway(svc *corev1.Service) bool
306306
}
307307

308308
// validateServiceUpdateForReconcile checks whether a Service update should trigger a reconcile.
309-
// Returns false when the backend does not have endpoint routing and the service of type clusterIP
309+
// Returns false when the backend does not have endpoint routing and the service of type clusterIP
310310
// does not have a new IP address.
311311
func (r *gatewayAPIReconciler) validateServiceUpdateForReconcile(oldObj client.Object, newObj client.Object) bool {
312312
oldSvc, ok := oldObj.(*corev1.Service)
313313
if !ok {
314314
r.log.Info("unexpected object type, bypassing reconciliation", "object", oldObj)
315-
return true
315+
return false
316316
}
317317
newSvc, ok := newObj.(*corev1.Service)
318318
if !ok {
319319
r.log.Info("unexpected object type, bypassing reconciliation", "object", newObj)
320-
return true
321-
}
322-
323-
if r.isServiceOwnedByGateway(newSvc) {
324-
return true
320+
return false
325321
}
326322

327-
if (newSvc.Spec.Type != corev1.ServiceTypeClusterIP) || (oldSvc.Spec.Type != corev1.ServiceTypeClusterIP) || (newSvc.Spec.ClusterIP != oldSvc.Spec.ClusterIP) {
328-
return true
323+
if r.validateServiceOwnedByGateway(newSvc) {
324+
return false
329325
}
330326

331327
nsName := utils.NamespacedName(newSvc)
332328
if !r.hasRouteWithEndpointRouting(&nsName) {
333-
r.log.Info("validateServiceUpdateForReconcile -- Service is not referenced by backend with endpoint routing", "service", nsName)
334-
return false
329+
if (newSvc.Spec.Type != corev1.ServiceTypeClusterIP) || (oldSvc.Spec.Type != corev1.ServiceTypeClusterIP) || (newSvc.Spec.ClusterIP != oldSvc.Spec.ClusterIP) {
330+
return false
331+
}
335332
}
336333

337334
return true
@@ -347,13 +344,12 @@ func (r *gatewayAPIReconciler) validateServiceForReconcile(obj client.Object) bo
347344
return false
348345
}
349346

350-
if r.isServiceOwnedByGateway(svc) {
347+
if r.validateServiceOwnedByGateway(svc) {
351348
return false
352349
}
353350

354351
nsName := utils.NamespacedName(svc)
355352
if r.isRouteReferencingBackend(&nsName) {
356-
r.log.Info("validateServiceForReconcile -- Service is referenced by a Route", "service", nsName)
357353
return true
358354
}
359355

@@ -477,9 +473,7 @@ func (r *gatewayAPIReconciler) isRouteReferencingBackend(nsName *types.Namespace
477473
return false
478474
}
479475
if len(tlsRouteList.Items) > 0 {
480-
// we don't know the old value of the service clusterIP here, so we can't avoid reconciling on service change.
481476
return true
482-
483477
}
484478
}
485479

0 commit comments

Comments
 (0)