Skip to content

Commit 7ee9489

Browse files
committed
Add retry for failing check
1 parent 9149f71 commit 7ee9489

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

internal/mode/static/handler.go

+15-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
v1 "k8s.io/api/core/v1"
1313
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1414
"k8s.io/apimachinery/pkg/types"
15+
"k8s.io/apimachinery/pkg/util/wait"
1516
"k8s.io/client-go/tools/record"
1617
"sigs.k8s.io/controller-runtime/pkg/client"
1718
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
@@ -472,8 +473,20 @@ func getGatewayAddresses(
472473
if svc == nil {
473474
svcName := controller.CreateNginxResourceName(gateway.Source.GetName(), gatewayClassName)
474475
key := types.NamespacedName{Name: svcName, Namespace: gateway.Source.GetNamespace()}
475-
if err := k8sClient.Get(ctx, key, &gwSvc); err != nil {
476-
return nil, fmt.Errorf("error finding Service for Gateway: %w", err)
476+
477+
if err := wait.PollUntilContextCancel(
478+
ctx,
479+
500*time.Millisecond,
480+
true, /* poll immediately */
481+
func(ctx context.Context) (bool, error) {
482+
if err := k8sClient.Get(ctx, key, &gwSvc); err != nil {
483+
return false, nil //nolint:nilerr // need to retry without returning error
484+
}
485+
486+
return true, nil
487+
},
488+
); err != nil {
489+
return nil, fmt.Errorf("error finding Service %s for Gateway: %w", svcName, err)
477490
}
478491
} else {
479492
gwSvc = *svc

0 commit comments

Comments
 (0)