agent/consul: require name for proxies

This commit is contained in:
Mitchell Hashimoto 2018-03-11 09:11:10 -07:00
parent 4207bb42c0
commit 566c98b2fc
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
3 changed files with 5 additions and 43 deletions

View File

@ -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.

View File

@ -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()

View File

@ -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