mirror of https://github.com/status-im/consul.git
Adds support for EnableTagOverride to the API client.
This commit is contained in:
parent
0562b95a55
commit
afdeb2f1fc
26
api/agent.go
26
api/agent.go
|
@ -18,11 +18,12 @@ type AgentCheck struct {
|
|||
|
||||
// AgentService represents a service known to the agent
|
||||
type AgentService struct {
|
||||
ID string
|
||||
Service string
|
||||
Tags []string
|
||||
Port int
|
||||
Address string
|
||||
ID string
|
||||
Service string
|
||||
Tags []string
|
||||
Port int
|
||||
Address string
|
||||
EnableTagOverride bool
|
||||
}
|
||||
|
||||
// AgentMember represents a cluster member known to the agent
|
||||
|
@ -42,13 +43,14 @@ type AgentMember struct {
|
|||
|
||||
// AgentServiceRegistration is used to register a new service
|
||||
type AgentServiceRegistration struct {
|
||||
ID string `json:",omitempty"`
|
||||
Name string `json:",omitempty"`
|
||||
Tags []string `json:",omitempty"`
|
||||
Port int `json:",omitempty"`
|
||||
Address string `json:",omitempty"`
|
||||
Check *AgentServiceCheck
|
||||
Checks AgentServiceChecks
|
||||
ID string `json:",omitempty"`
|
||||
Name string `json:",omitempty"`
|
||||
Tags []string `json:",omitempty"`
|
||||
Port int `json:",omitempty"`
|
||||
Address string `json:",omitempty"`
|
||||
EnableTagOverride bool `json:",omitempty"`
|
||||
Check *AgentServiceCheck
|
||||
Checks AgentServiceChecks
|
||||
}
|
||||
|
||||
// AgentCheckRegistration is used to register a new check
|
||||
|
|
|
@ -196,6 +196,49 @@ func TestAgent_ServiceAddress(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestAgent_EnableTagOverride(t *testing.T) {
|
||||
t.Parallel()
|
||||
c, s := makeClient(t)
|
||||
defer s.Stop()
|
||||
|
||||
agent := c.Agent()
|
||||
|
||||
reg1 := &AgentServiceRegistration{
|
||||
Name: "foo1",
|
||||
Port: 8000,
|
||||
Address: "192.168.0.42",
|
||||
EnableTagOverride: true,
|
||||
}
|
||||
reg2 := &AgentServiceRegistration{
|
||||
Name: "foo2",
|
||||
Port: 8000,
|
||||
}
|
||||
if err := agent.ServiceRegister(reg1); err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
if err := agent.ServiceRegister(reg2); err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
services, err := agent.Services()
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
if _, ok := services["foo1"]; !ok {
|
||||
t.Fatalf("missing service: %v", services)
|
||||
}
|
||||
if services["foo1"].EnableTagOverride != true {
|
||||
t.Fatalf("tag override not set on service foo1: %v", services)
|
||||
}
|
||||
if _, ok := services["foo2"]; !ok {
|
||||
t.Fatalf("missing service: %v", services)
|
||||
}
|
||||
if services["foo2"].EnableTagOverride != false {
|
||||
t.Fatalf("tag override set on service foo2: %v", services)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAgent_Services_MultipleChecks(t *testing.T) {
|
||||
t.Parallel()
|
||||
c, s := makeClient(t)
|
||||
|
|
|
@ -6,13 +6,14 @@ type Node struct {
|
|||
}
|
||||
|
||||
type CatalogService struct {
|
||||
Node string
|
||||
Address string
|
||||
ServiceID string
|
||||
ServiceName string
|
||||
ServiceAddress string
|
||||
ServiceTags []string
|
||||
ServicePort int
|
||||
Node string
|
||||
Address string
|
||||
ServiceID string
|
||||
ServiceName string
|
||||
ServiceAddress string
|
||||
ServiceTags []string
|
||||
ServicePort int
|
||||
ServiceEnableTagOverride bool
|
||||
}
|
||||
|
||||
type CatalogNode struct {
|
||||
|
|
|
@ -277,3 +277,94 @@ func TestCatalog_Registration(t *testing.T) {
|
|||
t.Fatalf("err: %s", err)
|
||||
})
|
||||
}
|
||||
|
||||
func TestCatalog_EnableTagOverride(t *testing.T) {
|
||||
t.Parallel()
|
||||
c, s := makeClient(t)
|
||||
defer s.Stop()
|
||||
|
||||
catalog := c.Catalog()
|
||||
|
||||
service := &AgentService{
|
||||
ID: "redis1",
|
||||
Service: "redis",
|
||||
Tags: []string{"master", "v1"},
|
||||
Port: 8000,
|
||||
}
|
||||
|
||||
reg := &CatalogRegistration{
|
||||
Datacenter: "dc1",
|
||||
Node: "foobar",
|
||||
Address: "192.168.10.10",
|
||||
Service: service,
|
||||
}
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if _, err := catalog.Register(reg, nil); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
node, _, err := catalog.Node("foobar", nil)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
if _, ok := node.Services["redis1"]; !ok {
|
||||
return false, fmt.Errorf("missing service: redis1")
|
||||
}
|
||||
if node.Services["redis1"].EnableTagOverride != false {
|
||||
return false, fmt.Errorf("tag override set")
|
||||
}
|
||||
|
||||
services, _, err := catalog.Service("redis", "", nil)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
if len(services) < 1 || services[0].ServiceName != "redis" {
|
||||
return false, fmt.Errorf("missing service: redis")
|
||||
}
|
||||
if services[0].ServiceEnableTagOverride != false {
|
||||
return false, fmt.Errorf("tag override set")
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %s", err)
|
||||
})
|
||||
|
||||
service.EnableTagOverride = true
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if _, err := catalog.Register(reg, nil); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
node, _, err := catalog.Node("foobar", nil)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
if _, ok := node.Services["redis1"]; !ok {
|
||||
return false, fmt.Errorf("missing service: redis1")
|
||||
}
|
||||
if node.Services["redis1"].EnableTagOverride != true {
|
||||
return false, fmt.Errorf("tag override not set")
|
||||
}
|
||||
|
||||
services, _, err := catalog.Service("redis", "", nil)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
if len(services) < 1 || services[0].ServiceName != "redis" {
|
||||
return false, fmt.Errorf("missing service: redis")
|
||||
}
|
||||
if services[0].ServiceEnableTagOverride != true {
|
||||
return false, fmt.Errorf("tag override not set")
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %s", err)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue