Skip to content

Commit 618d677

Browse files
committed
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. kubernetes#76374
1 parent 701e36b commit 618d677

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

test/e2e/framework/service_util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ func (j *ServiceTestJig) CreateLoadBalancerService(namespace, serviceName string
320320
func GetNodeAddresses(node *v1.Node, addressType v1.NodeAddressType) (ips []string) {
321321
for j := range node.Status.Addresses {
322322
nodeAddress := &node.Status.Addresses[j]
323-
if nodeAddress.Type == addressType {
323+
if nodeAddress.Type == addressType && nodeAddress.Address != "" {
324324
ips = append(ips, nodeAddress.Address)
325325
}
326326
}

test/e2e/framework/ssh.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ func IssueSSHCommandWithResult(cmd, provider string, node *v1.Node) (*SSHResult,
245245
Logf("Getting external IP address for %s", node.Name)
246246
host := ""
247247
for _, a := range node.Status.Addresses {
248-
if a.Type == v1.NodeExternalIP {
248+
if a.Type == v1.NodeExternalIP && a.Address != "" {
249249
host = net.JoinHostPort(a.Address, sshPort)
250250
break
251251
}
@@ -254,7 +254,7 @@ func IssueSSHCommandWithResult(cmd, provider string, node *v1.Node) (*SSHResult,
254254
if host == "" {
255255
// No external IPs were found, let's try to use internal as plan B
256256
for _, a := range node.Status.Addresses {
257-
if a.Type == v1.NodeInternalIP {
257+
if a.Type == v1.NodeInternalIP && a.Address != "" {
258258
host = net.JoinHostPort(a.Address, sshPort)
259259
break
260260
}

test/e2e/framework/util.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3424,7 +3424,7 @@ func NodeAddresses(nodelist *v1.NodeList, addrType v1.NodeAddressType) []string
34243424
hosts := []string{}
34253425
for _, n := range nodelist.Items {
34263426
for _, addr := range n.Status.Addresses {
3427-
if addr.Type == addrType {
3427+
if addr.Type == addrType && addr.Address != "" {
34283428
hosts = append(hosts, addr.Address)
34293429
break
34303430
}
@@ -4942,7 +4942,7 @@ func GetNodeExternalIP(node *v1.Node) (string, error) {
49424942
Logf("Getting external IP address for %s", node.Name)
49434943
host := ""
49444944
for _, a := range node.Status.Addresses {
4945-
if a.Type == v1.NodeExternalIP {
4945+
if a.Type == v1.NodeExternalIP && a.Address != "" {
49464946
host = net.JoinHostPort(a.Address, sshPort)
49474947
break
49484948
}

0 commit comments

Comments
 (0)