Skip to content

Commit

Permalink
revert extra check in service predicate and add empty check for gatew…
Browse files Browse the repository at this point in the history
…ays under certain gatewayclass

Signed-off-by: shawnh2 <shawnhxh@outlook.com>
  • Loading branch information
shawnh2 committed Feb 23, 2024
1 parent ae6cae6 commit 5aec879
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions internal/provider/kubernetes/predicates.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package kubernetes

import (
"context"
"fmt"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -213,14 +214,11 @@ func (r *gatewayAPIReconciler) validateServiceForReconcile(obj client.Object) bo
}
labels := svc.GetLabels()

// Only services in the configured namespace should be reconciled.
if svc.Namespace == r.namespace {
// Check if the Service belongs to a Gateway, if so, update the Gateway status.
gtw := r.findOwningGateway(ctx, labels)
if gtw != nil {
r.updateStatusForGateway(ctx, gtw)
return false
}
// Check if the Service belongs to a Gateway, if so, update the Gateway status.
gtw := r.findOwningGateway(ctx, labels)
if gtw != nil {
r.updateStatusForGateway(ctx, gtw)
return false
}

// Merged gateways will have only this label, update status of all Gateways under found GatewayClass.
Expand Down Expand Up @@ -321,7 +319,7 @@ func (r *gatewayAPIReconciler) isRouteReferencingBackend(nsName *types.Namespace
return allAssociatedRoutes != 0
}

// validateEndpointSliceForReconcile returns true if the the endpointSlice references
// validateEndpointSliceForReconcile returns true if the endpointSlice references
// a service that is referenced by a xRoute
func (r *gatewayAPIReconciler) validateEndpointSliceForReconcile(obj client.Object) bool {
ep, ok := obj.(*discoveryv1.EndpointSlice)
Expand Down Expand Up @@ -452,6 +450,10 @@ func (r *gatewayAPIReconciler) updateStatusForGatewaysUnderGatewayClass(ctx cont
return err
}

Check warning on line 451 in internal/provider/kubernetes/predicates.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/predicates.go#L445-L451

Added lines #L445 - L451 were not covered by tests

if len(gateways.Items) == 0 {
return fmt.Errorf("no gateways found for gatewayclass: %s", gatewayClassName)
}

Check warning on line 455 in internal/provider/kubernetes/predicates.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/predicates.go#L453-L455

Added lines #L453 - L455 were not covered by tests

for _, gateway := range gateways.Items {
gateway := gateway
r.updateStatusForGateway(ctx, &gateway)
Expand Down

0 comments on commit 5aec879

Please sign in to comment.