Fallback to ExternalIP in tests.

Make test code behave like [GetNodeHostIPs()](https://pkg.go.dev/k8s.io/kubernetes/pkg/util/node#GetNodeHostIPs)

First try InternalIP, then ExternalIP.
This commit is contained in:
Thomas Güttler
2026-02-04 12:04:42 +01:00
parent 23fc0bff62
commit 8e7eb56023
3 changed files with 16 additions and 4 deletions

View File

@@ -78,6 +78,9 @@ var _ = common.SIGDescribe("HostPort", func() {
randomNode := &nodes.Items[rand.Intn(len(nodes.Items))]
ips := e2enode.GetAddressesByTypeAndFamily(randomNode, v1.NodeInternalIP, family)
if len(ips) == 0 {
ips = e2enode.GetAddressesByTypeAndFamily(randomNode, v1.NodeExternalIP, family)
}
if len(ips) == 0 {
framework.Failf("Failed to get NodeIP")
}

View File

@@ -4215,7 +4215,10 @@ func execAffinityTestForSessionAffinityTimeout(ctx context.Context, f *framework
family = v1.IPv6Protocol
}
svcIP = e2enode.FirstAddressByTypeAndFamily(nodes, v1.NodeInternalIP, family)
gomega.Expect(svcIP).NotTo(gomega.BeEmpty(), "failed to get Node internal IP for family: %s", family)
if svcIP == "" {
svcIP = e2enode.FirstAddressByTypeAndFamily(nodes, v1.NodeExternalIP, family)
}
gomega.Expect(svcIP).NotTo(gomega.BeEmpty(), "failed to get Node IP for family: %s", family)
servicePort = int(svc.Spec.Ports[0].NodePort)
} else {
svcIP = svc.Spec.ClusterIP
@@ -4298,7 +4301,10 @@ func execAffinityTestForNonLBServiceWithOptionalTransition(ctx context.Context,
family = v1.IPv6Protocol
}
svcIP = e2enode.FirstAddressByTypeAndFamily(nodes, v1.NodeInternalIP, family)
gomega.Expect(svcIP).NotTo(gomega.BeEmpty(), "failed to get Node internal IP for family: %s", family)
if svcIP == "" {
svcIP = e2enode.FirstAddressByTypeAndFamily(nodes, v1.NodeExternalIP, family)
}
gomega.Expect(svcIP).NotTo(gomega.BeEmpty(), "failed to get Node IP for family: %s", family)
servicePort = int(svc.Spec.Ports[0].NodePort)
} else {
svcIP = svc.Spec.ClusterIP

View File

@@ -1268,8 +1268,11 @@ func getNodeHostIP(ctx context.Context, f *framework.Framework, nodeName string)
framework.ExpectNoError(err)
ips := e2enode.GetAddressesByTypeAndFamily(node, v1.NodeInternalIP, family)
if len(ips) == 0 {
framework.Failf("No address by type (%s) and family (%s) on node (%s) found.",
v1.NodeInternalIP, family, nodeName)
ips = e2enode.GetAddressesByTypeAndFamily(node, v1.NodeExternalIP, family)
}
if len(ips) == 0 {
framework.Failf("No address by family (%s) on node (%s) found.",
family, nodeName)
}
return ips[0]
}