@@ -548,7 +548,8 @@ func (ar *allocRunner) handleTaskStateUpdates() {
548
548
549
549
if len (liveRunners ) > 0 {
550
550
// if all live runners are sidecars - kill alloc
551
- if killEvent == nil && hasSidecars && ! hasNonSidecarTasks (liveRunners ) {
551
+ hasLiveSidecars := hasSidecars && ! hasNonSidecarTasks (liveRunners )
552
+ if killEvent == nil && hasLiveSidecars {
552
553
killEvent = structs .NewTaskEvent (structs .TaskMainDead )
553
554
}
554
555
@@ -573,11 +574,11 @@ func (ar *allocRunner) handleTaskStateUpdates() {
573
574
// Kill 'em all
574
575
states = ar .killTasks ()
575
576
576
- // Wait for TaskRunners to exit before continuing to
577
- // prevent looping before TaskRunners have transitioned
578
- // to Dead.
577
+ // Wait for TaskRunners to exit before continuing. This will
578
+ // prevent looping before TaskRunners have transitioned to
579
+ // Dead.
579
580
for _ , tr := range liveRunners {
580
- ar .logger .Info ("killing task" , "task" , tr .Task ().Name )
581
+ ar .logger .Info ("waiting for task to exit " , "task" , tr .Task ().Name )
581
582
select {
582
583
case <- tr .WaitCh ():
583
584
case <- ar .waitCh :
@@ -1228,20 +1229,24 @@ func (ar *allocRunner) GetTaskEventHandler(taskName string) drivermanager.EventH
1228
1229
}
1229
1230
1230
1231
// Restart satisfies the WorkloadRestarter interface and restarts all tasks
1231
- // that are currently running. Only the TaskRestartRunningSignal event type may
1232
- // be used.
1232
+ // that are currently running.
1233
+ //
1234
+ // The event type will be set to TaskRestartRunningSignal to comply with
1235
+ // internal restart logic requirements.
1233
1236
func (ar * allocRunner ) Restart (ctx context.Context , event * structs.TaskEvent , failure bool ) error {
1234
1237
if event .Type != structs .TaskRestartRunningSignal {
1235
- return fmt . Errorf ( "Invalid event %s for alloc restart request" , event . Type )
1238
+ event . Type = structs . TaskRestartRunningSignal
1236
1239
}
1237
1240
return ar .restartTasks (ctx , event , failure )
1238
1241
}
1239
1242
1240
- // RestartTask restarts the provided task. Only TaskRestartSignal event type
1241
- // may be used.
1243
+ // RestartTask restarts the provided task.
1244
+ //
1245
+ // The event type will be set to TaskRestartSignal to comply with internal
1246
+ // restart logic requirements.
1242
1247
func (ar * allocRunner ) RestartTask (taskName string , event * structs.TaskEvent ) error {
1243
1248
if event .Type != structs .TaskRestartSignal {
1244
- return fmt . Errorf ( "Invalid event %s for task restart request" , event . Type )
1249
+ event . Type = structs . TaskRestartSignal
1245
1250
}
1246
1251
1247
1252
tr , ok := ar .tasks [taskName ]
@@ -1252,11 +1257,13 @@ func (ar *allocRunner) RestartTask(taskName string, event *structs.TaskEvent) er
1252
1257
return tr .Restart (context .TODO (), event , false )
1253
1258
}
1254
1259
1255
- // RestartRunning restarts all tasks that are currently running. Only the
1256
- // TaskRestartRunningSignal event type may be used.
1260
+ // RestartRunning restarts all tasks that are currently running.
1261
+ //
1262
+ // The event type will be set to TaskRestartRunningSignal to comply with
1263
+ // internal restart logic requirements.
1257
1264
func (ar * allocRunner ) RestartRunning (event * structs.TaskEvent ) error {
1258
1265
if event .Type != structs .TaskRestartRunningSignal {
1259
- return fmt . Errorf ( "Invalid event %s for running tasks restart request" , event . Type )
1266
+ event . Type = structs . TaskRestartRunningSignal
1260
1267
}
1261
1268
return ar .restartTasks (context .TODO (), event , false )
1262
1269
}
0 commit comments