diff --git a/.changelog/27147.txt b/.changelog/27147.txt new file mode 100644 index 00000000000..25342c1759b --- /dev/null +++ b/.changelog/27147.txt @@ -0,0 +1,3 @@ +```release-note:bug +dynamic host volumes: fix Windows compatibility +``` diff --git a/client/hostvolumemanager/host_volume_plugin.go b/client/hostvolumemanager/host_volume_plugin.go index b9bf6912ce9..a63105d1cc0 100644 --- a/client/hostvolumemanager/host_volume_plugin.go +++ b/client/hostvolumemanager/host_volume_plugin.go @@ -144,18 +144,20 @@ 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) + if params.Uid != -1 || params.Gid != -1 { + 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) } - - return nil, fmt.Errorf("error changing owner/group: %w", err) } log.Debug("plugin ran successfully")