From 6cf2edd4d4e03b85292999446e8f00e2c05371c6 Mon Sep 17 00:00:00 2001 From: Tom Dohrmann Date: Tue, 10 Sep 2024 09:19:21 +0200 Subject: [PATCH] e2e: don't expect load balancer on bare metal --- e2e/internal/kubeclient/deploy.go | 23 +++++++++++++++-------- e2e/release/release_test.go | 6 ++++-- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/e2e/internal/kubeclient/deploy.go b/e2e/internal/kubeclient/deploy.go index adae8f5308..464f6c65ee 100644 --- a/e2e/internal/kubeclient/deploy.go +++ b/e2e/internal/kubeclient/deploy.go @@ -255,8 +255,8 @@ retryLoop: } } -// WaitForLoadBalancer waits until the given service is configured with an external IP and returns it. -func (c *Kubeclient) WaitForLoadBalancer(ctx context.Context, namespace, name string) (string, error) { +// WaitForService waits until the given service is configured with an external IP and returns it. +func (c *Kubeclient) WaitForService(ctx context.Context, namespace, name string, loadBalancer bool) (string, error) { watcher, err := c.Client.CoreV1().Services(namespace).Watch(ctx, metav1.ListOptions{FieldSelector: "metadata.name=" + name}) if err != nil { return "", err @@ -280,13 +280,20 @@ loop: if !ok { return "", fmt.Errorf("watcher received unexpected type %T", evt.Object) } - for _, ingress := range svc.Status.LoadBalancer.Ingress { - if ingress.IP != "" { - ip = ingress.IP - // TODO(burgerdev): deal with more than one port, and protocols other than TCP - port = int(svc.Spec.Ports[0].Port) - break loop + if loadBalancer { + for _, ingress := range svc.Status.LoadBalancer.Ingress { + if ingress.IP != "" { + ip = ingress.IP + // TODO(burgerdev): deal with more than one port, and protocols other than TCP + port = int(svc.Spec.Ports[0].Port) + break loop + } } + } else { + ip = svc.Spec.ClusterIP + // TODO(burgerdev): deal with more than one port, and protocols other than TCP + port = int(svc.Spec.Ports[0].Port) + break loop } case watch.Deleted: return "", fmt.Errorf("service %s/%s was deleted while waiting for it", namespace, name) diff --git a/e2e/release/release_test.go b/e2e/release/release_test.go index ff8e3ae1c0..1462ab9ddc 100644 --- a/e2e/release/release_test.go +++ b/e2e/release/release_test.go @@ -51,6 +51,8 @@ func TestRelease(t *testing.T) { k := kubeclient.NewForTest(t) lowerPlatformStr := strings.ToLower(*platformStr) + // On AKS, wait for a load balancer, on bare-metal connect directly to the cluster IP. + hasLoadBalancer := strings.HasPrefix(lowerPlatformStr, "aks-") dir := fetchRelease(ctx, t) @@ -119,7 +121,7 @@ func TestRelease(t *testing.T) { require.NoError(k.Apply(ctx, resources...)) require.NoError(k.WaitFor(ctx, kubeclient.StatefulSet{}, "default", "coordinator")) - coordinatorIP, err = k.WaitForLoadBalancer(ctx, "default", "coordinator") + coordinatorIP, err = k.WaitForService(ctx, "default", "coordinator", hasLoadBalancer) require.NoError(err) }), "the coordinator is required for subsequent tests to run") @@ -184,7 +186,7 @@ func TestRelease(t *testing.T) { ctx, cancel := context.WithTimeout(ctx, 2*time.Minute) defer cancel() - emojiwebIP, err := k.WaitForLoadBalancer(ctx, "default", "web-svc") + emojiwebIP, err := k.WaitForService(ctx, "default", "web-svc", hasLoadBalancer) require.NoError(err) cfg := &tls.Config{RootCAs: x509.NewCertPool()}