diff --git a/agent/consul/config_endpoint.go b/agent/consul/config_endpoint.go index 348c4c9a3..cbf474087 100644 --- a/agent/consul/config_endpoint.go +++ b/agent/consul/config_endpoint.go @@ -256,11 +256,11 @@ func (c *ConfigEntry) ResolveServiceConfig(args *structs.ServiceConfigRequest, r if !ok { return fmt.Errorf("invalid proxy config type %T", proxyEntry) } + // Apply the proxy defaults to the sidecar's proxy config + reply.ProxyConfig = proxyConf.Config } reply.Index = index - // Apply the proxy defaults to the sidecar's proxy config - reply.ProxyConfig = proxyConf.Config if serviceConf != nil && serviceConf.Protocol != "" { if reply.ProxyConfig == nil { diff --git a/agent/consul/config_endpoint_test.go b/agent/consul/config_endpoint_test.go index bc035d5a4..6c815869d 100644 --- a/agent/consul/config_endpoint_test.go +++ b/agent/consul/config_endpoint_test.go @@ -697,6 +697,45 @@ func TestConfigEntry_ResolveServiceConfig(t *testing.T) { require.Equal(expected, out) } +func TestConfigEntry_ResolveServiceConfigNoConfig(t *testing.T) { + t.Parallel() + + require := require.New(t) + + dir1, s1 := testServer(t) + defer os.RemoveAll(dir1) + defer s1.Shutdown() + codec := rpcClient(t, s1) + defer codec.Close() + + // Don't create any config and make sure we don't nil panic (spoiler alert - + // we did in first RC) + args := structs.ServiceConfigRequest{ + Name: "foo", + Datacenter: s1.config.Datacenter, + Upstreams: []string{"bar", "baz"}, + } + var out structs.ServiceConfigResponse + require.NoError(msgpackrpc.CallWithCodec(codec, "ConfigEntry.ResolveServiceConfig", &args, &out)) + // Hack to fix up the string encoding in the map[string]interface{}. + // msgpackRPC's codec doesn't use RawToString. + var err error + out.ProxyConfig, err = lib.MapWalk(out.ProxyConfig) + require.NoError(err) + for k := range out.UpstreamConfigs { + out.UpstreamConfigs[k], err = lib.MapWalk(out.UpstreamConfigs[k]) + require.NoError(err) + } + + expected := structs.ServiceConfigResponse{ + ProxyConfig: nil, + UpstreamConfigs: nil, + // Don't know what this is deterministically + QueryMeta: out.QueryMeta, + } + require.Equal(expected, out) +} + func TestConfigEntry_ResolveServiceConfig_ACLDeny(t *testing.T) { t.Parallel()