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
|
||||
for id, s := range services {
|
||||
if s.Tags == nil {
|
||||
if s.Tags == nil || s.Meta == nil {
|
||||
clone := *s
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1204,6 +1204,7 @@ func TestAgent_RegisterService(t *testing.T) {
|
|||
|
||||
args := &structs.ServiceDefinition{
|
||||
Name: "test",
|
||||
Meta: map[string]string{"hello": "world"},
|
||||
Tags: []string{"master"},
|
||||
Port: 8000,
|
||||
Check: structs.CheckType{
|
||||
|
@ -1232,6 +1233,9 @@ func TestAgent_RegisterService(t *testing.T) {
|
|||
if _, ok := a.State.Services()["test"]; !ok {
|
||||
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
|
||||
checks := a.State.Checks()
|
||||
|
@ -1254,7 +1258,7 @@ func TestAgent_RegisterService_TranslateKeys(t *testing.T) {
|
|||
a := NewTestAgent(t.Name(), "")
|
||||
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))
|
||||
|
||||
obj, err := a.srv.AgentRegisterService(nil, req)
|
||||
|
@ -1264,10 +1268,10 @@ func TestAgent_RegisterService_TranslateKeys(t *testing.T) {
|
|||
if obj != nil {
|
||||
t.Fatalf("bad: %v", obj)
|
||||
}
|
||||
|
||||
svc := &structs.NodeService{
|
||||
ID: "test",
|
||||
Service: "test",
|
||||
Meta: map[string]string{"some": "meta"},
|
||||
Port: 8000,
|
||||
EnableTagOverride: true,
|
||||
}
|
||||
|
|
|
@ -678,6 +678,7 @@ func vetRegisterWithACL(rule acl.ACL, subj *structs.RegisterRequest,
|
|||
ID: subj.Service.ID,
|
||||
Service: subj.Service.Service,
|
||||
Tags: subj.Service.Tags,
|
||||
Meta: subj.Service.Meta,
|
||||
Address: subj.Service.Address,
|
||||
Port: subj.Service.Port,
|
||||
EnableTagOverride: subj.Service.EnableTagOverride,
|
||||
|
|
|
@ -23,6 +23,7 @@ type AgentService struct {
|
|||
ID string
|
||||
Service string
|
||||
Tags []string
|
||||
Meta map[string]string
|
||||
Port int
|
||||
Address string
|
||||
EnableTagOverride bool
|
||||
|
|
|
@ -73,7 +73,7 @@ func TestAPI_AgentReload(t *testing.T) {
|
|||
agent := c.Agent()
|
||||
|
||||
// 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)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
|
@ -95,6 +95,9 @@ func TestAPI_AgentReload(t *testing.T) {
|
|||
if service.Port != 1234 {
|
||||
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) {
|
||||
|
|
Loading…
Reference in New Issue