diff --git a/agent/agent.go b/agent/agent.go index 79c9eb1129..212672ea9f 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -2523,6 +2523,9 @@ func (a *Agent) loadProxies(conf *config.RuntimeConfig) error { if err != nil { return fmt.Errorf("failed adding proxy: %s", err) } + if proxy == nil { + continue + } if err := a.AddProxy(proxy, false); err != nil { return fmt.Errorf("failed adding proxy: %s", err) } diff --git a/agent/agent_test.go b/agent/agent_test.go index 022c25f8e4..768d1c9512 100644 --- a/agent/agent_test.go +++ b/agent/agent_test.go @@ -15,8 +15,6 @@ import ( "testing" "time" - "github.com/stretchr/testify/require" - "github.com/hashicorp/consul/agent/checks" "github.com/hashicorp/consul/agent/structs" "github.com/hashicorp/consul/api" @@ -25,6 +23,7 @@ import ( "github.com/hashicorp/consul/types" uuid "github.com/hashicorp/go-uuid" "github.com/pascaldekloe/goe/verify" + "github.com/stretchr/testify/require" ) func externalIP() (string, error) { @@ -1669,6 +1668,27 @@ func TestAgent_loadProxies(t *testing.T) { } } +func TestAgent_loadProxies_nilProxy(t *testing.T) { + t.Parallel() + a := NewTestAgent(t.Name(), ` + service = { + id = "rabbitmq" + name = "rabbitmq" + port = 5672 + token = "abc123" + connect { + } + } + `) + defer a.Shutdown() + + services := a.State.Services() + require.Contains(t, services, "rabbitmq") + require.Equal(t, "abc123", a.State.ServiceToken("rabbitmq")) + require.NotContains(t, services, "rabbitme-proxy") + require.Empty(t, a.State.Proxies()) +} + func TestAgent_unloadProxies(t *testing.T) { t.Parallel() a := NewTestAgent(t.Name(), `