Skip to content

Commit

Permalink
Merge pull request #9 from burmanm/change_network_settings
Browse files Browse the repository at this point in the history
Change network settings to more conservative approach
  • Loading branch information
burmanm authored Jul 27, 2023
2 parents bee01cc + f621422 commit 73bae73
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
24 changes: 17 additions & 7 deletions pkg/config/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ func parseNodeInfo() (*NodeInfo, error) {
}

podIp := os.Getenv("POD_IP")
hostIp := os.Getenv("HOST_IP")

useHostIp := false
useHostIpStr := os.Getenv("USE_HOST_IP_FOR_BROADCAST")
Expand All @@ -122,12 +123,22 @@ func parseNodeInfo() (*NodeInfo, error) {
}
}

broadcastIp := podIp
if useHostIp {
podIp = os.Getenv("HOST_IP")
broadcastIp = hostIp
}

if ip := net.ParseIP(broadcastIp); ip != nil {
n.BroadcastIP = ip
}

if ip := net.ParseIP(podIp); ip != nil {
n.IP = ip
n.ListenIP = ip
}

// This is not currently overridable
if ip := net.ParseIP("0.0.0.0"); ip != nil {
n.RPCIP = ip
}

return n, nil
Expand Down Expand Up @@ -455,11 +466,10 @@ func k8ssandraOverrides(merged map[string]interface{}, configInput *ConfigInput,
},
}

listenIP := nodeInfo.IP.String()
merged["listen_address"] = listenIP
merged["rpc_address"] = listenIP
delete(merged, "broadcast_address") // Sets it to the same as listen_address
delete(merged, "rpc_broadcast_address") // Sets it to the same as rpc_address
merged["listen_address"] = nodeInfo.ListenIP.String()
merged["rpc_address"] = nodeInfo.RPCIP.String()
delete(merged, "broadcast_address") // Sets it to the same as listen_address
merged["broadcast_rpc_address"] = nodeInfo.BroadcastIP

return merged
}
Expand Down
15 changes: 10 additions & 5 deletions pkg/config/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,26 +110,31 @@ func TestParseNodeInfo(t *testing.T) {
nodeInfo, err := parseNodeInfo()
require.NoError(err)
require.NotNil(nodeInfo)
require.Equal("172.27.0.1", nodeInfo.IP.String())
require.Equal("172.27.0.1", nodeInfo.ListenIP.String())
require.Equal("172.27.0.1", nodeInfo.BroadcastIP.String())
require.Equal("0.0.0.0", nodeInfo.RPCIP.String())
require.Equal("r1", nodeInfo.Rack)

t.Setenv("HOST_IP", "10.0.0.1")
nodeInfo, err = parseNodeInfo()
require.NoError(err)
require.NotNil(nodeInfo)
require.Equal("172.27.0.1", nodeInfo.IP.String())
require.Equal("172.27.0.1", nodeInfo.ListenIP.String())
require.Equal("172.27.0.1", nodeInfo.BroadcastIP.String())

t.Setenv("USE_HOST_IP_FOR_BROADCAST", "false")
nodeInfo, err = parseNodeInfo()
require.NoError(err)
require.NotNil(nodeInfo)
require.Equal("172.27.0.1", nodeInfo.IP.String())
require.Equal("172.27.0.1", nodeInfo.ListenIP.String())
require.Equal("172.27.0.1", nodeInfo.BroadcastIP.String())

t.Setenv("USE_HOST_IP_FOR_BROADCAST", "true")
nodeInfo, err = parseNodeInfo()
require.NoError(err)
require.NotNil(nodeInfo)
require.Equal("10.0.0.1", nodeInfo.IP.String())
require.Equal("172.27.0.1", nodeInfo.ListenIP.String())
require.Equal("10.0.0.1", nodeInfo.BroadcastIP.String())
}

func TestBuild(t *testing.T) {
Expand Down Expand Up @@ -209,7 +214,7 @@ func TestCassandraYamlWriting(t *testing.T) {
seedProvider := seedProviders[0].(map[string]interface{})
require.Equal("org.apache.cassandra.locator.K8SeedProvider", seedProvider["class_name"])

listenIP := nodeInfo.IP.String()
listenIP := nodeInfo.ListenIP.String()
require.Equal(listenIP, cassandraYaml["listen_address"])

// Verify our changed properties are there
Expand Down
8 changes: 5 additions & 3 deletions pkg/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ type DatacenterInfo struct {
// Built from other sources

type NodeInfo struct {
Name string
Rack string
IP net.IP
Name string
Rack string
ListenIP net.IP
BroadcastIP net.IP
RPCIP net.IP
}

var (
Expand Down

0 comments on commit 73bae73

Please sign in to comment.