connect: updating a service-defaults config entry should leave an unset protocol alone (#6342)

If the entry is updated for reasons other than protocol it is surprising
that the value is explicitly persisted as 'tcp' rather than leaving it
empty and letting it fall back dynamically on the proxy-defaults value.
This commit is contained in:
R.B. Boyer 2019-08-19 10:44:06 -05:00 committed by GitHub
parent 6012343e6b
commit 1a485011d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 15 deletions

View File

@ -23,11 +23,13 @@ func TestConfigEntry_Apply(t *testing.T) {
codec := rpcClient(t, s1)
defer codec.Close()
updated := &structs.ServiceConfigEntry{
Name: "foo",
}
args := structs.ConfigEntryRequest{
Datacenter: "dc1",
Entry: &structs.ServiceConfigEntry{
Name: "foo",
},
Entry: updated,
}
out := false
require.NoError(msgpackrpc.CallWithCodec(codec, "ConfigEntry.Apply", &args, &out))
@ -42,13 +44,17 @@ func TestConfigEntry_Apply(t *testing.T) {
require.Equal("foo", serviceConf.Name)
require.Equal(structs.ServiceDefaults, serviceConf.Kind)
updated = &structs.ServiceConfigEntry{
Name: "foo",
MeshGateway: structs.MeshGatewayConfig{
Mode: structs.MeshGatewayModeLocal,
},
}
args = structs.ConfigEntryRequest{
Datacenter: "dc1",
Op: structs.ConfigEntryUpsertCAS,
Entry: &structs.ServiceConfigEntry{
Name: "foo",
Protocol: "tcp",
},
Entry: updated,
}
require.NoError(msgpackrpc.CallWithCodec(codec, "ConfigEntry.Apply", &args, &out))
@ -64,9 +70,10 @@ func TestConfigEntry_Apply(t *testing.T) {
serviceConf, ok = entry.(*structs.ServiceConfigEntry)
require.True(ok)
require.Equal("foo", serviceConf.Name)
require.Equal("tcp", serviceConf.Protocol)
require.Equal(structs.ServiceDefaults, serviceConf.Kind)
updated.Kind = structs.ServiceDefaults // the server adds this
updated.RaftIndex = serviceConf.RaftIndex // these will always be different
require.Equal(updated, serviceConf)
}
func TestConfigEntry_ProxyDefaultsMeshGateway(t *testing.T) {

View File

@ -79,11 +79,7 @@ func (e *ServiceConfigEntry) Normalize() error {
}
e.Kind = ServiceDefaults
if e.Protocol == "" {
e.Protocol = DefaultServiceProtocol
} else {
e.Protocol = strings.ToLower(e.Protocol)
}
e.Protocol = strings.ToLower(e.Protocol)
return nil
}