Merge pull request #14253 from obnoxxx/improve-is-host

network: improve  the IsHost() function
This commit is contained in:
Blaine Gardner authored and GitHub committed 2024-05-31 09:35:19 -06:00
commit ed2d110678
2 files changed
+39 -4

No files matched your search

+7 -2
View File
@@ -32,8 +32,13 @@ func (n *NetworkSpec) IsMultus() bool {
return n.Provider == NetworkProviderMultus
}
// IsHost get whether to use host network provider. This method also preserve
// compatibility with the old HostNetwork field.
// IsHost is intended to be used to determine if the rook operator should configure
// managed pods to use host networking.
// This behavior is enabled by configuring the cephCluster with the "host" network provider.
// This method also maintains compatibility with the old HostNetwork setting
// which is incompatible with other network providers: HostNetwork set to true
// together with an empty or unset network provider has the same effect as
// network.Provider set to "host"
func (n *NetworkSpec) IsHost() bool {
return (n.HostNetwork && n.Provider == NetworkProviderDefault) || n.Provider == NetworkProviderHost
}
+32 -2
View File
@@ -72,10 +72,40 @@ func TestValidateNetworkSpec(t *testing.T) {
assert.NoError(t, err)
}
func TestNetworkCephIsHostLegacy(t *testing.T) {
net := NetworkSpec{HostNetwork: true}
// test the NetworkSpec.IsHost method with different network providers
// Also test it in combination with the legacy
// "HostNetwork" setting.
func TestNetworkCephIsHost(t *testing.T) {
net := NetworkSpec{HostNetwork: false}
net.Provider = NetworkProviderHost
assert.True(t, net.IsHost())
net.Provider = NetworkProviderDefault
net.HostNetwork = true
assert.True(t, net.IsHost())
net = NetworkSpec{}
net.Provider = NetworkProviderDefault
net.HostNetwork = false
assert.False(t, net.IsHost())
net = NetworkSpec{}
net.Provider = NetworkProviderMultus
net.HostNetwork = false
assert.False(t, net.IsHost())
net = NetworkSpec{}
net.Provider = NetworkProviderMultus
net.HostNetwork = true
assert.False(t, net.IsHost())
// test with nonempty but invalid provider
net = NetworkSpec{}
net.HostNetwork = true
net.Provider = "foo"
assert.False(t, net.IsHost())
}
func TestNetworkSpec(t *testing.T) {