Skip to content

Commit 5282e74

Browse files
committed
dynamic host volumes: fix Windows compatibility
1 parent 9db0938 commit 5282e74

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

.changelog/27147.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
dynamic host volumes: fix Windows compatibility
3+
```

client/hostvolumemanager/host_volume_plugin.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -144,18 +144,20 @@ func (p *HostVolumePluginMkdir) Create(_ context.Context,
144144
}
145145

146146
// Chown note: A uid or gid of -1 means to not change that value.
147-
if err = os.Chown(path, params.Uid, params.Gid); err != nil {
148-
log.Error("error changing owner/group", "error", err, "uid", params.Uid, "gid", params.Gid)
149-
150-
// Failing to change ownership is fatal for this plugin. Since we have
151-
// already created the directory, we should attempt to clean it.
152-
// Otherwise, the operator must do this manually.
153-
if err := os.RemoveAll(path); err != nil {
154-
log.Error("failed to remove directory after create failure",
155-
"error", err)
147+
if params.Uid != -1 || params.Gid != -1 {
148+
if err = os.Chown(path, params.Uid, params.Gid); err != nil {
149+
log.Error("error changing owner/group", "error", err, "uid", params.Uid, "gid", params.Gid)
150+
151+
// Failing to change ownership is fatal for this plugin. Since we have
152+
// already created the directory, we should attempt to clean it.
153+
// Otherwise, the operator must do this manually.
154+
if err := os.RemoveAll(path); err != nil {
155+
log.Error("failed to remove directory after create failure",
156+
"error", err)
157+
}
158+
159+
return nil, fmt.Errorf("error changing owner/group: %w", err)
156160
}
157-
158-
return nil, fmt.Errorf("error changing owner/group: %w", err)
159161
}
160162

161163
log.Debug("plugin ran successfully")

0 commit comments

Comments
 (0)