From 45da80bde253963ea844f661d4edd7cefa40ddeb Mon Sep 17 00:00:00 2001 From: Seth Hoenig Date: Thu, 6 Jun 2024 10:47:23 -0500 Subject: [PATCH] client: cleanup empty task directory when using unveil filesystem isolation (#23237) This PR fixes a bug where Nomad client would leave behind an empty directory created on behalf of tasks making use of the unveil filesystem isolation mode (i.e. using exec2 task driver). Once unmounting is complete, we should remember to also delete the directory. Fixes #22433 --- .changelog/23237.txt | 3 +++ client/allocdir/task_dir.go | 8 ++++++++ 2 files changed, 11 insertions(+) create mode 100644 .changelog/23237.txt diff --git a/.changelog/23237.txt b/.changelog/23237.txt new file mode 100644 index 000000000..20649614f --- /dev/null +++ b/.changelog/23237.txt @@ -0,0 +1,3 @@ +```release-note:bug +client: Fixed a bug where empty task directories would be left behind +``` diff --git a/client/allocdir/task_dir.go b/client/allocdir/task_dir.go index 2d2fca001..14146552f 100644 --- a/client/allocdir/task_dir.go +++ b/client/allocdir/task_dir.go @@ -349,6 +349,14 @@ func (t *TaskDir) Unmount() error { } } + // delete the task's parent alloc mounts dir if it exists + if dir := filepath.Dir(t.MountsAllocDir); pathExists(dir) { + if err := os.RemoveAll(dir); err != nil { + mErr.Errors = append(mErr.Errors, + fmt.Errorf("failed to remove the task alloc mounts dir %q: %w", dir, err)) + } + } + if pathExists(t.SecretsDir) { if err := removeSecretDir(t.SecretsDir); err != nil { mErr = multierror.Append(mErr,