agent/consul/state: service registration with proxy works

This commit is contained in:
Mitchell Hashimoto 2018-03-05 19:56:52 -08:00
parent 23ee0888ec
commit 09568ce7b5
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
2 changed files with 62 additions and 0 deletions

View File

@ -981,6 +981,40 @@ func TestStateStore_EnsureService(t *testing.T) {
} }
} }
func TestStateStore_EnsureService_connectProxy(t *testing.T) {
s := testStateStore(t)
// Create the service registration.
ns1 := &structs.NodeService{
Kind: structs.ServiceKindConnectProxy,
ID: "connect-proxy",
Service: "connect-proxy",
Address: "1.1.1.1",
Port: 1111,
ProxyDestination: "foo",
}
// Service successfully registers into the state store.
testRegisterNode(t, s, 0, "node1")
if err := s.EnsureService(10, "node1", ns1); err != nil {
t.Fatalf("err: %s", err)
}
// Retrieve and verify
_, out, err := s.NodeServices(nil, "node1")
if err != nil {
t.Fatalf("err: %s", err)
}
if out == nil || len(out.Services) != 1 {
t.Fatalf("bad: %#v", out)
}
expect1 := *ns1
expect1.CreateIndex, expect1.ModifyIndex = 10, 10
if svc := out.Services["connect-proxy"]; !reflect.DeepEqual(&expect1, svc) {
t.Fatalf("bad: %#v", svc)
}
}
func TestStateStore_Services(t *testing.T) { func TestStateStore_Services(t *testing.T) {
s := testStateStore(t) s := testStateStore(t)

View File

@ -388,6 +388,7 @@ type ServiceNode struct {
Datacenter string Datacenter string
TaggedAddresses map[string]string TaggedAddresses map[string]string
NodeMeta map[string]string NodeMeta map[string]string
ServiceKind ServiceKind
ServiceID string ServiceID string
ServiceName string ServiceName string
ServiceTags []string ServiceTags []string
@ -395,6 +396,7 @@ type ServiceNode struct {
ServiceMeta map[string]string ServiceMeta map[string]string
ServicePort int ServicePort int
ServiceEnableTagOverride bool ServiceEnableTagOverride bool
ServiceProxyDestination string
RaftIndex RaftIndex
} }
@ -431,6 +433,7 @@ func (s *ServiceNode) PartialClone() *ServiceNode {
// ToNodeService converts the given service node to a node service. // ToNodeService converts the given service node to a node service.
func (s *ServiceNode) ToNodeService() *NodeService { func (s *ServiceNode) ToNodeService() *NodeService {
return &NodeService{ return &NodeService{
Kind: s.ServiceKind,
ID: s.ServiceID, ID: s.ServiceID,
Service: s.ServiceName, Service: s.ServiceName,
Tags: s.ServiceTags, Tags: s.ServiceTags,
@ -438,6 +441,7 @@ func (s *ServiceNode) ToNodeService() *NodeService {
Port: s.ServicePort, Port: s.ServicePort,
Meta: s.ServiceMeta, Meta: s.ServiceMeta,
EnableTagOverride: s.ServiceEnableTagOverride, EnableTagOverride: s.ServiceEnableTagOverride,
ProxyDestination: s.ServiceProxyDestination,
RaftIndex: RaftIndex{ RaftIndex: RaftIndex{
CreateIndex: s.CreateIndex, CreateIndex: s.CreateIndex,
ModifyIndex: s.ModifyIndex, ModifyIndex: s.ModifyIndex,
@ -447,8 +451,26 @@ func (s *ServiceNode) ToNodeService() *NodeService {
type ServiceNodes []*ServiceNode type ServiceNodes []*ServiceNode
// ServiceKind is the kind of service being registered.
type ServiceKind string
const (
// ServiceKindTypical is a typical, classic Consul service.
ServiceKindTypical ServiceKind = "typical"
// ServiceKindConnectProxy is a proxy for the Connect feature. This
// service proxies another service within Consul and speaks the connect
// protocol.
ServiceKindConnectProxy ServiceKind = "connect-proxy"
)
// NodeService is a service provided by a node // NodeService is a service provided by a node
type NodeService struct { type NodeService struct {
// Kind is the kind of service this is. Different kinds of services may
// have differing validation, DNS behavior, etc. An empty kind will default
// to the Default kind. See ServiceKind for the full list of kinds.
Kind ServiceKind
ID string ID string
Service string Service string
Tags []string Tags []string
@ -457,6 +479,10 @@ type NodeService struct {
Port int Port int
EnableTagOverride bool EnableTagOverride bool
// ProxyDestination is the name of the service that this service is
// a Connect proxy for. This is only valid if Kind is "connect-proxy".
ProxyDestination string
RaftIndex RaftIndex
} }
@ -485,6 +511,7 @@ func (s *NodeService) ToServiceNode(node string) *ServiceNode {
Node: node, Node: node,
// Skip Address, see ServiceNode definition. // Skip Address, see ServiceNode definition.
// Skip TaggedAddresses, see ServiceNode definition. // Skip TaggedAddresses, see ServiceNode definition.
ServiceKind: s.Kind,
ServiceID: s.ID, ServiceID: s.ID,
ServiceName: s.Service, ServiceName: s.Service,
ServiceTags: s.Tags, ServiceTags: s.Tags,
@ -492,6 +519,7 @@ func (s *NodeService) ToServiceNode(node string) *ServiceNode {
ServicePort: s.Port, ServicePort: s.Port,
ServiceMeta: s.Meta, ServiceMeta: s.Meta,
ServiceEnableTagOverride: s.EnableTagOverride, ServiceEnableTagOverride: s.EnableTagOverride,
ServiceProxyDestination: s.ProxyDestination,
RaftIndex: RaftIndex{ RaftIndex: RaftIndex{
CreateIndex: s.CreateIndex, CreateIndex: s.CreateIndex,
ModifyIndex: s.ModifyIndex, ModifyIndex: s.ModifyIndex,