Added Missing Service Meta synchronization and field
This commit is contained in:
parent
5d0060a9c3
commit
ee47eb7d7d
|
@ -131,9 +131,18 @@ func (s *HTTPServer) AgentServices(resp http.ResponseWriter, req *http.Request)
|
||||||
|
|
||||||
// Use empty list instead of nil
|
// Use empty list instead of nil
|
||||||
for id, s := range services {
|
for id, s := range services {
|
||||||
if s.Tags == nil {
|
if s.Tags == nil || s.Meta == nil {
|
||||||
clone := *s
|
clone := *s
|
||||||
clone.Tags = make([]string, 0)
|
if s.Tags == nil {
|
||||||
|
clone.Tags = make([]string, 0)
|
||||||
|
} else {
|
||||||
|
clone.Tags = s.Tags
|
||||||
|
}
|
||||||
|
if s.Meta == nil {
|
||||||
|
clone.Meta = make(map[string]string)
|
||||||
|
} else {
|
||||||
|
clone.Meta = s.Meta
|
||||||
|
}
|
||||||
services[id] = &clone
|
services[id] = &clone
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1204,6 +1204,7 @@ func TestAgent_RegisterService(t *testing.T) {
|
||||||
|
|
||||||
args := &structs.ServiceDefinition{
|
args := &structs.ServiceDefinition{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
|
Meta: map[string]string{"hello": "world"},
|
||||||
Tags: []string{"master"},
|
Tags: []string{"master"},
|
||||||
Port: 8000,
|
Port: 8000,
|
||||||
Check: structs.CheckType{
|
Check: structs.CheckType{
|
||||||
|
@ -1232,6 +1233,9 @@ func TestAgent_RegisterService(t *testing.T) {
|
||||||
if _, ok := a.State.Services()["test"]; !ok {
|
if _, ok := a.State.Services()["test"]; !ok {
|
||||||
t.Fatalf("missing test service")
|
t.Fatalf("missing test service")
|
||||||
}
|
}
|
||||||
|
if val := a.State.Service("test").Meta["hello"]; val != "world" {
|
||||||
|
t.Fatalf("Missing meta: %v", a.State.Service("test").Meta)
|
||||||
|
}
|
||||||
|
|
||||||
// Ensure we have a check mapping
|
// Ensure we have a check mapping
|
||||||
checks := a.State.Checks()
|
checks := a.State.Checks()
|
||||||
|
@ -1254,7 +1258,7 @@ func TestAgent_RegisterService_TranslateKeys(t *testing.T) {
|
||||||
a := NewTestAgent(t.Name(), "")
|
a := NewTestAgent(t.Name(), "")
|
||||||
defer a.Shutdown()
|
defer a.Shutdown()
|
||||||
|
|
||||||
json := `{"name":"test", "port":8000, "enable_tag_override": true}`
|
json := `{"name":"test", "port":8000, "enable_tag_override": true, "meta": {"some": "meta"}}`
|
||||||
req, _ := http.NewRequest("PUT", "/v1/agent/service/register", strings.NewReader(json))
|
req, _ := http.NewRequest("PUT", "/v1/agent/service/register", strings.NewReader(json))
|
||||||
|
|
||||||
obj, err := a.srv.AgentRegisterService(nil, req)
|
obj, err := a.srv.AgentRegisterService(nil, req)
|
||||||
|
@ -1264,10 +1268,10 @@ func TestAgent_RegisterService_TranslateKeys(t *testing.T) {
|
||||||
if obj != nil {
|
if obj != nil {
|
||||||
t.Fatalf("bad: %v", obj)
|
t.Fatalf("bad: %v", obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
svc := &structs.NodeService{
|
svc := &structs.NodeService{
|
||||||
ID: "test",
|
ID: "test",
|
||||||
Service: "test",
|
Service: "test",
|
||||||
|
Meta: map[string]string{"some": "meta"},
|
||||||
Port: 8000,
|
Port: 8000,
|
||||||
EnableTagOverride: true,
|
EnableTagOverride: true,
|
||||||
}
|
}
|
||||||
|
|
|
@ -678,6 +678,7 @@ func vetRegisterWithACL(rule acl.ACL, subj *structs.RegisterRequest,
|
||||||
ID: subj.Service.ID,
|
ID: subj.Service.ID,
|
||||||
Service: subj.Service.Service,
|
Service: subj.Service.Service,
|
||||||
Tags: subj.Service.Tags,
|
Tags: subj.Service.Tags,
|
||||||
|
Meta: subj.Service.Meta,
|
||||||
Address: subj.Service.Address,
|
Address: subj.Service.Address,
|
||||||
Port: subj.Service.Port,
|
Port: subj.Service.Port,
|
||||||
EnableTagOverride: subj.Service.EnableTagOverride,
|
EnableTagOverride: subj.Service.EnableTagOverride,
|
||||||
|
|
|
@ -23,6 +23,7 @@ type AgentService struct {
|
||||||
ID string
|
ID string
|
||||||
Service string
|
Service string
|
||||||
Tags []string
|
Tags []string
|
||||||
|
Meta map[string]string
|
||||||
Port int
|
Port int
|
||||||
Address string
|
Address string
|
||||||
EnableTagOverride bool
|
EnableTagOverride bool
|
||||||
|
|
|
@ -73,7 +73,7 @@ func TestAPI_AgentReload(t *testing.T) {
|
||||||
agent := c.Agent()
|
agent := c.Agent()
|
||||||
|
|
||||||
// Update the config file with a service definition
|
// Update the config file with a service definition
|
||||||
config := `{"service":{"name":"redis", "port":1234}}`
|
config := `{"service":{"name":"redis", "port":1234, "Meta": {"some": "meta"}}}`
|
||||||
err = ioutil.WriteFile(configFile.Name(), []byte(config), 0644)
|
err = ioutil.WriteFile(configFile.Name(), []byte(config), 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
|
@ -95,6 +95,9 @@ func TestAPI_AgentReload(t *testing.T) {
|
||||||
if service.Port != 1234 {
|
if service.Port != 1234 {
|
||||||
t.Fatalf("bad: %v", service.Port)
|
t.Fatalf("bad: %v", service.Port)
|
||||||
}
|
}
|
||||||
|
if service.Meta["some"] != "meta" {
|
||||||
|
t.Fatalf("Missing metadata some:=meta in %v", service)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAPI_AgentMembersOpts(t *testing.T) {
|
func TestAPI_AgentMembersOpts(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue