Skip to content

Commit

Permalink
test: Validate Service IP
Browse files Browse the repository at this point in the history
Validate resolved service IP when waiting for service to become
available.

This will help avoid test flakes where kube-dns is returning a stale
IP of a service that was just removed, e.g., when running test with
`--force-deploy`.

Signed-off-by: Jarno Rajahalme <[email protected]>
  • Loading branch information
jrajahalme committed Jul 14, 2021
1 parent 8ed8abb commit 84af027
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions connectivity/check/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"encoding/json"
"fmt"
"strconv"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -621,13 +622,25 @@ func (ct *ConnectivityTest) waitForService(ctx context.Context, service Service)

// Warning: ExecInPodWithStderr ignores ctx. Don't pass it here so we don't
// falsely expect the function to be able to be cancelled.
_, e, err := ct.client.ExecInPodWithStderr(context.TODO(),
stdout, e, err := ct.client.ExecInPodWithStderr(context.TODO(),
pod.Pod.Namespace, pod.Pod.Name, pod.Pod.Labels["name"],
[]string{"nslookup", service.Service.Name}) // BusyBox nslookup doesn't support any arguments.

// Lookup successful.
if err == nil {
return nil
svcIP := ""
switch service.Service.Spec.Type {
case corev1.ServiceTypeClusterIP, corev1.ServiceTypeNodePort:
svcIP = service.Service.Spec.ClusterIP
case corev1.ServiceTypeLoadBalancer:
if len(service.Service.Status.LoadBalancer.Ingress) > 0 {
svcIP = service.Service.Status.LoadBalancer.Ingress[0].IP
}
}
if strings.Contains(stdout.String(), svcIP) {
return nil
}
err = fmt.Errorf("Service IP %q not found in nslookup output %q", svcIP, stdout.String())
}

ct.Debugf("Error waiting for service %s: %s: %s", service.Name(), err, e.String())
Expand Down

0 comments on commit 84af027

Please sign in to comment.