diff --git a/connectivity/check/deployment.go b/connectivity/check/deployment.go index bab81ee21c..1b508eab5f 100644 --- a/connectivity/check/deployment.go +++ b/connectivity/check/deployment.go @@ -1280,15 +1280,14 @@ func (ct *ConnectivityTest) validateDeployment(ctx context.Context) error { } if ct.Features[features.IngressController].Enabled { - ingressServices, err := ct.clients.src.ListServices(ctx, ct.params.TestNamespace, metav1.ListOptions{LabelSelector: "cilium.io/ingress=true"}) - if err != nil { - return fmt.Errorf("unable to list ingress services: %w", err) - } - - for _, ingressService := range ingressServices.Items { - ct.ingressService[ingressService.Name] = Service{ - Service: ingressService.DeepCopy(), + for name := range ct.ingresses() { + svcName := fmt.Sprintf("cilium-ingress-%s", name) + svc, err := WaitForServiceRetrieval(ctx, ct, ct.client, ct.params.TestNamespace, svcName) + if err != nil { + return err } + + ct.ingressService[svcName] = svc } } diff --git a/connectivity/check/wait.go b/connectivity/check/wait.go index 4cffe30fb2..0150c02b24 100644 --- a/connectivity/check/wait.go +++ b/connectivity/check/wait.go @@ -15,6 +15,7 @@ import ( "github.com/cilium/cilium/api/v1/models" "golang.org/x/exp/slices" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/cilium/cilium-cli/defaults" "github.com/cilium/cilium-cli/k8s" @@ -134,6 +135,29 @@ func WaitForCoreDNS(ctx context.Context, log Logger, client Pod) error { } } +// Service waits until the specified service is created and can be retrieved. +func WaitForServiceRetrieval(ctx context.Context, log Logger, client *k8s.Client, namespace string, name string) (Service, error) { + log.Logf("⌛ [%s] Retrieving service %s/%s ...", client.ClusterName(), namespace, name) + + ctx, cancel := context.WithTimeout(ctx, ShortTimeout) + defer cancel() + for { + svc, err := client.GetService(ctx, namespace, name, metav1.GetOptions{}) + if err == nil { + return Service{Service: svc.DeepCopy()}, nil + } + + log.Debugf("[%s] Failed to retrieve Service %s/%s: %s", client.ClusterName(), namespace, name, err) + + select { + case <-time.After(PollInterval): + case <-ctx.Done(): + return Service{}, fmt.Errorf("timeout reached waiting for service %s/%s to be retrieved (last error: %w)", + namespace, name, err) + } + } +} + // WaitForService waits until the given service is synchronized in CoreDNS. func WaitForService(ctx context.Context, log Logger, client Pod, service Service) error { log.Logf("⌛ [%s] Waiting for Service %s to become ready...", client.K8sClient.ClusterName(), service.Name())