mirror of https://github.com/status-im/consul.git
agent: Support multiple tags per service registration
This commit is contained in:
parent
7f399a0ecc
commit
8db2e3bd58
|
@ -19,7 +19,7 @@ func TestHTTPAgentServices(t *testing.T) {
|
|||
srv1 := &structs.NodeService{
|
||||
ID: "mysql",
|
||||
Service: "mysql",
|
||||
Tag: "master",
|
||||
Tags: []string{"master"},
|
||||
Port: 5000,
|
||||
}
|
||||
srv.agent.state.AddService(srv1)
|
||||
|
@ -394,7 +394,7 @@ func TestHTTPAgentRegisterService(t *testing.T) {
|
|||
}
|
||||
args := &ServiceDefinition{
|
||||
Name: "test",
|
||||
Tag: "master",
|
||||
Tags: []string{"master"},
|
||||
Port: 8000,
|
||||
Check: CheckType{
|
||||
TTL: 15 * time.Second,
|
||||
|
|
|
@ -108,7 +108,7 @@ func TestAgent_AddService(t *testing.T) {
|
|||
srv := &structs.NodeService{
|
||||
ID: "redis",
|
||||
Service: "redis",
|
||||
Tag: "foo",
|
||||
Tags: []string{"foo"},
|
||||
Port: 8000,
|
||||
}
|
||||
chk := &CheckType{TTL: time.Minute}
|
||||
|
|
|
@ -249,7 +249,7 @@ func TestCatalogServiceNodes(t *testing.T) {
|
|||
Address: "127.0.0.1",
|
||||
Service: &structs.NodeService{
|
||||
Service: "api",
|
||||
Tag: "a",
|
||||
Tags: []string{"a"},
|
||||
},
|
||||
}
|
||||
var out struct{}
|
||||
|
@ -293,7 +293,7 @@ func TestCatalogNodeServices(t *testing.T) {
|
|||
Address: "127.0.0.1",
|
||||
Service: &structs.NodeService{
|
||||
Service: "api",
|
||||
Tag: "a",
|
||||
Tags: []string{"a"},
|
||||
},
|
||||
}
|
||||
var out struct{}
|
||||
|
|
|
@ -197,7 +197,7 @@ func TestDecodeConfig(t *testing.T) {
|
|||
|
||||
func TestDecodeConfig_Service(t *testing.T) {
|
||||
// Basics
|
||||
input := `{"service": {"id": "red1", "name": "redis", "tag": "master", "port":8000, "check": {"script": "/bin/check_redis", "interval": "10s", "ttl": "15s" }}}`
|
||||
input := `{"service": {"id": "red1", "name": "redis", "tags": ["master"], "port":8000, "check": {"script": "/bin/check_redis", "interval": "10s", "ttl": "15s" }}}`
|
||||
config, err := DecodeConfig(bytes.NewReader([]byte(input)))
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
|
@ -216,7 +216,7 @@ func TestDecodeConfig_Service(t *testing.T) {
|
|||
t.Fatalf("bad: %v", serv)
|
||||
}
|
||||
|
||||
if serv.Tag != "master" {
|
||||
if !strContains(serv.Tags, "master") {
|
||||
t.Fatalf("bad: %v", serv)
|
||||
}
|
||||
|
||||
|
|
|
@ -219,7 +219,7 @@ func TestDNS_ServiceLookup(t *testing.T) {
|
|||
Address: "127.0.0.1",
|
||||
Service: &structs.NodeService{
|
||||
Service: "db",
|
||||
Tag: "master",
|
||||
Tags: []string{"master"},
|
||||
Port: 12345,
|
||||
},
|
||||
}
|
||||
|
@ -279,7 +279,7 @@ func TestDNS_ServiceLookup_Dedup(t *testing.T) {
|
|||
Address: "127.0.0.1",
|
||||
Service: &structs.NodeService{
|
||||
Service: "db",
|
||||
Tag: "master",
|
||||
Tags: []string{"master"},
|
||||
Port: 12345,
|
||||
},
|
||||
}
|
||||
|
@ -295,7 +295,7 @@ func TestDNS_ServiceLookup_Dedup(t *testing.T) {
|
|||
Service: &structs.NodeService{
|
||||
ID: "db2",
|
||||
Service: "db",
|
||||
Tag: "slave",
|
||||
Tags: []string{"slave"},
|
||||
Port: 12345,
|
||||
},
|
||||
}
|
||||
|
@ -310,7 +310,7 @@ func TestDNS_ServiceLookup_Dedup(t *testing.T) {
|
|||
Service: &structs.NodeService{
|
||||
ID: "db3",
|
||||
Service: "db",
|
||||
Tag: "slave",
|
||||
Tags: []string{"slave"},
|
||||
Port: 12346,
|
||||
},
|
||||
}
|
||||
|
@ -355,7 +355,7 @@ func TestDNS_ServiceLookup_Dedup_SRV(t *testing.T) {
|
|||
Address: "127.0.0.1",
|
||||
Service: &structs.NodeService{
|
||||
Service: "db",
|
||||
Tag: "master",
|
||||
Tags: []string{"master"},
|
||||
Port: 12345,
|
||||
},
|
||||
}
|
||||
|
@ -371,7 +371,7 @@ func TestDNS_ServiceLookup_Dedup_SRV(t *testing.T) {
|
|||
Service: &structs.NodeService{
|
||||
ID: "db2",
|
||||
Service: "db",
|
||||
Tag: "slave",
|
||||
Tags: []string{"slave"},
|
||||
Port: 12345,
|
||||
},
|
||||
}
|
||||
|
@ -386,7 +386,7 @@ func TestDNS_ServiceLookup_Dedup_SRV(t *testing.T) {
|
|||
Service: &structs.NodeService{
|
||||
ID: "db3",
|
||||
Service: "db",
|
||||
Tag: "slave",
|
||||
Tags: []string{"slave"},
|
||||
Port: 12346,
|
||||
},
|
||||
}
|
||||
|
@ -482,7 +482,7 @@ func TestDNS_ServiceLookup_FilterCritical(t *testing.T) {
|
|||
Address: "127.0.0.1",
|
||||
Service: &structs.NodeService{
|
||||
Service: "db",
|
||||
Tag: "master",
|
||||
Tags: []string{"master"},
|
||||
Port: 12345,
|
||||
},
|
||||
Check: &structs.HealthCheck{
|
||||
|
@ -502,7 +502,7 @@ func TestDNS_ServiceLookup_FilterCritical(t *testing.T) {
|
|||
Address: "127.0.0.2",
|
||||
Service: &structs.NodeService{
|
||||
Service: "db",
|
||||
Tag: "master",
|
||||
Tags: []string{"master"},
|
||||
Port: 12345,
|
||||
},
|
||||
Check: &structs.HealthCheck{
|
||||
|
|
|
@ -29,7 +29,7 @@ func TestAgentAntiEntropy_Services(t *testing.T) {
|
|||
srv1 := &structs.NodeService{
|
||||
ID: "mysql",
|
||||
Service: "mysql",
|
||||
Tag: "master",
|
||||
Tags: []string{"master"},
|
||||
Port: 5000,
|
||||
}
|
||||
agent.state.AddService(srv1)
|
||||
|
@ -42,7 +42,7 @@ func TestAgentAntiEntropy_Services(t *testing.T) {
|
|||
srv2 := &structs.NodeService{
|
||||
ID: "redis",
|
||||
Service: "redis",
|
||||
Tag: "",
|
||||
Tags: nil,
|
||||
Port: 8000,
|
||||
}
|
||||
agent.state.AddService(srv2)
|
||||
|
@ -59,7 +59,7 @@ func TestAgentAntiEntropy_Services(t *testing.T) {
|
|||
srv3 := &structs.NodeService{
|
||||
ID: "web",
|
||||
Service: "web",
|
||||
Tag: "",
|
||||
Tags: nil,
|
||||
Port: 80,
|
||||
}
|
||||
agent.state.AddService(srv3)
|
||||
|
@ -68,7 +68,7 @@ func TestAgentAntiEntropy_Services(t *testing.T) {
|
|||
srv4 := &structs.NodeService{
|
||||
ID: "lb",
|
||||
Service: "lb",
|
||||
Tag: "",
|
||||
Tags: nil,
|
||||
Port: 443,
|
||||
}
|
||||
args.Service = srv4
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
type ServiceDefinition struct {
|
||||
ID string
|
||||
Name string
|
||||
Tag string
|
||||
Tags []string
|
||||
Port int
|
||||
Check CheckType
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ func (s *ServiceDefinition) NodeService() *structs.NodeService {
|
|||
ns := &structs.NodeService{
|
||||
ID: s.ID,
|
||||
Service: s.Name,
|
||||
Tag: s.Tag,
|
||||
Tags: s.Tags,
|
||||
Port: s.Port,
|
||||
}
|
||||
if ns.ID == "" && ns.Service != "" {
|
||||
|
|
|
@ -29,3 +29,13 @@ func aeScale(interval time.Duration, n int) time.Duration {
|
|||
func randomStagger(intv time.Duration) time.Duration {
|
||||
return time.Duration(uint64(rand.Int63()) % uint64(intv))
|
||||
}
|
||||
|
||||
// strContains checks if a list contains a string
|
||||
func strContains(l []string, s string) bool {
|
||||
for _, v := range l {
|
||||
if v == s {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue