Skip to content

Commit 12b344a

Browse files
author
Kubernetes Submit Queue
authored
Merge pull request kubernetes#39768 from rkouj/check-path-exists
Automatic merge from submit-queue (batch tested with PRs 39768, 39463) Check if path exists before performing unmount This is part 3 of an effort to check if path exists before performing an unmount operation. [Part 1](kubernetes#38547) and [part 2](kubernetes#39311) involved auditing the different volume plugins and refactoring their `TearDownAt()s` to use the common util function/or create one if absent. The ideal way to do this change would involve refactoring of the `TearDownAt()s` of these plugins and make a common util function that checks path. (The plugins involved in this PR use someway of unmounting a bind mount and unmounting a global path, there is also refactoring needed to consolidate disk_manager of fc, rbd and iscsi). A non-goal part of this effort can also involve refactoring all the `SetupAt()s` In the interest of time and considering other higher priority issues that I am caught up with, I am unable to give the time the refactoring needs. Hence I've made the minimum change that would give the desired output. I am tracking the work pending in this issue: kubernetes#39251 ```release-note NONE ```
2 parents 9d8eb29 + 32766e3 commit 12b344a

File tree

9 files changed

+76
-23
lines changed

9 files changed

+76
-23
lines changed

pkg/volume/azure_dd/azure_dd.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"k8s.io/kubernetes/pkg/util/mount"
3535
utilstrings "k8s.io/kubernetes/pkg/util/strings"
3636
"k8s.io/kubernetes/pkg/volume"
37+
"k8s.io/kubernetes/pkg/volume/util"
3738
)
3839

3940
// This is the primary entrypoint for volume plugins.
@@ -316,6 +317,13 @@ func (c *azureDiskUnmounter) TearDown() error {
316317
// Unmounts the bind mount, and detaches the disk only if the PD
317318
// resource was the last reference to that disk on the kubelet.
318319
func (c *azureDiskUnmounter) TearDownAt(dir string) error {
320+
if pathExists, pathErr := util.PathExists(dir); pathErr != nil {
321+
return fmt.Errorf("Error checking if path exists: %v", pathErr)
322+
} else if !pathExists {
323+
glog.Warningf("Warning: Unmount skipped because path does not exist: %v", dir)
324+
return nil
325+
}
326+
319327
notMnt, err := c.mounter.IsLikelyNotMountPoint(dir)
320328
if err != nil {
321329
glog.Errorf("Error checking if mountpoint %s: %v", dir, err)

pkg/volume/cinder/cinder.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"k8s.io/kubernetes/pkg/util/mount"
3535
"k8s.io/kubernetes/pkg/util/strings"
3636
"k8s.io/kubernetes/pkg/volume"
37+
"k8s.io/kubernetes/pkg/volume/util"
3738
)
3839

3940
// This is the primary entrypoint for volume plugins.
@@ -386,6 +387,13 @@ func (c *cinderVolumeUnmounter) TearDown() error {
386387
// Unmounts the bind mount, and detaches the disk only if the PD
387388
// resource was the last reference to that disk on the kubelet.
388389
func (c *cinderVolumeUnmounter) TearDownAt(dir string) error {
390+
if pathExists, pathErr := util.PathExists(dir); pathErr != nil {
391+
return fmt.Errorf("Error checking if path exists: %v", pathErr)
392+
} else if !pathExists {
393+
glog.Warningf("Warning: Unmount skipped because path does not exist: %v", dir)
394+
return nil
395+
}
396+
389397
glog.V(5).Infof("Cinder TearDown of %s", dir)
390398
notmnt, err := c.mounter.IsLikelyNotMountPoint(dir)
391399
if err != nil {

pkg/volume/fc/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ go_library(
2323
"//pkg/util/mount:go_default_library",
2424
"//pkg/util/strings:go_default_library",
2525
"//pkg/volume:go_default_library",
26+
"//pkg/volume/util:go_default_library",
2627
"//vendor:github.com/golang/glog",
2728
"//vendor:k8s.io/apimachinery/pkg/types",
2829
],

pkg/volume/fc/fc.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"k8s.io/kubernetes/pkg/util/mount"
2828
"k8s.io/kubernetes/pkg/util/strings"
2929
"k8s.io/kubernetes/pkg/volume"
30+
"k8s.io/kubernetes/pkg/volume/util"
3031
)
3132

3233
// This is the primary entrypoint for volume plugins.
@@ -222,6 +223,12 @@ func (c *fcDiskUnmounter) TearDown() error {
222223
}
223224

224225
func (c *fcDiskUnmounter) TearDownAt(dir string) error {
226+
if pathExists, pathErr := util.PathExists(dir); pathErr != nil {
227+
return fmt.Errorf("Error checking if path exists: %v", pathErr)
228+
} else if !pathExists {
229+
glog.Warningf("Warning: Unmount skipped because path does not exist: %v", dir)
230+
return nil
231+
}
225232
return diskTearDown(c.manager, *c, dir, c.mounter)
226233
}
227234

pkg/volume/flexvolume/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ go_library(
2121
"//pkg/util/mount:go_default_library",
2222
"//pkg/util/strings:go_default_library",
2323
"//pkg/volume:go_default_library",
24+
"//pkg/volume/util:go_default_library",
2425
"//vendor:github.com/golang/glog",
2526
"//vendor:k8s.io/apimachinery/pkg/apis/meta/v1",
2627
"//vendor:k8s.io/apimachinery/pkg/types",

pkg/volume/flexvolume/flexvolume.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"k8s.io/kubernetes/pkg/util/mount"
3333
utilstrings "k8s.io/kubernetes/pkg/util/strings"
3434
"k8s.io/kubernetes/pkg/volume"
35+
"k8s.io/kubernetes/pkg/volume/util"
3536
)
3637

3738
// This is the primary entrypoint for volume plugins.
@@ -371,6 +372,12 @@ func (f *flexVolumeUnmounter) TearDown() error {
371372

372373
// TearDownAt simply deletes everything in the directory.
373374
func (f *flexVolumeUnmounter) TearDownAt(dir string) error {
375+
if pathExists, pathErr := util.PathExists(dir); pathErr != nil {
376+
return fmt.Errorf("Error checking if path exists: %v", pathErr)
377+
} else if !pathExists {
378+
glog.Warningf("Warning: Unmount skipped because path does not exist: %v", dir)
379+
return nil
380+
}
374381

375382
notmnt, err := f.mounter.IsLikelyNotMountPoint(dir)
376383
if err != nil {

pkg/volume/iscsi/iscsi.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,12 @@ func (c *iscsiDiskUnmounter) TearDown() error {
230230
}
231231

232232
func (c *iscsiDiskUnmounter) TearDownAt(dir string) error {
233+
if pathExists, pathErr := ioutil.PathExists(dir); pathErr != nil {
234+
return fmt.Errorf("Error checking if path exists: %v", pathErr)
235+
} else if !pathExists {
236+
glog.Warningf("Warning: Unmount skipped because path does not exist: %v", dir)
237+
return nil
238+
}
233239
return diskTearDown(c.manager, *c, dir, c.mounter)
234240
}
235241

pkg/volume/rbd/rbd.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,12 @@ func (c *rbdUnmounter) TearDown() error {
413413
}
414414

415415
func (c *rbdUnmounter) TearDownAt(dir string) error {
416+
if pathExists, pathErr := volutil.PathExists(dir); pathErr != nil {
417+
return fmt.Errorf("Error checking if path exists: %v", pathErr)
418+
} else if !pathExists {
419+
glog.Warningf("Warning: Unmount skipped because path does not exist: %v", dir)
420+
return nil
421+
}
416422
return diskTearDown(c.manager, *c, dir, c.mounter)
417423
}
418424

0 commit comments

Comments
 (0)