Skip to content

Commit b6aff48

Browse files
committed
taskDirHook: ensure hooks rerun if task dir is missing
1 parent bc96b7c commit b6aff48

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

client/allocrunner/taskrunner/task_dir_hook.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package taskrunner
55

66
import (
77
"context"
8+
"os"
89
"path/filepath"
910
"strings"
1011

@@ -49,11 +50,18 @@ func (h *taskDirHook) Name() string {
4950
func (h *taskDirHook) Prestart(ctx context.Context, req *interfaces.TaskPrestartRequest, resp *interfaces.TaskPrestartResponse) error {
5051
fsi := h.runner.driverCapabilities.FSIsolation
5152
if v, ok := req.PreviousState[TaskDirHookIsDoneDataKey]; ok && v == "true" {
52-
setEnvvars(h.runner.envBuilder, fsi, h.runner.taskDir, h.runner.clientConfig)
53-
resp.State = map[string]string{
54-
TaskDirHookIsDoneDataKey: "true",
53+
if _, err := os.Stat(h.runner.taskDir.Dir); err == nil {
54+
setEnvvars(h.runner.envBuilder, fsi, h.runner.taskDir, h.runner.clientConfig)
55+
resp.State = map[string]string{
56+
TaskDirHookIsDoneDataKey: "true",
57+
}
58+
return nil
5559
}
56-
return nil
60+
61+
// Previous state indicated that we ran the hooks. However, the expected
62+
// directories are not present. Fallthrough to run the hooks again. This
63+
// can happen when e.g. `client.alloc_dir` is in ephemeral storage and
64+
// the client reboots.
5765
}
5866

5967
cc := h.runner.clientConfig

0 commit comments

Comments
 (0)