From 618d6771f859f56f89d61767e583cff164fb1f35 Mon Sep 17 00:00:00 2001 From: Matt Matejczyk Date: Mon, 8 Apr 2019 17:42:57 +0200 Subject: [PATCH] Add missing node.address != "" condition in tests It turns out to be a frequent bug that is revealed when nodes don't have external IP addresses. In the test we assume that in such case there won't be any addresses of type 'NodeExternalIp', which is invalid. In such case there will be an address of type 'NodeExternalIP', but with the empty 'Address' field. Ref. https://github.com/kubernetes/kubernetes/issues/76374 --- test/e2e/framework/service_util.go | 2 +- test/e2e/framework/ssh.go | 4 ++-- test/e2e/framework/util.go | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/e2e/framework/service_util.go b/test/e2e/framework/service_util.go index bfd756beb7..60a10853ef 100644 --- a/test/e2e/framework/service_util.go +++ b/test/e2e/framework/service_util.go @@ -320,7 +320,7 @@ func (j *ServiceTestJig) CreateLoadBalancerService(namespace, serviceName string func GetNodeAddresses(node *v1.Node, addressType v1.NodeAddressType) (ips []string) { for j := range node.Status.Addresses { nodeAddress := &node.Status.Addresses[j] - if nodeAddress.Type == addressType { + if nodeAddress.Type == addressType && nodeAddress.Address != "" { ips = append(ips, nodeAddress.Address) } } diff --git a/test/e2e/framework/ssh.go b/test/e2e/framework/ssh.go index 188bb35da9..d023885ba8 100644 --- a/test/e2e/framework/ssh.go +++ b/test/e2e/framework/ssh.go @@ -245,7 +245,7 @@ func IssueSSHCommandWithResult(cmd, provider string, node *v1.Node) (*SSHResult, Logf("Getting external IP address for %s", node.Name) host := "" for _, a := range node.Status.Addresses { - if a.Type == v1.NodeExternalIP { + if a.Type == v1.NodeExternalIP && a.Address != "" { host = net.JoinHostPort(a.Address, sshPort) break } @@ -254,7 +254,7 @@ func IssueSSHCommandWithResult(cmd, provider string, node *v1.Node) (*SSHResult, if host == "" { // No external IPs were found, let's try to use internal as plan B for _, a := range node.Status.Addresses { - if a.Type == v1.NodeInternalIP { + if a.Type == v1.NodeInternalIP && a.Address != "" { host = net.JoinHostPort(a.Address, sshPort) break } diff --git a/test/e2e/framework/util.go b/test/e2e/framework/util.go index d60390f7dd..954d75a8eb 100644 --- a/test/e2e/framework/util.go +++ b/test/e2e/framework/util.go @@ -3424,7 +3424,7 @@ func NodeAddresses(nodelist *v1.NodeList, addrType v1.NodeAddressType) []string hosts := []string{} for _, n := range nodelist.Items { for _, addr := range n.Status.Addresses { - if addr.Type == addrType { + if addr.Type == addrType && addr.Address != "" { hosts = append(hosts, addr.Address) break } @@ -4942,7 +4942,7 @@ func GetNodeExternalIP(node *v1.Node) (string, error) { Logf("Getting external IP address for %s", node.Name) host := "" for _, a := range node.Status.Addresses { - if a.Type == v1.NodeExternalIP { + if a.Type == v1.NodeExternalIP && a.Address != "" { host = net.JoinHostPort(a.Address, sshPort) break }