diff --git a/nomad/structs/services.go b/nomad/structs/services.go index 2ca1dd81f2d..54935b7310d 100644 --- a/nomad/structs/services.go +++ b/nomad/structs/services.go @@ -1352,9 +1352,12 @@ func (p *ConsulGatewayProxy) Copy() *ConsulGatewayProxy { return nil } - bindAddresses := make(map[string]*ConsulGatewayBindAddress, len(p.EnvoyGatewayBindAddresses)) - for k, v := range p.EnvoyGatewayBindAddresses { - bindAddresses[k] = v.Copy() + var bindAddresses map[string]*ConsulGatewayBindAddress + if p.EnvoyGatewayBindAddresses != nil { + bindAddresses = make(map[string]*ConsulGatewayBindAddress, len(p.EnvoyGatewayBindAddresses)) + for k, v := range p.EnvoyGatewayBindAddresses { + bindAddresses[k] = v.Copy() + } } return &ConsulGatewayProxy{ diff --git a/nomad/structs/services_test.go b/nomad/structs/services_test.go index 12b3b5b55c4..3b46b4895ac 100644 --- a/nomad/structs/services_test.go +++ b/nomad/structs/services_test.go @@ -293,6 +293,23 @@ func TestConsulConnect_CopyEquals(t *testing.T) { require.False(t, c.Equals(o)) } +func TestConsulConnect_GatewayProxy_CopyEquals(t *testing.T) { + t.Parallel() + + c := &ConsulGatewayProxy{ + ConnectTimeout: helper.TimeToPtr(1 * time.Second), + EnvoyGatewayBindTaggedAddresses: false, + EnvoyGatewayBindAddresses: nil, + } + + require.NoError(t, c.Validate()) + + // Copies should be equivalent + o := c.Copy() + require.Equal(t, c, o) + require.True(t, c.Equals(o)) +} + func TestSidecarTask_MergeIntoTask(t *testing.T) { t.Parallel()