Merge Consul OSS branch 'master' at commit d84863799deca45ccf4bec5ab9f645ccae6b3aeb
This commit is contained in:
commit
3ac803da5e
|
@ -281,6 +281,12 @@ func (c *ConfigEntry) ResolveServiceConfig(args *structs.ServiceConfigRequest, r
|
|||
}
|
||||
}
|
||||
|
||||
// Extract the global protocol from proxyConf for upstream configs.
|
||||
var proxyConfGlobalProtocol interface{}
|
||||
if proxyConf != nil && proxyConf.Config != nil {
|
||||
proxyConfGlobalProtocol = proxyConf.Config["protocol"]
|
||||
}
|
||||
|
||||
// Apply the upstream protocols to the upstream configs
|
||||
for _, upstream := range args.Upstreams {
|
||||
_, upstreamEntry, err := state.ConfigEntry(ws, structs.ServiceDefaults, upstream)
|
||||
|
@ -296,8 +302,19 @@ func (c *ConfigEntry) ResolveServiceConfig(args *structs.ServiceConfigRequest, r
|
|||
}
|
||||
}
|
||||
|
||||
// No upstream found; skip.
|
||||
if upstreamConf == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
// Fallback to proxyConf global protocol.
|
||||
protocol := proxyConfGlobalProtocol
|
||||
if upstreamConf.Protocol != "" {
|
||||
protocol = upstreamConf.Protocol
|
||||
}
|
||||
|
||||
// Nothing to configure if a protocol hasn't been set.
|
||||
if upstreamConf == nil || upstreamConf.Protocol == "" {
|
||||
if protocol == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -305,7 +322,7 @@ func (c *ConfigEntry) ResolveServiceConfig(args *structs.ServiceConfigRequest, r
|
|||
reply.UpstreamConfigs = make(map[string]map[string]interface{})
|
||||
}
|
||||
reply.UpstreamConfigs[upstream] = map[string]interface{}{
|
||||
"protocol": upstreamConf.Protocol,
|
||||
"protocol": protocol,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -733,6 +733,73 @@ func TestConfigEntry_ResolveServiceConfig(t *testing.T) {
|
|||
require.Equal(map[string]interface{}{"foo": 1}, proxyConf.Config)
|
||||
}
|
||||
|
||||
func TestConfigEntry_ResolveServiceConfig_UpstreamProxyDefaultsProtocol(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",
|
||||
},
|
||||
}))
|
||||
require.NoError(state.EnsureConfigEntry(2, &structs.ServiceConfigEntry{
|
||||
Kind: structs.ServiceDefaults,
|
||||
Name: "foo",
|
||||
}))
|
||||
require.NoError(state.EnsureConfigEntry(2, &structs.ServiceConfigEntry{
|
||||
Kind: structs.ServiceDefaults,
|
||||
Name: "bar",
|
||||
}))
|
||||
require.NoError(state.EnsureConfigEntry(2, &structs.ServiceConfigEntry{
|
||||
Kind: structs.ServiceDefaults,
|
||||
Name: "other",
|
||||
}))
|
||||
require.NoError(state.EnsureConfigEntry(2, &structs.ServiceConfigEntry{
|
||||
Kind: structs.ServiceDefaults,
|
||||
Name: "alreadyprotocol",
|
||||
Protocol: "grpc",
|
||||
}))
|
||||
|
||||
args := structs.ServiceConfigRequest{
|
||||
Name: "foo",
|
||||
Datacenter: s1.config.Datacenter,
|
||||
Upstreams: []string{"bar", "other", "alreadyprotocol", "dne"},
|
||||
}
|
||||
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",
|
||||
},
|
||||
"other": map[string]interface{}{
|
||||
"protocol": "http",
|
||||
},
|
||||
"alreadyprotocol": map[string]interface{}{
|
||||
"protocol": "grpc",
|
||||
},
|
||||
},
|
||||
// Don't know what this is deterministically
|
||||
QueryMeta: out.QueryMeta,
|
||||
}
|
||||
require.Equal(expected, out)
|
||||
}
|
||||
|
||||
func TestConfigEntry_ResolveServiceConfigNoConfig(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
|
Loading…
Reference in New Issue