diff --git a/pkg/config/builder.go b/pkg/config/builder.go index 9dcc321..81189fb 100644 --- a/pkg/config/builder.go +++ b/pkg/config/builder.go @@ -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") @@ -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 @@ -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 } diff --git a/pkg/config/builder_test.go b/pkg/config/builder_test.go index 8d5aaff..7e85803 100644 --- a/pkg/config/builder_test.go +++ b/pkg/config/builder_test.go @@ -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) { @@ -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 diff --git a/pkg/config/types.go b/pkg/config/types.go index 528d97b..dff6298 100644 --- a/pkg/config/types.go +++ b/pkg/config/types.go @@ -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 (