Making the docker driver register services and checks
This commit is contained in:
parent
f6a932194f
commit
8b91606b22
|
@ -110,12 +110,11 @@ func (c *ConsulService) SyncTask(task *structs.Task) error {
|
|||
services[srv.ID] = srv
|
||||
|
||||
for _, chk := range service.Checks {
|
||||
hash := chk.Hash(service.ID)
|
||||
if _, ok := c.checks[hash]; !ok {
|
||||
if _, ok := c.checks[chk.ID]; !ok {
|
||||
c.registerCheck(chk, srv)
|
||||
}
|
||||
c.checks[hash] = chk
|
||||
checks[hash] = chk
|
||||
c.checks[chk.ID] = chk
|
||||
checks[chk.ID] = chk
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -245,22 +244,6 @@ func (c *ConsulService) performSync() error {
|
|||
}
|
||||
cChecks = c.filterConsulChecks(cChecks)
|
||||
|
||||
// Remove services and checks that consul has but we don't have anymore
|
||||
for serviceID, _ := range cServices {
|
||||
if _, ok := c.services[serviceID]; !ok {
|
||||
if err := c.deregisterService(serviceID); err != nil {
|
||||
mErr.Errors = append(mErr.Errors, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
for checkID, _ := range cChecks {
|
||||
if _, ok := c.checks[checkID]; !ok {
|
||||
if err := c.deregisterCheck(checkID); err != nil {
|
||||
mErr.Errors = append(mErr.Errors, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add services and checks that consul doesn't have but we do
|
||||
for serviceID, service := range c.services {
|
||||
if _, ok := cServices[serviceID]; !ok {
|
||||
|
|
|
@ -643,6 +643,9 @@ func (d *DockerDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle
|
|||
doneCh: make(chan struct{}),
|
||||
waitCh: make(chan *cstructs.WaitResult, 1),
|
||||
}
|
||||
if err := exec.RegisterServices(); err != nil {
|
||||
d.logger.Printf("[ERR] driver.docker: error registering services with consul for task: %v", task)
|
||||
}
|
||||
go h.run()
|
||||
return h, nil
|
||||
}
|
||||
|
@ -828,6 +831,11 @@ func (h *DockerHandle) run() {
|
|||
h.waitCh <- cstructs.NewWaitResult(exitCode, 0, err)
|
||||
close(h.waitCh)
|
||||
|
||||
// Remove services
|
||||
if err := h.executor.DeregisterServices(); err != nil {
|
||||
h.logger.Printf("[ERR] driver.docker: error deregistering services: %v", err)
|
||||
}
|
||||
|
||||
// Shutdown the syslog collector
|
||||
if err := h.executor.Exit(); err != nil {
|
||||
h.logger.Printf("[ERR] driver.docker: failed to kill the syslog collector: %v", err)
|
||||
|
|
|
@ -342,6 +342,7 @@ func (e *UniversalExecutor) ShutDown() error {
|
|||
}
|
||||
|
||||
func (e *UniversalExecutor) RegisterServices() error {
|
||||
e.logger.Printf("registering services")
|
||||
if e.consulService == nil {
|
||||
cs, err := consul.NewConsulService(e.ctx.ConsulConfig, e.logger)
|
||||
if err != nil {
|
||||
|
@ -349,9 +350,9 @@ func (e *UniversalExecutor) RegisterServices() error {
|
|||
}
|
||||
e.consulService = cs
|
||||
}
|
||||
e.consulService.SyncTask(e.ctx.Task)
|
||||
go e.consulService.SyncWithConsul()
|
||||
return nil
|
||||
err := e.consulService.SyncTask(e.ctx.Task)
|
||||
e.logger.Printf("Finished registering services")
|
||||
return err
|
||||
}
|
||||
|
||||
func (e *UniversalExecutor) DeregisterServices() error {
|
||||
|
|
|
@ -120,11 +120,11 @@ func (e *ExecutorRPCServer) UpdateTask(args *structs.Task, resp *interface{}) er
|
|||
return e.Impl.UpdateTask(args)
|
||||
}
|
||||
|
||||
func (e *ExecutorRPCServer) RegisterServices() error {
|
||||
func (e *ExecutorRPCServer) RegisterServices(args interface{}, resp *interface{}) error {
|
||||
return e.Impl.RegisterServices()
|
||||
}
|
||||
|
||||
func (e *ExecutorRPCServer) DeregisterServices() error {
|
||||
func (e *ExecutorRPCServer) DeregisterServices(args interface{}, resp *interface{}) error {
|
||||
return e.Impl.DeregisterServices()
|
||||
}
|
||||
|
||||
|
|
|
@ -1512,11 +1512,13 @@ func (s *Service) InitFields(job string, taskGroup string, task string) {
|
|||
"BASE": fmt.Sprintf("%s-%s-%s", job, taskGroup, task),
|
||||
},
|
||||
)
|
||||
s.ID = fmt.Sprintf("%s-%s", NomadConsulPrefix, s.Hash())
|
||||
|
||||
for _, check := range s.Checks {
|
||||
if check.Name == "" {
|
||||
check.Name = fmt.Sprintf("service: %q check", s.Name)
|
||||
}
|
||||
check.ID = check.Hash(s.ID)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue