Skip to content

Commit

Permalink
e2e: don't expect load balancer on bare metal
Browse files Browse the repository at this point in the history
  • Loading branch information
Freax13 committed Sep 10, 2024
1 parent 3e93493 commit 6cf2edd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
23 changes: 15 additions & 8 deletions e2e/internal/kubeclient/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions e2e/release/release_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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()}
Expand Down

0 comments on commit 6cf2edd

Please sign in to comment.