clean up consul earlier when destroying a task

This commit is contained in:
Pete Wildsmith
2017-04-27 23:27:58 +01:00
parent fcbaf69702
commit 06f3aac9de

View File

@@ -918,6 +918,7 @@ func (r *TaskRunner) run() {
select {
case success := <-prestartResultCh:
if !success {
r.consulCleanup()
r.cleanup()
r.setState(structs.TaskStateDead, nil)
return
@@ -1025,6 +1026,11 @@ func (r *TaskRunner) run() {
r.runningLock.Lock()
running := r.running
r.runningLock.Unlock()
// Remove from consul before killing the task so that traffic
// can be rerouted
r.consulCleanup()
if !running {
r.cleanup()
r.setState(structs.TaskStateDead, r.destroyEvent)
@@ -1059,6 +1065,7 @@ func (r *TaskRunner) run() {
// shouldRestart will block if the task should restart after a delay.
restart := r.shouldRestart()
if !restart {
r.consulCleanup()
r.cleanup()
r.setState(structs.TaskStateDead, nil)
return
@@ -1073,12 +1080,14 @@ func (r *TaskRunner) run() {
}
}
// cleanup removes Consul entries and calls Driver.Cleanup when a task is
// stopping. Errors are logged.
func (r *TaskRunner) cleanup() {
func (r *TaskRunner) consulCleanup() {
// Remove from Consul
r.consul.RemoveTask(r.alloc.ID, r.task)
}
// cleanup calls Driver.Cleanup when a task is
// stopping. Errors are logged.
func (r *TaskRunner) cleanup() {
drv, err := r.createDriver()
if err != nil {
r.logger.Printf("[ERR] client: error creating driver to cleanup resources: %v", err)