agent/consul: require name for proxies
This commit is contained in:
parent
4207bb42c0
commit
566c98b2fc
|
@ -47,17 +47,6 @@ func (c *Catalog) Register(args *structs.RegisterRequest, reply *struct{}) error
|
||||||
|
|
||||||
// Handle a service registration.
|
// Handle a service registration.
|
||||||
if args.Service != nil {
|
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
|
// 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
|
// the above just hasn't been moved over yet. We should move it over
|
||||||
// in time.
|
// in time.
|
||||||
|
|
|
@ -384,36 +384,6 @@ func TestCatalog_Register_ConnectProxy_invalid(t *testing.T) {
|
||||||
assert.Contains(err.Error(), "ProxyDestination")
|
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.
|
// Test that write is required for the proxy destination to register a proxy.
|
||||||
func TestCatalog_Register_ConnectProxy_ACLProxyDestination(t *testing.T) {
|
func TestCatalog_Register_ConnectProxy_ACLProxyDestination(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
|
@ -462,8 +462,11 @@ type ServiceNodes []*ServiceNode
|
||||||
type ServiceKind string
|
type ServiceKind string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// ServiceKindTypical is a typical, classic Consul service.
|
// ServiceKindTypical is a typical, classic Consul service. This is
|
||||||
ServiceKindTypical ServiceKind = "typical"
|
// 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
|
// ServiceKindConnectProxy is a proxy for the Connect feature. This
|
||||||
// service proxies another service within Consul and speaks the connect
|
// service proxies another service within Consul and speaks the connect
|
||||||
|
|
Loading…
Reference in New Issue