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 <[email protected]>
  • Loading branch information
giorio94 committed Mar 18, 2024
1 parent 907d7bd commit eff1aba
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
15 changes: 7 additions & 8 deletions connectivity/check/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

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 eff1aba

Please sign in to comment.