agent/consul: support catalog registration with Connect native
This commit is contained in:
parent
55b3d5d6f4
commit
8e02bbc897
|
@ -444,6 +444,36 @@ service "foo" {
|
||||||
assert.Nil(msgpackrpc.CallWithCodec(codec, "Catalog.Register", &args, &out))
|
assert.Nil(msgpackrpc.CallWithCodec(codec, "Catalog.Register", &args, &out))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCatalog_Register_ConnectNative(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.TestRegisterRequest(t)
|
||||||
|
args.Service.ConnectNative = true
|
||||||
|
|
||||||
|
// Register
|
||||||
|
var out struct{}
|
||||||
|
assert.Nil(msgpackrpc.CallWithCodec(codec, "Catalog.Register", &args, &out))
|
||||||
|
|
||||||
|
// List
|
||||||
|
req := structs.ServiceSpecificRequest{
|
||||||
|
Datacenter: "dc1",
|
||||||
|
ServiceName: args.Service.Service,
|
||||||
|
}
|
||||||
|
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.ServiceKindTypical, v.ServiceKind)
|
||||||
|
assert.True(v.ServiceConnectNative)
|
||||||
|
}
|
||||||
|
|
||||||
func TestCatalog_Deregister(t *testing.T) {
|
func TestCatalog_Deregister(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
dir1, s1 := testServer(t)
|
dir1, s1 := testServer(t)
|
||||||
|
@ -1877,6 +1907,37 @@ service "foo" {
|
||||||
assert.Equal("foo-proxy", v.ServiceName)
|
assert.Equal("foo-proxy", v.ServiceName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCatalog_ListServiceNodes_ConnectNative(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()
|
||||||
|
|
||||||
|
testrpc.WaitForLeader(t, s1.RPC, "dc1")
|
||||||
|
|
||||||
|
// Register the service
|
||||||
|
args := structs.TestRegisterRequest(t)
|
||||||
|
args.Service.ConnectNative = true
|
||||||
|
var out struct{}
|
||||||
|
assert.Nil(msgpackrpc.CallWithCodec(codec, "Catalog.Register", args, &out))
|
||||||
|
|
||||||
|
// List
|
||||||
|
req := structs.ServiceSpecificRequest{
|
||||||
|
Datacenter: "dc1",
|
||||||
|
ServiceName: args.Service.Service,
|
||||||
|
TagFilter: false,
|
||||||
|
}
|
||||||
|
var resp structs.IndexedServiceNodes
|
||||||
|
assert.Nil(msgpackrpc.CallWithCodec(codec, "Catalog.ServiceNodes", &req, &resp))
|
||||||
|
assert.Len(resp.ServiceNodes, 1)
|
||||||
|
v := resp.ServiceNodes[0]
|
||||||
|
assert.Equal(args.Service.ConnectNative, v.ServiceConnectNative)
|
||||||
|
}
|
||||||
|
|
||||||
func TestCatalog_NodeServices(t *testing.T) {
|
func TestCatalog_NodeServices(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
dir1, s1 := testServer(t)
|
dir1, s1 := testServer(t)
|
||||||
|
@ -1958,6 +2019,36 @@ func TestCatalog_NodeServices_ConnectProxy(t *testing.T) {
|
||||||
assert.Equal(args.Service.ProxyDestination, v.ProxyDestination)
|
assert.Equal(args.Service.ProxyDestination, v.ProxyDestination)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCatalog_NodeServices_ConnectNative(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()
|
||||||
|
|
||||||
|
testrpc.WaitForLeader(t, s1.RPC, "dc1")
|
||||||
|
|
||||||
|
// Register the service
|
||||||
|
args := structs.TestRegisterRequest(t)
|
||||||
|
var out struct{}
|
||||||
|
assert.Nil(msgpackrpc.CallWithCodec(codec, "Catalog.Register", args, &out))
|
||||||
|
|
||||||
|
// List
|
||||||
|
req := structs.NodeSpecificRequest{
|
||||||
|
Datacenter: "dc1",
|
||||||
|
Node: args.Node,
|
||||||
|
}
|
||||||
|
var resp structs.IndexedNodeServices
|
||||||
|
assert.Nil(msgpackrpc.CallWithCodec(codec, "Catalog.NodeServices", &req, &resp))
|
||||||
|
|
||||||
|
assert.Len(resp.NodeServices.Services, 1)
|
||||||
|
v := resp.NodeServices.Services[args.Service.Service]
|
||||||
|
assert.Equal(args.Service.ConnectNative, v.ConnectNative)
|
||||||
|
}
|
||||||
|
|
||||||
// Used to check for a regression against a known bug
|
// Used to check for a regression against a known bug
|
||||||
func TestCatalog_Register_FailedCase1(t *testing.T) {
|
func TestCatalog_Register_FailedCase1(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
|
@ -432,6 +432,7 @@ type ServiceNode struct {
|
||||||
ServicePort int
|
ServicePort int
|
||||||
ServiceEnableTagOverride bool
|
ServiceEnableTagOverride bool
|
||||||
ServiceProxyDestination string
|
ServiceProxyDestination string
|
||||||
|
ServiceConnectNative bool
|
||||||
|
|
||||||
RaftIndex
|
RaftIndex
|
||||||
}
|
}
|
||||||
|
@ -460,6 +461,7 @@ func (s *ServiceNode) PartialClone() *ServiceNode {
|
||||||
ServiceMeta: nsmeta,
|
ServiceMeta: nsmeta,
|
||||||
ServiceEnableTagOverride: s.ServiceEnableTagOverride,
|
ServiceEnableTagOverride: s.ServiceEnableTagOverride,
|
||||||
ServiceProxyDestination: s.ServiceProxyDestination,
|
ServiceProxyDestination: s.ServiceProxyDestination,
|
||||||
|
ServiceConnectNative: s.ServiceConnectNative,
|
||||||
RaftIndex: RaftIndex{
|
RaftIndex: RaftIndex{
|
||||||
CreateIndex: s.CreateIndex,
|
CreateIndex: s.CreateIndex,
|
||||||
ModifyIndex: s.ModifyIndex,
|
ModifyIndex: s.ModifyIndex,
|
||||||
|
@ -479,6 +481,7 @@ func (s *ServiceNode) ToNodeService() *NodeService {
|
||||||
Meta: s.ServiceMeta,
|
Meta: s.ServiceMeta,
|
||||||
EnableTagOverride: s.ServiceEnableTagOverride,
|
EnableTagOverride: s.ServiceEnableTagOverride,
|
||||||
ProxyDestination: s.ServiceProxyDestination,
|
ProxyDestination: s.ServiceProxyDestination,
|
||||||
|
ConnectNative: s.ServiceConnectNative,
|
||||||
RaftIndex: RaftIndex{
|
RaftIndex: RaftIndex{
|
||||||
CreateIndex: s.CreateIndex,
|
CreateIndex: s.CreateIndex,
|
||||||
ModifyIndex: s.ModifyIndex,
|
ModifyIndex: s.ModifyIndex,
|
||||||
|
@ -526,6 +529,9 @@ type NodeService struct {
|
||||||
// earlier than their target services.
|
// earlier than their target services.
|
||||||
ProxyDestination string
|
ProxyDestination string
|
||||||
|
|
||||||
|
// ConnectNative is true if this service speaks the Connect protocol.
|
||||||
|
ConnectNative bool
|
||||||
|
|
||||||
RaftIndex
|
RaftIndex
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -567,7 +573,8 @@ func (s *NodeService) IsSame(other *NodeService) bool {
|
||||||
!reflect.DeepEqual(s.Meta, other.Meta) ||
|
!reflect.DeepEqual(s.Meta, other.Meta) ||
|
||||||
s.EnableTagOverride != other.EnableTagOverride ||
|
s.EnableTagOverride != other.EnableTagOverride ||
|
||||||
s.Kind != other.Kind ||
|
s.Kind != other.Kind ||
|
||||||
s.ProxyDestination != other.ProxyDestination {
|
s.ProxyDestination != other.ProxyDestination ||
|
||||||
|
s.ConnectNative != other.ConnectNative {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -590,6 +597,7 @@ func (s *NodeService) ToServiceNode(node string) *ServiceNode {
|
||||||
ServiceMeta: s.Meta,
|
ServiceMeta: s.Meta,
|
||||||
ServiceEnableTagOverride: s.EnableTagOverride,
|
ServiceEnableTagOverride: s.EnableTagOverride,
|
||||||
ServiceProxyDestination: s.ProxyDestination,
|
ServiceProxyDestination: s.ProxyDestination,
|
||||||
|
ServiceConnectNative: s.ConnectNative,
|
||||||
RaftIndex: RaftIndex{
|
RaftIndex: RaftIndex{
|
||||||
CreateIndex: s.CreateIndex,
|
CreateIndex: s.CreateIndex,
|
||||||
ModifyIndex: s.ModifyIndex,
|
ModifyIndex: s.ModifyIndex,
|
||||||
|
|
|
@ -331,6 +331,7 @@ func TestStructs_NodeService_IsSame(t *testing.T) {
|
||||||
check(func() { other.EnableTagOverride = false }, func() { other.EnableTagOverride = true })
|
check(func() { other.EnableTagOverride = false }, func() { other.EnableTagOverride = true })
|
||||||
check(func() { other.Kind = ServiceKindConnectProxy }, func() { other.Kind = "" })
|
check(func() { other.Kind = ServiceKindConnectProxy }, func() { other.Kind = "" })
|
||||||
check(func() { other.ProxyDestination = "" }, func() { other.ProxyDestination = "db" })
|
check(func() { other.ProxyDestination = "" }, func() { other.ProxyDestination = "db" })
|
||||||
|
check(func() { other.ConnectNative = true }, func() { other.ConnectNative = false })
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStructs_HealthCheck_IsSame(t *testing.T) {
|
func TestStructs_HealthCheck_IsSame(t *testing.T) {
|
||||||
|
|
Loading…
Reference in a new issue