mirror of https://github.com/hashicorp/consul
connect: ensure proxy-defaults protocol is used for upstreams (#7938)
parent
0a8a311bd7
commit
1b5023cb69
|
@ -360,14 +360,9 @@ func (c *ConfigEntry) ResolveServiceConfig(args *structs.ServiceConfigRequest, r
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// No upstream found; skip.
|
|
||||||
if upstreamConf == nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fallback to proxyConf global protocol.
|
// Fallback to proxyConf global protocol.
|
||||||
protocol := proxyConfGlobalProtocol
|
protocol := proxyConfGlobalProtocol
|
||||||
if upstreamConf.Protocol != "" {
|
if upstreamConf != nil && upstreamConf.Protocol != "" {
|
||||||
protocol = upstreamConf.Protocol
|
protocol = upstreamConf.Protocol
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1019,6 +1019,9 @@ func TestConfigEntry_ResolveServiceConfig_UpstreamProxyDefaultsProtocol(t *testi
|
||||||
"other": map[string]interface{}{
|
"other": map[string]interface{}{
|
||||||
"protocol": "http",
|
"protocol": "http",
|
||||||
},
|
},
|
||||||
|
"dne": map[string]interface{}{
|
||||||
|
"protocol": "http",
|
||||||
|
},
|
||||||
"alreadyprotocol": map[string]interface{}{
|
"alreadyprotocol": map[string]interface{}{
|
||||||
"protocol": "grpc",
|
"protocol": "grpc",
|
||||||
},
|
},
|
||||||
|
@ -1029,6 +1032,50 @@ func TestConfigEntry_ResolveServiceConfig_UpstreamProxyDefaultsProtocol(t *testi
|
||||||
require.Equal(expected, out)
|
require.Equal(expected, out)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestConfigEntry_ResolveServiceConfig_ProxyDefaultsProtocol_UsedForAllUpstreams(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()
|
||||||
|
|
||||||
|
// Create a dummy proxy/service config in the state store to look up.
|
||||||
|
state := s1.fsm.State()
|
||||||
|
require.NoError(state.EnsureConfigEntry(1, &structs.ProxyConfigEntry{
|
||||||
|
Kind: structs.ProxyDefaults,
|
||||||
|
Name: structs.ProxyConfigGlobal,
|
||||||
|
Config: map[string]interface{}{
|
||||||
|
"protocol": "http",
|
||||||
|
},
|
||||||
|
}, nil))
|
||||||
|
|
||||||
|
args := structs.ServiceConfigRequest{
|
||||||
|
Name: "foo",
|
||||||
|
Datacenter: s1.config.Datacenter,
|
||||||
|
Upstreams: []string{"bar"},
|
||||||
|
}
|
||||||
|
var out structs.ServiceConfigResponse
|
||||||
|
require.NoError(msgpackrpc.CallWithCodec(codec, "ConfigEntry.ResolveServiceConfig", &args, &out))
|
||||||
|
|
||||||
|
expected := structs.ServiceConfigResponse{
|
||||||
|
ProxyConfig: map[string]interface{}{
|
||||||
|
"protocol": "http",
|
||||||
|
},
|
||||||
|
UpstreamConfigs: map[string]map[string]interface{}{
|
||||||
|
"bar": map[string]interface{}{
|
||||||
|
"protocol": "http",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// Don't know what this is deterministically
|
||||||
|
QueryMeta: out.QueryMeta,
|
||||||
|
}
|
||||||
|
require.Equal(expected, out)
|
||||||
|
}
|
||||||
|
|
||||||
func TestConfigEntry_ResolveServiceConfigNoConfig(t *testing.T) {
|
func TestConfigEntry_ResolveServiceConfigNoConfig(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue