From 1a485011d0092e6866b90ed72ed0316d24ae3d05 Mon Sep 17 00:00:00 2001 From: "R.B. Boyer" Date: Mon, 19 Aug 2019 10:44:06 -0500 Subject: [PATCH] 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. --- agent/consul/config_endpoint_test.go | 27 +++++++++++++++++---------- agent/structs/config_entry.go | 6 +----- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/agent/consul/config_endpoint_test.go b/agent/consul/config_endpoint_test.go index e1ab202729..ec32be119b 100644 --- a/agent/consul/config_endpoint_test.go +++ b/agent/consul/config_endpoint_test.go @@ -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) { diff --git a/agent/structs/config_entry.go b/agent/structs/config_entry.go index aa5458cf31..293a5efa71 100644 --- a/agent/structs/config_entry.go +++ b/agent/structs/config_entry.go @@ -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 }