address comments
This commit is contained in:
parent
8bbf4a55e5
commit
4b04e503f3
|
@ -1351,19 +1351,19 @@ func (c *Client) setupConsulSyncer() error {
|
|||
domains[1] = consul.ClientDomain
|
||||
|
||||
for allocID, ar := range c.getAllocRunners() {
|
||||
if ar.Alloc().TerminalStatus() {
|
||||
// Ignore non-running allocations
|
||||
continue
|
||||
ar.taskStatusLock.RLock()
|
||||
taskStates := copyTaskStates(ar.taskStates)
|
||||
ar.taskStatusLock.RUnlock()
|
||||
for taskName, taskState := range taskStates {
|
||||
// Only keep running tasks
|
||||
if taskState.State == structs.TaskStateRunning {
|
||||
d := consul.NewExecutorDomain(allocID, taskName)
|
||||
domains = append(domains, d)
|
||||
}
|
||||
}
|
||||
ar.taskLock.RLock()
|
||||
for task := range ar.tasks {
|
||||
d := consul.NewExecutorDomain(allocID, task)
|
||||
domains = append(domains, d)
|
||||
}
|
||||
ar.taskLock.RUnlock()
|
||||
}
|
||||
|
||||
return c.consulSyncer.KeepDomains(domains)
|
||||
return c.consulSyncer.ReapUnmatched(domains)
|
||||
}
|
||||
c.consulSyncer.AddPeriodicHandler("Nomad Client Services Sync Handler", consulServicesReaperFn)
|
||||
|
||||
|
|
|
@ -363,16 +363,15 @@ func (e *UniversalExecutor) UpdateTask(task *structs.Task) error {
|
|||
if e.consulSyncer != nil {
|
||||
e.interpolateServices(e.ctx.Task)
|
||||
domain := consul.NewExecutorDomain(e.ctx.AllocID, task.Name)
|
||||
serviceMap := servicesToServiceMap(e.ctx.AllocID, task.Services)
|
||||
serviceMap := generateServiceKeys(e.ctx.AllocID, task.Services)
|
||||
e.consulSyncer.SetServices(domain, serviceMap)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// servicesToServiceMap takes a list of interpolated services and returns a map
|
||||
// of ServiceKeys to services where the service key is appropriate for the
|
||||
// executor.
|
||||
func servicesToServiceMap(allocID string, services []*structs.Service) map[consul.ServiceKey]*structs.Service {
|
||||
// generateServiceKeys takes a list of interpolated Nomad Services and returns a map
|
||||
// of ServiceKeys to Nomad Services.
|
||||
func generateServiceKeys(allocID string, services []*structs.Service) map[consul.ServiceKey]*structs.Service {
|
||||
keys := make(map[consul.ServiceKey]*structs.Service, len(services))
|
||||
for _, service := range services {
|
||||
key := consul.GenerateServiceKey(service)
|
||||
|
@ -505,7 +504,7 @@ func (e *UniversalExecutor) SyncServices(ctx *ConsulContext) error {
|
|||
e.consulSyncer.SetDelegatedChecks(e.createCheckMap(), e.createCheck)
|
||||
e.consulSyncer.SetAddrFinder(e.ctx.Task.FindHostAndPortFor)
|
||||
domain := consul.NewExecutorDomain(e.ctx.AllocID, e.ctx.Task.Name)
|
||||
serviceMap := servicesToServiceMap(e.ctx.AllocID, e.ctx.Task.Services)
|
||||
serviceMap := generateServiceKeys(e.ctx.AllocID, e.ctx.Task.Services)
|
||||
e.consulSyncer.SetServices(domain, serviceMap)
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -412,7 +412,7 @@ func (a *Agent) setupClient() error {
|
|||
}
|
||||
a.client = client
|
||||
|
||||
// Create the Nomad Server services for Consul
|
||||
// Create the Nomad Client services for Consul
|
||||
if a.config.Consul.AutoRegister && a.config.Consul.ClientServiceName != "" {
|
||||
httpServ := &structs.Service{
|
||||
Name: a.config.Consul.ClientServiceName,
|
||||
|
|
|
@ -54,7 +54,7 @@ const (
|
|||
|
||||
// nomadServicePrefix is the first prefix that scopes all Nomad registered
|
||||
// services
|
||||
nomadServicePrefix = "nomad-registered-service"
|
||||
nomadServicePrefix = "_nomad"
|
||||
|
||||
// The periodic time interval for syncing services and checks with Consul
|
||||
syncInterval = 5 * time.Second
|
||||
|
@ -953,8 +953,8 @@ func (c *Syncer) runCheck(check Check) {
|
|||
}
|
||||
}
|
||||
|
||||
// KeepDomains prunes all services that do not exist in the passed domains
|
||||
func (c *Syncer) KeepDomains(domains []ServiceDomain) error {
|
||||
// ReapUnmatched prunes all services that do not exist in the passed domains
|
||||
func (c *Syncer) ReapUnmatched(domains []ServiceDomain) error {
|
||||
servicesInConsul, err := c.ConsulClient().Agent().Services()
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
Loading…
Reference in a new issue