Skip to content

Commit

Permalink
fix defaulting to address
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinschoonover committed Nov 29, 2021
1 parent 3096593 commit 66cd2d7
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
6 changes: 3 additions & 3 deletions command/agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func TestAgent_ServerConfig(t *testing.T) {
require.Equal(t, "127.0.0.2", conf.Addresses.HTTP)
require.Equal(t, "127.0.0.2", conf.Addresses.RPC)
require.Equal(t, "127.0.0.2", conf.Addresses.Serf)
require.Equal(t, "127.0.0.2:4646", conf.normalizedAddrs.HTTP)
require.Equal(t, []string{"127.0.0.2:4646"}, conf.normalizedAddrs.HTTP)
require.Equal(t, "127.0.0.2:4003", conf.normalizedAddrs.RPC)
require.Equal(t, "127.0.0.2:4004", conf.normalizedAddrs.Serf)
require.Equal(t, "10.0.0.10:4646", conf.AdvertiseAddrs.HTTP)
Expand Down Expand Up @@ -563,7 +563,7 @@ func TestAgent_HTTPCheck(t *testing.T) {
logger: logger,
config: &Config{
AdvertiseAddrs: &AdvertiseAddrs{HTTP: "advertise:4646"},
normalizedAddrs: &Addresses{HTTP: "normalized:4646"},
normalizedAddrs: &NormalizedAddrs{HTTP: []string{"normalized:4646"}},
Consul: &config.ConsulConfig{
ChecksUseAdvertise: helper.BoolToPtr(false),
},
Expand All @@ -587,7 +587,7 @@ func TestAgent_HTTPCheck(t *testing.T) {
if check.Protocol != "http" {
t.Errorf("expected http proto not: %q", check.Protocol)
}
if expected := a.config.normalizedAddrs.HTTP; check.PortLabel != expected {
if expected := a.config.normalizedAddrs.HTTP[0]; check.PortLabel != expected {
t.Errorf("expected normalized addr not %q", check.PortLabel)
}
})
Expand Down
4 changes: 2 additions & 2 deletions command/agent/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1261,7 +1261,7 @@ func (c *Config) normalizeAddrs() error {
Serf: net.JoinHostPort(c.Addresses.Serf, strconv.Itoa(c.Ports.Serf)),
}

addr, err = normalizeAdvertise(c.AdvertiseAddrs.HTTP, c.BindAddr, c.Ports.HTTP, c.DevMode)
addr, err = normalizeAdvertise(c.AdvertiseAddrs.HTTP, httpAddrs[0], c.Ports.HTTP, c.DevMode)
if err != nil {
return fmt.Errorf("Failed to parse HTTP advertise address (%v, %v, %v, %v): %v", c.AdvertiseAddrs.HTTP, c.Addresses.HTTP, c.Ports.HTTP, c.DevMode, err)
}
Expand Down Expand Up @@ -2034,7 +2034,7 @@ func LoadConfigDir(dir string) (*Config, error) {

// joinHostPorts joins every addr in addrs with the specified port
func joinHostPorts(addrs []string, port string) []string {
localAddrs := addrs
localAddrs := make([]string, len(addrs))
for i, k := range addrs {
localAddrs[i] = net.JoinHostPort(k, port)

Expand Down
3 changes: 1 addition & 2 deletions command/agent/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -957,8 +957,7 @@ func TestConfig_normalizeAddrs(t *testing.T) {
t.Fatalf("expected BindAddr 169.254.1.5, got %s", c.BindAddr)
}

// was this test case incorrect? should default to bind addr if not specified (https://www.nomadproject.io/docs/configuration#advertise)
if c.AdvertiseAddrs.HTTP != "169.254.1.5:4646" {
if c.AdvertiseAddrs.HTTP != "169.254.1.10:4646" {
t.Fatalf("expected HTTP advertise address 169.254.1.5:4646, got %s", c.AdvertiseAddrs.HTTP)
}

Expand Down
6 changes: 3 additions & 3 deletions command/agent/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -945,8 +945,8 @@ func TestHTTPServer_Limits_Error(t *testing.T) {
t.Parallel()

conf := &Config{
normalizedAddrs: &Addresses{
HTTP: "localhost:0", // port is never used
normalizedAddrs: &NormalizedAddrs{
HTTP: []string{"localhost:0"}, // port is never used
},
TLSConfig: &config.TLSConfig{
EnableHTTP: tc.tls,
Expand All @@ -964,7 +964,7 @@ func TestHTTPServer_Limits_Error(t *testing.T) {
config: conf,
}

srv, err := NewHTTPServer(agent, conf)
srv, err := NewHTTPServers(agent, conf)
require.Error(t, err)
require.Nil(t, srv)
require.Contains(t, err.Error(), tc.expectedErr)
Expand Down

0 comments on commit 66cd2d7

Please sign in to comment.