Skip to content

Commit

Permalink
connectivity: explicitly wait for ingress service creation
Browse files Browse the repository at this point in the history
Rather than just listing the services, let's explicitly wait until we
successfully retrieve all expected services, so that we can provide a
clear error in case something went wrong and they were not created.

Signed-off-by: Marco Iorio <marco.iorio@isovalent.com>
  • Loading branch information
giorio94 authored and michi-covalent committed Mar 26, 2024
1 parent f45d1e3 commit b005442
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
11 changes: 4 additions & 7 deletions connectivity/check/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -1272,16 +1272,13 @@ 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"})
svcName := fmt.Sprintf("cilium-ingress-%s", IngressServiceName)
svc, err := WaitForServiceRetrieval(ctx, ct, ct.client, ct.params.TestNamespace, svcName)
if err != nil {
return fmt.Errorf("unable to list ingress services: %w", err)
return err
}

for _, ingressService := range ingressServices.Items {
ct.ingressService[ingressService.Name] = Service{
Service: ingressService.DeepCopy(),
}
}
ct.ingressService[svcName] = svc
}

if ct.params.MultiCluster == "" {
Expand Down
24 changes: 24 additions & 0 deletions connectivity/check/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit b005442

Please sign in to comment.