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
This commit is contained in:
Seth Hoenig
2024-06-06 10:47:23 -05:00
committed by GitHub
parent 71fd5c2474
commit 45da80bde2
2 changed files with 11 additions and 0 deletions

3
.changelog/23237.txt Normal file
View File

@@ -0,0 +1,3 @@
```release-note:bug
client: Fixed a bug where empty task directories would be left behind
```

View File

@@ -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,