Browse Source

agent/consul: require name for proxies

pull/4275/head
Mitchell Hashimoto 7 years ago
parent
commit
2feef5f7a3
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
  1. 11
      agent/consul/catalog_endpoint.go
  2. 30
      agent/consul/catalog_endpoint_test.go
  3. 7
      agent/structs/structs.go

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

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

7
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

Loading…
Cancel
Save