Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Validate Service IP #422

Merged
merged 1 commit into from
Aug 13, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 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 @@ -436,6 +437,16 @@ func (ct *ConnectivityTest) validateDeployment(ctx context.Context) error {
}

for _, echoService := range echoServices.Items {
if ct.params.MultiCluster != "" {
if _, exists := ct.echoServices[echoService.Name]; exists {
// ct.clients.clients() lists the client cluster first.
// If we already have this service (for the client cluster), keep it
// so that we can rely on the service's ClusterIP being valid for the
// client pods.
continue
}
}

ct.echoServices[echoService.Name] = Service{
Service: echoService.DeepCopy(),
}
Expand Down Expand Up @@ -615,16 +626,33 @@ func (ct *ConnectivityTest) waitForService(ctx context.Context, service Service)
// Don't retry lookups more often than once per second.
r := time.After(time.Second)

e, err := ct.client.ExecInPodWithTTY(ctx,
stdout, err := ct.client.ExecInPodWithTTY(ctx,
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 svcIP == "" {
return nil
}

nslookupStr := strings.ReplaceAll(stdout.String(), "\r\n", "\n")
if strings.Contains(nslookupStr, "Address: "+svcIP+"\n") {
return nil
}
err = fmt.Errorf("Service IP %q not found in nslookup output %q", svcIP, nslookupStr)
}

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

// Wait for the pace timer to avoid busy polling.
<-r
Expand Down