mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
client: Remove created directory when mkdir plugin fails to chown. (#26194)
The mkdir plugin creates the directory and then chowns it. In the event the chown command fails, we should attempt to remove the directory. Without this, we leave directories on the client in partial failure situations.
This commit is contained in:
3
.changelog/26194.txt
Normal file
3
.changelog/26194.txt
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
```release-note:bug
|
||||||
|
client: Attempt to rollback directory creation when the `mkdir` plugin fails to perform ownership changes on it
|
||||||
|
```
|
||||||
@@ -138,6 +138,15 @@ func (p *HostVolumePluginMkdir) Create(_ context.Context,
|
|||||||
// Chown note: A uid or gid of -1 means to not change that value.
|
// Chown note: A uid or gid of -1 means to not change that value.
|
||||||
if err = os.Chown(path, params.Uid, params.Gid); err != nil {
|
if err = os.Chown(path, params.Uid, params.Gid); err != nil {
|
||||||
log.Error("error changing owner/group", "error", err, "uid", params.Uid, "gid", params.Gid)
|
log.Error("error changing owner/group", "error", err, "uid", params.Uid, "gid", params.Gid)
|
||||||
|
|
||||||
|
// Failing to change ownership is fatal for this plugin. Since we have
|
||||||
|
// already created the directory, we should attempt to clean it.
|
||||||
|
// Otherwise, the operator must do this manually.
|
||||||
|
if err := os.RemoveAll(path); err != nil {
|
||||||
|
log.Error("failed to remove directory after create failure",
|
||||||
|
"error", err)
|
||||||
|
}
|
||||||
|
|
||||||
return nil, fmt.Errorf("error changing owner/group: %w", err)
|
return nil, fmt.Errorf("error changing owner/group: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user