diff --git a/.changelog/26194.txt b/.changelog/26194.txt new file mode 100644 index 000000000..f9910f602 --- /dev/null +++ b/.changelog/26194.txt @@ -0,0 +1,3 @@ +```release-note:bug +client: Attempt to rollback directory creation when the `mkdir` plugin fails to perform ownership changes on it +``` diff --git a/client/hostvolumemanager/host_volume_plugin.go b/client/hostvolumemanager/host_volume_plugin.go index 92473e7f1..8e068d284 100644 --- a/client/hostvolumemanager/host_volume_plugin.go +++ b/client/hostvolumemanager/host_volume_plugin.go @@ -138,6 +138,15 @@ func (p *HostVolumePluginMkdir) Create(_ context.Context, // 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 { 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) }