Skip to content

Commit 518f3ed

Browse files
Merge pull request #1446 from jluhrsen/OCPBUGS-1661
UPSTREAM: 113799: tests: network: Prefer internal IPs first
2 parents 8564fb8 + 25af2bb commit 518f3ed

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

test/e2e/framework/network/utils.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ func EndpointsUseHostNetwork(config *NetworkingTestConfig) {
117117
config.EndpointsHostNetwork = true
118118
}
119119

120+
// PreferExternalAddresses prefer node External Addresses for the tests
121+
func PreferExternalAddresses(config *NetworkingTestConfig) {
122+
config.PreferExternalAddresses = true
123+
}
124+
120125
// NewNetworkingTestConfig creates and sets up a new test config helper.
121126
func NewNetworkingTestConfig(f *framework.Framework, setters ...Option) *NetworkingTestConfig {
122127
// default options
@@ -205,6 +210,8 @@ type NetworkingTestConfig struct {
205210
// The kubernetes namespace within which all resources for this
206211
// config are created
207212
Namespace string
213+
// Whether to prefer node External Addresses for the tests
214+
PreferExternalAddresses bool
208215
}
209216

210217
// NetexecDialResponse represents the response returned by the `netexec` subcommand of `agnhost`
@@ -817,13 +824,17 @@ func (config *NetworkingTestConfig) setup(selector map[string]string) {
817824
family = v1.IPv6Protocol
818825
secondaryFamily = v1.IPv4Protocol
819826
}
820-
// Get Node IPs from the cluster, ExternalIPs take precedence
821-
config.NodeIP = e2enode.FirstAddressByTypeAndFamily(nodeList, v1.NodeExternalIP, family)
827+
if config.PreferExternalAddresses {
828+
// Get Node IPs from the cluster, ExternalIPs take precedence
829+
config.NodeIP = e2enode.FirstAddressByTypeAndFamily(nodeList, v1.NodeExternalIP, family)
830+
}
822831
if config.NodeIP == "" {
823832
config.NodeIP = e2enode.FirstAddressByTypeAndFamily(nodeList, v1.NodeInternalIP, family)
824833
}
825834
if config.DualStackEnabled {
826-
config.SecondaryNodeIP = e2enode.FirstAddressByTypeAndFamily(nodeList, v1.NodeExternalIP, secondaryFamily)
835+
if config.PreferExternalAddresses {
836+
config.SecondaryNodeIP = e2enode.FirstAddressByTypeAndFamily(nodeList, v1.NodeExternalIP, secondaryFamily)
837+
}
827838
if config.SecondaryNodeIP == "" {
828839
config.SecondaryNodeIP = e2enode.FirstAddressByTypeAndFamily(nodeList, v1.NodeInternalIP, secondaryFamily)
829840
}

0 commit comments

Comments
 (0)