mirror of https://github.com/status-im/consul.git
agent: switch ConnectNative to an embedded struct
This commit is contained in:
parent
1df5d91b39
commit
1830c6b308
|
@ -1536,7 +1536,7 @@ func TestAgent_RegisterService_ConnectNative(t *testing.T) {
|
||||||
Check: structs.CheckType{
|
Check: structs.CheckType{
|
||||||
TTL: 15 * time.Second,
|
TTL: 15 * time.Second,
|
||||||
},
|
},
|
||||||
Connect: &structs.ServiceDefinitionConnect{
|
Connect: &structs.ServiceConnect{
|
||||||
Native: true,
|
Native: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -1550,7 +1550,7 @@ func TestAgent_RegisterService_ConnectNative(t *testing.T) {
|
||||||
// Ensure the service
|
// Ensure the service
|
||||||
svc, ok := a.State.Services()["web"]
|
svc, ok := a.State.Services()["web"]
|
||||||
assert.True(ok, "has service")
|
assert.True(ok, "has service")
|
||||||
assert.True(svc.ConnectNative)
|
assert.True(svc.Connect.Native)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAgent_DeregisterService(t *testing.T) {
|
func TestAgent_DeregisterService(t *testing.T) {
|
||||||
|
@ -2260,7 +2260,7 @@ func TestAgentConnectCALeafCert_aclDefaultDeny(t *testing.T) {
|
||||||
Check: structs.CheckType{
|
Check: structs.CheckType{
|
||||||
TTL: 15 * time.Second,
|
TTL: 15 * time.Second,
|
||||||
},
|
},
|
||||||
Connect: &structs.ServiceDefinitionConnect{
|
Connect: &structs.ServiceConnect{
|
||||||
Proxy: &structs.ServiceDefinitionConnectProxy{},
|
Proxy: &structs.ServiceDefinitionConnectProxy{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -2300,7 +2300,7 @@ func TestAgentConnectCALeafCert_aclProxyToken(t *testing.T) {
|
||||||
Check: structs.CheckType{
|
Check: structs.CheckType{
|
||||||
TTL: 15 * time.Second,
|
TTL: 15 * time.Second,
|
||||||
},
|
},
|
||||||
Connect: &structs.ServiceDefinitionConnect{
|
Connect: &structs.ServiceConnect{
|
||||||
Proxy: &structs.ServiceDefinitionConnectProxy{},
|
Proxy: &structs.ServiceDefinitionConnectProxy{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -2349,7 +2349,7 @@ func TestAgentConnectCALeafCert_aclProxyTokenOther(t *testing.T) {
|
||||||
Check: structs.CheckType{
|
Check: structs.CheckType{
|
||||||
TTL: 15 * time.Second,
|
TTL: 15 * time.Second,
|
||||||
},
|
},
|
||||||
Connect: &structs.ServiceDefinitionConnect{
|
Connect: &structs.ServiceConnect{
|
||||||
Proxy: &structs.ServiceDefinitionConnectProxy{},
|
Proxy: &structs.ServiceDefinitionConnectProxy{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -2371,7 +2371,7 @@ func TestAgentConnectCALeafCert_aclProxyTokenOther(t *testing.T) {
|
||||||
Check: structs.CheckType{
|
Check: structs.CheckType{
|
||||||
TTL: 15 * time.Second,
|
TTL: 15 * time.Second,
|
||||||
},
|
},
|
||||||
Connect: &structs.ServiceDefinitionConnect{
|
Connect: &structs.ServiceConnect{
|
||||||
Proxy: &structs.ServiceDefinitionConnectProxy{},
|
Proxy: &structs.ServiceDefinitionConnectProxy{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -2417,7 +2417,7 @@ func TestAgentConnectCALeafCert_aclServiceWrite(t *testing.T) {
|
||||||
Check: structs.CheckType{
|
Check: structs.CheckType{
|
||||||
TTL: 15 * time.Second,
|
TTL: 15 * time.Second,
|
||||||
},
|
},
|
||||||
Connect: &structs.ServiceDefinitionConnect{
|
Connect: &structs.ServiceConnect{
|
||||||
Proxy: &structs.ServiceDefinitionConnectProxy{},
|
Proxy: &structs.ServiceDefinitionConnectProxy{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -2478,7 +2478,7 @@ func TestAgentConnectCALeafCert_aclServiceReadDeny(t *testing.T) {
|
||||||
Check: structs.CheckType{
|
Check: structs.CheckType{
|
||||||
TTL: 15 * time.Second,
|
TTL: 15 * time.Second,
|
||||||
},
|
},
|
||||||
Connect: &structs.ServiceDefinitionConnect{
|
Connect: &structs.ServiceConnect{
|
||||||
Proxy: &structs.ServiceDefinitionConnectProxy{},
|
Proxy: &structs.ServiceDefinitionConnectProxy{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -2758,7 +2758,7 @@ func TestAgentConnectProxyConfig_Blocking(t *testing.T) {
|
||||||
Check: structs.CheckType{
|
Check: structs.CheckType{
|
||||||
TTL: 15 * time.Second,
|
TTL: 15 * time.Second,
|
||||||
},
|
},
|
||||||
Connect: &structs.ServiceDefinitionConnect{
|
Connect: &structs.ServiceConnect{
|
||||||
Proxy: &structs.ServiceDefinitionConnectProxy{
|
Proxy: &structs.ServiceDefinitionConnectProxy{
|
||||||
Command: []string{"tubes.sh"},
|
Command: []string{"tubes.sh"},
|
||||||
Config: map[string]interface{}{
|
Config: map[string]interface{}{
|
||||||
|
@ -2964,7 +2964,7 @@ func TestAgentConnectProxyConfig_aclDefaultDeny(t *testing.T) {
|
||||||
Check: structs.CheckType{
|
Check: structs.CheckType{
|
||||||
TTL: 15 * time.Second,
|
TTL: 15 * time.Second,
|
||||||
},
|
},
|
||||||
Connect: &structs.ServiceDefinitionConnect{
|
Connect: &structs.ServiceConnect{
|
||||||
Proxy: &structs.ServiceDefinitionConnectProxy{},
|
Proxy: &structs.ServiceDefinitionConnectProxy{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -3003,7 +3003,7 @@ func TestAgentConnectProxyConfig_aclProxyToken(t *testing.T) {
|
||||||
Check: structs.CheckType{
|
Check: structs.CheckType{
|
||||||
TTL: 15 * time.Second,
|
TTL: 15 * time.Second,
|
||||||
},
|
},
|
||||||
Connect: &structs.ServiceDefinitionConnect{
|
Connect: &structs.ServiceConnect{
|
||||||
Proxy: &structs.ServiceDefinitionConnectProxy{},
|
Proxy: &structs.ServiceDefinitionConnectProxy{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -3054,7 +3054,7 @@ func TestAgentConnectProxyConfig_aclServiceWrite(t *testing.T) {
|
||||||
Check: structs.CheckType{
|
Check: structs.CheckType{
|
||||||
TTL: 15 * time.Second,
|
TTL: 15 * time.Second,
|
||||||
},
|
},
|
||||||
Connect: &structs.ServiceDefinitionConnect{
|
Connect: &structs.ServiceConnect{
|
||||||
Proxy: &structs.ServiceDefinitionConnectProxy{},
|
Proxy: &structs.ServiceDefinitionConnectProxy{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -3116,7 +3116,7 @@ func TestAgentConnectProxyConfig_aclServiceReadDeny(t *testing.T) {
|
||||||
Check: structs.CheckType{
|
Check: structs.CheckType{
|
||||||
TTL: 15 * time.Second,
|
TTL: 15 * time.Second,
|
||||||
},
|
},
|
||||||
Connect: &structs.ServiceDefinitionConnect{
|
Connect: &structs.ServiceConnect{
|
||||||
Proxy: &structs.ServiceDefinitionConnectProxy{},
|
Proxy: &structs.ServiceDefinitionConnectProxy{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -3171,7 +3171,7 @@ func TestAgentConnectProxyConfig_ConfigHandling(t *testing.T) {
|
||||||
Check: structs.CheckType{
|
Check: structs.CheckType{
|
||||||
TTL: 15 * time.Second,
|
TTL: 15 * time.Second,
|
||||||
},
|
},
|
||||||
Connect: &structs.ServiceDefinitionConnect{},
|
Connect: &structs.ServiceConnect{},
|
||||||
}
|
}
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
|
|
|
@ -1049,7 +1049,7 @@ func (b *Builder) serviceVal(v *ServiceDefinition) *structs.ServiceDefinition {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Builder) serviceConnectVal(v *ServiceConnect) *structs.ServiceDefinitionConnect {
|
func (b *Builder) serviceConnectVal(v *ServiceConnect) *structs.ServiceConnect {
|
||||||
if v == nil {
|
if v == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -1063,7 +1063,7 @@ func (b *Builder) serviceConnectVal(v *ServiceConnect) *structs.ServiceDefinitio
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return &structs.ServiceDefinitionConnect{
|
return &structs.ServiceConnect{
|
||||||
Proxy: proxy,
|
Proxy: proxy,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2097,7 +2097,7 @@ func TestConfigFlagsAndEdgecases(t *testing.T) {
|
||||||
&structs.ServiceDefinition{
|
&structs.ServiceDefinition{
|
||||||
Name: "web",
|
Name: "web",
|
||||||
Port: 8080,
|
Port: 8080,
|
||||||
Connect: &structs.ServiceDefinitionConnect{
|
Connect: &structs.ServiceConnect{
|
||||||
Proxy: &structs.ServiceDefinitionConnectProxy{
|
Proxy: &structs.ServiceDefinitionConnectProxy{
|
||||||
Config: map[string]interface{}{
|
Config: map[string]interface{}{
|
||||||
"upstreams": []map[string]interface{}{
|
"upstreams": []map[string]interface{}{
|
||||||
|
@ -2141,7 +2141,7 @@ func TestConfigFlagsAndEdgecases(t *testing.T) {
|
||||||
&structs.ServiceDefinition{
|
&structs.ServiceDefinition{
|
||||||
Name: "web",
|
Name: "web",
|
||||||
Port: 8080,
|
Port: 8080,
|
||||||
Connect: &structs.ServiceDefinitionConnect{
|
Connect: &structs.ServiceConnect{
|
||||||
Proxy: &structs.ServiceDefinitionConnectProxy{
|
Proxy: &structs.ServiceDefinitionConnectProxy{
|
||||||
Config: map[string]interface{}{
|
Config: map[string]interface{}{
|
||||||
"upstreams": []interface{}{
|
"upstreams": []interface{}{
|
||||||
|
@ -3699,7 +3699,7 @@ func TestFullConfig(t *testing.T) {
|
||||||
DeregisterCriticalServiceAfter: 68482 * time.Second,
|
DeregisterCriticalServiceAfter: 68482 * time.Second,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Connect: &structs.ServiceDefinitionConnect{
|
Connect: &structs.ServiceConnect{
|
||||||
Proxy: &structs.ServiceDefinitionConnectProxy{
|
Proxy: &structs.ServiceDefinitionConnectProxy{
|
||||||
ExecMode: "daemon",
|
ExecMode: "daemon",
|
||||||
Command: []string{"awesome-proxy"},
|
Command: []string{"awesome-proxy"},
|
||||||
|
|
|
@ -456,7 +456,7 @@ func TestCatalog_Register_ConnectNative(t *testing.T) {
|
||||||
defer codec.Close()
|
defer codec.Close()
|
||||||
|
|
||||||
args := structs.TestRegisterRequest(t)
|
args := structs.TestRegisterRequest(t)
|
||||||
args.Service.ConnectNative = true
|
args.Service.Connect.Native = true
|
||||||
|
|
||||||
// Register
|
// Register
|
||||||
var out struct{}
|
var out struct{}
|
||||||
|
@ -472,7 +472,7 @@ func TestCatalog_Register_ConnectNative(t *testing.T) {
|
||||||
assert.Len(resp.ServiceNodes, 1)
|
assert.Len(resp.ServiceNodes, 1)
|
||||||
v := resp.ServiceNodes[0]
|
v := resp.ServiceNodes[0]
|
||||||
assert.Equal(structs.ServiceKindTypical, v.ServiceKind)
|
assert.Equal(structs.ServiceKindTypical, v.ServiceKind)
|
||||||
assert.True(v.ServiceConnectNative)
|
assert.True(v.ServiceConnect.Native)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCatalog_Deregister(t *testing.T) {
|
func TestCatalog_Deregister(t *testing.T) {
|
||||||
|
@ -1840,7 +1840,7 @@ func TestCatalog_ListServiceNodes_ConnectDestinationNative(t *testing.T) {
|
||||||
|
|
||||||
// Register the native service
|
// Register the native service
|
||||||
args := structs.TestRegisterRequest(t)
|
args := structs.TestRegisterRequest(t)
|
||||||
args.Service.ConnectNative = true
|
args.Service.Connect.Native = true
|
||||||
var out struct{}
|
var out struct{}
|
||||||
require.Nil(msgpackrpc.CallWithCodec(codec, "Catalog.Register", args, &out))
|
require.Nil(msgpackrpc.CallWithCodec(codec, "Catalog.Register", args, &out))
|
||||||
|
|
||||||
|
@ -1965,7 +1965,7 @@ func TestCatalog_ListServiceNodes_ConnectNative(t *testing.T) {
|
||||||
|
|
||||||
// Register the service
|
// Register the service
|
||||||
args := structs.TestRegisterRequest(t)
|
args := structs.TestRegisterRequest(t)
|
||||||
args.Service.ConnectNative = true
|
args.Service.Connect.Native = true
|
||||||
var out struct{}
|
var out struct{}
|
||||||
assert.Nil(msgpackrpc.CallWithCodec(codec, "Catalog.Register", args, &out))
|
assert.Nil(msgpackrpc.CallWithCodec(codec, "Catalog.Register", args, &out))
|
||||||
|
|
||||||
|
@ -1979,7 +1979,7 @@ func TestCatalog_ListServiceNodes_ConnectNative(t *testing.T) {
|
||||||
assert.Nil(msgpackrpc.CallWithCodec(codec, "Catalog.ServiceNodes", &req, &resp))
|
assert.Nil(msgpackrpc.CallWithCodec(codec, "Catalog.ServiceNodes", &req, &resp))
|
||||||
assert.Len(resp.ServiceNodes, 1)
|
assert.Len(resp.ServiceNodes, 1)
|
||||||
v := resp.ServiceNodes[0]
|
v := resp.ServiceNodes[0]
|
||||||
assert.Equal(args.Service.ConnectNative, v.ServiceConnectNative)
|
assert.Equal(args.Service.Connect.Native, v.ServiceConnect.Native)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCatalog_NodeServices(t *testing.T) {
|
func TestCatalog_NodeServices(t *testing.T) {
|
||||||
|
@ -2090,7 +2090,7 @@ func TestCatalog_NodeServices_ConnectNative(t *testing.T) {
|
||||||
|
|
||||||
assert.Len(resp.NodeServices.Services, 1)
|
assert.Len(resp.NodeServices.Services, 1)
|
||||||
v := resp.NodeServices.Services[args.Service.Service]
|
v := resp.NodeServices.Services[args.Service.Service]
|
||||||
assert.Equal(args.Service.ConnectNative, v.ConnectNative)
|
assert.Equal(args.Service.Connect.Native, v.Connect.Native)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Used to check for a regression against a known bug
|
// Used to check for a regression against a known bug
|
||||||
|
|
|
@ -1590,7 +1590,7 @@ func TestStateStore_ConnectServiceNodes(t *testing.T) {
|
||||||
assert.Nil(s.EnsureService(13, "bar", &structs.NodeService{ID: "api", Service: "api", Tags: nil, Address: "", Port: 5000}))
|
assert.Nil(s.EnsureService(13, "bar", &structs.NodeService{ID: "api", Service: "api", Tags: nil, Address: "", Port: 5000}))
|
||||||
assert.Nil(s.EnsureService(14, "foo", &structs.NodeService{Kind: structs.ServiceKindConnectProxy, ID: "proxy", Service: "proxy", ProxyDestination: "db", Port: 8000}))
|
assert.Nil(s.EnsureService(14, "foo", &structs.NodeService{Kind: structs.ServiceKindConnectProxy, ID: "proxy", Service: "proxy", ProxyDestination: "db", Port: 8000}))
|
||||||
assert.Nil(s.EnsureService(15, "bar", &structs.NodeService{Kind: structs.ServiceKindConnectProxy, ID: "proxy", Service: "proxy", ProxyDestination: "db", Port: 8000}))
|
assert.Nil(s.EnsureService(15, "bar", &structs.NodeService{Kind: structs.ServiceKindConnectProxy, ID: "proxy", Service: "proxy", ProxyDestination: "db", Port: 8000}))
|
||||||
assert.Nil(s.EnsureService(16, "bar", &structs.NodeService{ID: "native-db", Service: "db", ConnectNative: true}))
|
assert.Nil(s.EnsureService(16, "bar", &structs.NodeService{ID: "native-db", Service: "db", Connect: structs.ServiceConnect{Native: true}}))
|
||||||
assert.Nil(s.EnsureService(17, "bar", &structs.NodeService{ID: "db2", Service: "db", Tags: []string{"slave"}, Address: "", Port: 8001}))
|
assert.Nil(s.EnsureService(17, "bar", &structs.NodeService{ID: "db2", Service: "db", Tags: []string{"slave"}, Address: "", Port: 8001}))
|
||||||
assert.True(watchFired(ws))
|
assert.True(watchFired(ws))
|
||||||
|
|
||||||
|
@ -1604,7 +1604,7 @@ func TestStateStore_ConnectServiceNodes(t *testing.T) {
|
||||||
for _, n := range nodes {
|
for _, n := range nodes {
|
||||||
assert.True(
|
assert.True(
|
||||||
n.ServiceKind == structs.ServiceKindConnectProxy ||
|
n.ServiceKind == structs.ServiceKindConnectProxy ||
|
||||||
n.ServiceConnectNative,
|
n.ServiceConnect.Native,
|
||||||
"either proxy or connect native")
|
"either proxy or connect native")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ func (idx *IndexConnectService) FromObject(obj interface{}) (bool, []byte, error
|
||||||
// For proxies, this service supports Connect for the destination
|
// For proxies, this service supports Connect for the destination
|
||||||
result = []byte(strings.ToLower(sn.ServiceProxyDestination))
|
result = []byte(strings.ToLower(sn.ServiceProxyDestination))
|
||||||
|
|
||||||
case sn.ServiceConnectNative:
|
case sn.ServiceConnect.Native:
|
||||||
// For native, this service supports Connect directly
|
// For native, this service supports Connect directly
|
||||||
result = []byte(strings.ToLower(sn.ServiceName))
|
result = []byte(strings.ToLower(sn.ServiceName))
|
||||||
|
|
||||||
|
|
|
@ -36,8 +36,8 @@ func TestIndexConnectService_FromObject(t *testing.T) {
|
||||||
{
|
{
|
||||||
"typical service, is native",
|
"typical service, is native",
|
||||||
&structs.ServiceNode{
|
&structs.ServiceNode{
|
||||||
ServiceName: "dB",
|
ServiceName: "dB",
|
||||||
ServiceConnectNative: true,
|
ServiceConnect: structs.ServiceConnect{Native: true},
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
[]byte("db\x00"),
|
[]byte("db\x00"),
|
||||||
|
|
|
@ -21,7 +21,7 @@ type ServiceDefinition struct {
|
||||||
Token string
|
Token string
|
||||||
EnableTagOverride bool
|
EnableTagOverride bool
|
||||||
ProxyDestination string
|
ProxyDestination string
|
||||||
Connect *ServiceDefinitionConnect
|
Connect *ServiceConnect
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ServiceDefinition) NodeService() *NodeService {
|
func (s *ServiceDefinition) NodeService() *NodeService {
|
||||||
|
@ -37,7 +37,7 @@ func (s *ServiceDefinition) NodeService() *NodeService {
|
||||||
ProxyDestination: s.ProxyDestination,
|
ProxyDestination: s.ProxyDestination,
|
||||||
}
|
}
|
||||||
if s.Connect != nil {
|
if s.Connect != nil {
|
||||||
ns.ConnectNative = s.Connect.Native
|
ns.Connect = *s.Connect
|
||||||
}
|
}
|
||||||
if ns.ID == "" && ns.Service != "" {
|
if ns.ID == "" && ns.Service != "" {
|
||||||
ns.ID = ns.Service
|
ns.ID = ns.Service
|
||||||
|
@ -126,17 +126,6 @@ func (s *ServiceDefinition) CheckTypes() (checks CheckTypes, err error) {
|
||||||
return checks, nil
|
return checks, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServiceDefinitionConnect is the connect block within a service registration.
|
|
||||||
// Note this is duplicated in config.ServiceConnect and needs to be kept in
|
|
||||||
// sync.
|
|
||||||
type ServiceDefinitionConnect struct {
|
|
||||||
// Native is true when this service can natively understand Connect.
|
|
||||||
Native bool
|
|
||||||
|
|
||||||
// Proxy configures a connect proxy instance for the service
|
|
||||||
Proxy *ServiceDefinitionConnectProxy
|
|
||||||
}
|
|
||||||
|
|
||||||
// ServiceDefinitionConnectProxy is the connect proxy config within a service
|
// ServiceDefinitionConnectProxy is the connect proxy config within a service
|
||||||
// registration. Note this is duplicated in config.ServiceConnectProxy and needs
|
// registration. Note this is duplicated in config.ServiceConnectProxy and needs
|
||||||
// to be kept in sync.
|
// to be kept in sync.
|
||||||
|
|
|
@ -73,7 +73,7 @@ func TestServiceDefinitionValidate(t *testing.T) {
|
||||||
"managed proxy with a port set",
|
"managed proxy with a port set",
|
||||||
func(x *ServiceDefinition) {
|
func(x *ServiceDefinition) {
|
||||||
x.Port = 8080
|
x.Port = 8080
|
||||||
x.Connect = &ServiceDefinitionConnect{
|
x.Connect = &ServiceConnect{
|
||||||
Proxy: &ServiceDefinitionConnectProxy{},
|
Proxy: &ServiceDefinitionConnectProxy{},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -83,7 +83,7 @@ func TestServiceDefinitionValidate(t *testing.T) {
|
||||||
{
|
{
|
||||||
"managed proxy with no port set",
|
"managed proxy with no port set",
|
||||||
func(x *ServiceDefinition) {
|
func(x *ServiceDefinition) {
|
||||||
x.Connect = &ServiceDefinitionConnect{
|
x.Connect = &ServiceConnect{
|
||||||
Proxy: &ServiceDefinitionConnectProxy{},
|
Proxy: &ServiceDefinitionConnectProxy{},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -94,7 +94,7 @@ func TestServiceDefinitionValidate(t *testing.T) {
|
||||||
"managed proxy with native set",
|
"managed proxy with native set",
|
||||||
func(x *ServiceDefinition) {
|
func(x *ServiceDefinition) {
|
||||||
x.Port = 8080
|
x.Port = 8080
|
||||||
x.Connect = &ServiceDefinitionConnect{
|
x.Connect = &ServiceConnect{
|
||||||
Native: true,
|
Native: true,
|
||||||
Proxy: &ServiceDefinitionConnectProxy{},
|
Proxy: &ServiceDefinitionConnectProxy{},
|
||||||
}
|
}
|
||||||
|
|
|
@ -432,7 +432,7 @@ type ServiceNode struct {
|
||||||
ServicePort int
|
ServicePort int
|
||||||
ServiceEnableTagOverride bool
|
ServiceEnableTagOverride bool
|
||||||
ServiceProxyDestination string
|
ServiceProxyDestination string
|
||||||
ServiceConnectNative bool
|
ServiceConnect ServiceConnect
|
||||||
|
|
||||||
RaftIndex
|
RaftIndex
|
||||||
}
|
}
|
||||||
|
@ -461,7 +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,
|
ServiceConnect: s.ServiceConnect,
|
||||||
RaftIndex: RaftIndex{
|
RaftIndex: RaftIndex{
|
||||||
CreateIndex: s.CreateIndex,
|
CreateIndex: s.CreateIndex,
|
||||||
ModifyIndex: s.ModifyIndex,
|
ModifyIndex: s.ModifyIndex,
|
||||||
|
@ -481,7 +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,
|
Connect: s.ServiceConnect,
|
||||||
RaftIndex: RaftIndex{
|
RaftIndex: RaftIndex{
|
||||||
CreateIndex: s.CreateIndex,
|
CreateIndex: s.CreateIndex,
|
||||||
ModifyIndex: s.ModifyIndex,
|
ModifyIndex: s.ModifyIndex,
|
||||||
|
@ -529,12 +529,25 @@ 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.
|
// Connect are the Connect settings for a service. This is purposely NOT
|
||||||
ConnectNative bool
|
// a pointer so that we never have to nil-check this.
|
||||||
|
Connect ServiceConnect
|
||||||
|
|
||||||
RaftIndex
|
RaftIndex
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ServiceConnect are the shared Connect settings between all service
|
||||||
|
// definitions from the agent to the state store.
|
||||||
|
type ServiceConnect struct {
|
||||||
|
// Native is true when this service can natively understand Connect.
|
||||||
|
Native bool
|
||||||
|
|
||||||
|
// Proxy configures a connect proxy instance for the service. This is
|
||||||
|
// only used for agent service definitions and is invalid for non-agent
|
||||||
|
// (catalog API) definitions.
|
||||||
|
Proxy *ServiceDefinitionConnectProxy
|
||||||
|
}
|
||||||
|
|
||||||
// Validate validates the node service configuration.
|
// Validate validates the node service configuration.
|
||||||
//
|
//
|
||||||
// NOTE(mitchellh): This currently only validates fields for a ConnectProxy.
|
// NOTE(mitchellh): This currently only validates fields for a ConnectProxy.
|
||||||
|
@ -556,7 +569,7 @@ func (s *NodeService) Validate() error {
|
||||||
"Port must be set for a Connect proxy"))
|
"Port must be set for a Connect proxy"))
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.ConnectNative {
|
if s.Connect.Native {
|
||||||
result = multierror.Append(result, fmt.Errorf(
|
result = multierror.Append(result, fmt.Errorf(
|
||||||
"A Proxy cannot also be ConnectNative, only typical services"))
|
"A Proxy cannot also be ConnectNative, only typical services"))
|
||||||
}
|
}
|
||||||
|
@ -579,7 +592,7 @@ func (s *NodeService) IsSame(other *NodeService) bool {
|
||||||
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 {
|
s.Connect != other.Connect {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -602,7 +615,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,
|
ServiceConnect: s.Connect,
|
||||||
RaftIndex: RaftIndex{
|
RaftIndex: RaftIndex{
|
||||||
CreateIndex: s.CreateIndex,
|
CreateIndex: s.CreateIndex,
|
||||||
ModifyIndex: s.ModifyIndex,
|
ModifyIndex: s.ModifyIndex,
|
||||||
|
|
|
@ -249,7 +249,7 @@ func TestStructs_NodeService_ValidateConnectProxy(t *testing.T) {
|
||||||
|
|
||||||
{
|
{
|
||||||
"connect-proxy: ConnectNative set",
|
"connect-proxy: ConnectNative set",
|
||||||
func(x *NodeService) { x.ConnectNative = true },
|
func(x *NodeService) { x.Connect.Native = true },
|
||||||
"cannot also be",
|
"cannot also be",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -337,7 +337,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 })
|
check(func() { other.Connect.Native = true }, func() { other.Connect.Native = false })
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStructs_HealthCheck_IsSame(t *testing.T) {
|
func TestStructs_HealthCheck_IsSame(t *testing.T) {
|
||||||
|
|
|
@ -54,7 +54,7 @@ The table below shows this endpoint's support for
|
||||||
- `Service` `(Service: nil)` - Specifies to register a service. If `ID` is not
|
- `Service` `(Service: nil)` - Specifies to register a service. If `ID` is not
|
||||||
provided, it will be defaulted to the value of the `Service.Service` property.
|
provided, it will be defaulted to the value of the `Service.Service` property.
|
||||||
Only one service with a given `ID` may be present per node. The service
|
Only one service with a given `ID` may be present per node. The service
|
||||||
`Tags`, `Address`, `ServiceMeta`, `Port`, `ConnectNative` fields are all optional.
|
`Tags`, `Address`, `ServiceMeta`, and `Port` fields are all optional.
|
||||||
|
|
||||||
- `Check` `(Check: nil)` - Specifies to register a check. The register API
|
- `Check` `(Check: nil)` - Specifies to register a check. The register API
|
||||||
manipulates the health check entry in the Catalog, but it does not setup the
|
manipulates the health check entry in the Catalog, but it does not setup the
|
||||||
|
@ -485,8 +485,8 @@ $ curl \
|
||||||
- `ServiceProxyDestination` is the name of the service that is being proxied,
|
- `ServiceProxyDestination` is the name of the service that is being proxied,
|
||||||
for "connect-proxy" type services.
|
for "connect-proxy" type services.
|
||||||
|
|
||||||
- `ServiceConnectNative` is true if this service supports Connect
|
- `ServiceConnect` are the [Connect](/docs/connect/index.html) settings. The
|
||||||
[natively](/docs/connect/native.html).
|
value of this struct is equivalent to the `Connect` field for service registration.
|
||||||
|
|
||||||
## List Nodes for Connect-capable Service
|
## List Nodes for Connect-capable Service
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue