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