From 566c98b2fcb7bc0f6877e5078785cb57e5e5d30f Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 11 Mar 2018 09:11:10 -0700 Subject: [PATCH] agent/consul: require name for proxies --- agent/consul/catalog_endpoint.go | 11 ---------- agent/consul/catalog_endpoint_test.go | 30 --------------------------- agent/structs/structs.go | 7 +++++-- 3 files changed, 5 insertions(+), 43 deletions(-) diff --git a/agent/consul/catalog_endpoint.go b/agent/consul/catalog_endpoint.go index 840b97fa6..adde8e52e 100644 --- a/agent/consul/catalog_endpoint.go +++ b/agent/consul/catalog_endpoint.go @@ -47,17 +47,6 @@ func (c *Catalog) Register(args *structs.RegisterRequest, reply *struct{}) error // Handle a service registration. if args.Service != nil { - // Connect proxy specific logic - if args.Service.Kind == structs.ServiceKindConnectProxy { - // Name is optional, if it isn't set, we default to the - // proxy name. It actually MUST be this, but the validation - // below this will verify. - if args.Service.Service == "" { - args.Service.Service = fmt.Sprintf( - "%s-connect-proxy", args.Service.ProxyDestination) - } - } - // Validate the service. This is in addition to the below since // the above just hasn't been moved over yet. We should move it over // in time. diff --git a/agent/consul/catalog_endpoint_test.go b/agent/consul/catalog_endpoint_test.go index b095c3f3a..fd437c978 100644 --- a/agent/consul/catalog_endpoint_test.go +++ b/agent/consul/catalog_endpoint_test.go @@ -384,36 +384,6 @@ func TestCatalog_Register_ConnectProxy_invalid(t *testing.T) { assert.Contains(err.Error(), "ProxyDestination") } -// Test registering a proxy with no name set, which should work. -func TestCatalog_Register_ConnectProxy_noName(t *testing.T) { - t.Parallel() - - assert := assert.New(t) - dir1, s1 := testServer(t) - defer os.RemoveAll(dir1) - defer s1.Shutdown() - codec := rpcClient(t, s1) - defer codec.Close() - - args := structs.TestRegisterRequestProxy(t) - args.Service.Service = "" - - // Register - var out struct{} - assert.Nil(msgpackrpc.CallWithCodec(codec, "Catalog.Register", &args, &out)) - - // List - req := structs.ServiceSpecificRequest{ - Datacenter: "dc1", - ServiceName: fmt.Sprintf("%s-connect-proxy", args.Service.ProxyDestination), - } - var resp structs.IndexedServiceNodes - assert.Nil(msgpackrpc.CallWithCodec(codec, "Catalog.ServiceNodes", &req, &resp)) - assert.Len(resp.ServiceNodes, 1) - v := resp.ServiceNodes[0] - assert.Equal(structs.ServiceKindConnectProxy, v.ServiceKind) -} - // Test that write is required for the proxy destination to register a proxy. func TestCatalog_Register_ConnectProxy_ACLProxyDestination(t *testing.T) { t.Parallel() diff --git a/agent/structs/structs.go b/agent/structs/structs.go index f8f339a5b..40b606d17 100644 --- a/agent/structs/structs.go +++ b/agent/structs/structs.go @@ -462,8 +462,11 @@ type ServiceNodes []*ServiceNode type ServiceKind string const ( - // ServiceKindTypical is a typical, classic Consul service. - ServiceKindTypical ServiceKind = "typical" + // ServiceKindTypical is a typical, classic Consul service. This is + // represented by the absense of a value. This was chosen for ease of + // backwards compatibility: existing services in the catalog would + // default to the typical service. + ServiceKindTypical ServiceKind = "" // ServiceKindConnectProxy is a proxy for the Connect feature. This // service proxies another service within Consul and speaks the connect