Commit 12b344aa authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #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](https://github.com/kubernetes/kubernetes/pull/38547) and [part 2](https://github.com/kubernetes/kubernetes/pull/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: https://github.com/kubernetes/kubernetes/issues/39251 ```release-note NONE ```
parents 9d8eb299 32766e3b
...@@ -34,6 +34,7 @@ import ( ...@@ -34,6 +34,7 @@ import (
"k8s.io/kubernetes/pkg/util/mount" "k8s.io/kubernetes/pkg/util/mount"
utilstrings "k8s.io/kubernetes/pkg/util/strings" utilstrings "k8s.io/kubernetes/pkg/util/strings"
"k8s.io/kubernetes/pkg/volume" "k8s.io/kubernetes/pkg/volume"
"k8s.io/kubernetes/pkg/volume/util"
) )
// This is the primary entrypoint for volume plugins. // This is the primary entrypoint for volume plugins.
...@@ -316,6 +317,13 @@ func (c *azureDiskUnmounter) TearDown() error { ...@@ -316,6 +317,13 @@ func (c *azureDiskUnmounter) TearDown() error {
// Unmounts the bind mount, and detaches the disk only if the PD // Unmounts the bind mount, and detaches the disk only if the PD
// resource was the last reference to that disk on the kubelet. // resource was the last reference to that disk on the kubelet.
func (c *azureDiskUnmounter) TearDownAt(dir string) error { func (c *azureDiskUnmounter) TearDownAt(dir string) error {
if pathExists, pathErr := util.PathExists(dir); pathErr != nil {
return fmt.Errorf("Error checking if path exists: %v", pathErr)
} else if !pathExists {
glog.Warningf("Warning: Unmount skipped because path does not exist: %v", dir)
return nil
}
notMnt, err := c.mounter.IsLikelyNotMountPoint(dir) notMnt, err := c.mounter.IsLikelyNotMountPoint(dir)
if err != nil { if err != nil {
glog.Errorf("Error checking if mountpoint %s: %v", dir, err) glog.Errorf("Error checking if mountpoint %s: %v", dir, err)
......
...@@ -34,6 +34,7 @@ import ( ...@@ -34,6 +34,7 @@ import (
"k8s.io/kubernetes/pkg/util/mount" "k8s.io/kubernetes/pkg/util/mount"
"k8s.io/kubernetes/pkg/util/strings" "k8s.io/kubernetes/pkg/util/strings"
"k8s.io/kubernetes/pkg/volume" "k8s.io/kubernetes/pkg/volume"
"k8s.io/kubernetes/pkg/volume/util"
) )
// This is the primary entrypoint for volume plugins. // This is the primary entrypoint for volume plugins.
...@@ -386,6 +387,13 @@ func (c *cinderVolumeUnmounter) TearDown() error { ...@@ -386,6 +387,13 @@ func (c *cinderVolumeUnmounter) TearDown() error {
// Unmounts the bind mount, and detaches the disk only if the PD // Unmounts the bind mount, and detaches the disk only if the PD
// resource was the last reference to that disk on the kubelet. // resource was the last reference to that disk on the kubelet.
func (c *cinderVolumeUnmounter) TearDownAt(dir string) error { func (c *cinderVolumeUnmounter) TearDownAt(dir string) error {
if pathExists, pathErr := util.PathExists(dir); pathErr != nil {
return fmt.Errorf("Error checking if path exists: %v", pathErr)
} else if !pathExists {
glog.Warningf("Warning: Unmount skipped because path does not exist: %v", dir)
return nil
}
glog.V(5).Infof("Cinder TearDown of %s", dir) glog.V(5).Infof("Cinder TearDown of %s", dir)
notmnt, err := c.mounter.IsLikelyNotMountPoint(dir) notmnt, err := c.mounter.IsLikelyNotMountPoint(dir)
if err != nil { if err != nil {
......
...@@ -23,6 +23,7 @@ go_library( ...@@ -23,6 +23,7 @@ go_library(
"//pkg/util/mount:go_default_library", "//pkg/util/mount:go_default_library",
"//pkg/util/strings:go_default_library", "//pkg/util/strings:go_default_library",
"//pkg/volume:go_default_library", "//pkg/volume:go_default_library",
"//pkg/volume/util:go_default_library",
"//vendor:github.com/golang/glog", "//vendor:github.com/golang/glog",
"//vendor:k8s.io/apimachinery/pkg/types", "//vendor:k8s.io/apimachinery/pkg/types",
], ],
......
...@@ -27,6 +27,7 @@ import ( ...@@ -27,6 +27,7 @@ import (
"k8s.io/kubernetes/pkg/util/mount" "k8s.io/kubernetes/pkg/util/mount"
"k8s.io/kubernetes/pkg/util/strings" "k8s.io/kubernetes/pkg/util/strings"
"k8s.io/kubernetes/pkg/volume" "k8s.io/kubernetes/pkg/volume"
"k8s.io/kubernetes/pkg/volume/util"
) )
// This is the primary entrypoint for volume plugins. // This is the primary entrypoint for volume plugins.
...@@ -222,6 +223,12 @@ func (c *fcDiskUnmounter) TearDown() error { ...@@ -222,6 +223,12 @@ func (c *fcDiskUnmounter) TearDown() error {
} }
func (c *fcDiskUnmounter) TearDownAt(dir string) error { func (c *fcDiskUnmounter) TearDownAt(dir string) error {
if pathExists, pathErr := util.PathExists(dir); pathErr != nil {
return fmt.Errorf("Error checking if path exists: %v", pathErr)
} else if !pathExists {
glog.Warningf("Warning: Unmount skipped because path does not exist: %v", dir)
return nil
}
return diskTearDown(c.manager, *c, dir, c.mounter) return diskTearDown(c.manager, *c, dir, c.mounter)
} }
......
...@@ -21,6 +21,7 @@ go_library( ...@@ -21,6 +21,7 @@ go_library(
"//pkg/util/mount:go_default_library", "//pkg/util/mount:go_default_library",
"//pkg/util/strings:go_default_library", "//pkg/util/strings:go_default_library",
"//pkg/volume:go_default_library", "//pkg/volume:go_default_library",
"//pkg/volume/util:go_default_library",
"//vendor:github.com/golang/glog", "//vendor:github.com/golang/glog",
"//vendor:k8s.io/apimachinery/pkg/apis/meta/v1", "//vendor:k8s.io/apimachinery/pkg/apis/meta/v1",
"//vendor:k8s.io/apimachinery/pkg/types", "//vendor:k8s.io/apimachinery/pkg/types",
......
...@@ -32,6 +32,7 @@ import ( ...@@ -32,6 +32,7 @@ import (
"k8s.io/kubernetes/pkg/util/mount" "k8s.io/kubernetes/pkg/util/mount"
utilstrings "k8s.io/kubernetes/pkg/util/strings" utilstrings "k8s.io/kubernetes/pkg/util/strings"
"k8s.io/kubernetes/pkg/volume" "k8s.io/kubernetes/pkg/volume"
"k8s.io/kubernetes/pkg/volume/util"
) )
// This is the primary entrypoint for volume plugins. // This is the primary entrypoint for volume plugins.
...@@ -371,6 +372,12 @@ func (f *flexVolumeUnmounter) TearDown() error { ...@@ -371,6 +372,12 @@ func (f *flexVolumeUnmounter) TearDown() error {
// TearDownAt simply deletes everything in the directory. // TearDownAt simply deletes everything in the directory.
func (f *flexVolumeUnmounter) TearDownAt(dir string) error { func (f *flexVolumeUnmounter) TearDownAt(dir string) error {
if pathExists, pathErr := util.PathExists(dir); pathErr != nil {
return fmt.Errorf("Error checking if path exists: %v", pathErr)
} else if !pathExists {
glog.Warningf("Warning: Unmount skipped because path does not exist: %v", dir)
return nil
}
notmnt, err := f.mounter.IsLikelyNotMountPoint(dir) notmnt, err := f.mounter.IsLikelyNotMountPoint(dir)
if err != nil { if err != nil {
......
...@@ -230,6 +230,12 @@ func (c *iscsiDiskUnmounter) TearDown() error { ...@@ -230,6 +230,12 @@ func (c *iscsiDiskUnmounter) TearDown() error {
} }
func (c *iscsiDiskUnmounter) TearDownAt(dir string) error { func (c *iscsiDiskUnmounter) TearDownAt(dir string) error {
if pathExists, pathErr := ioutil.PathExists(dir); pathErr != nil {
return fmt.Errorf("Error checking if path exists: %v", pathErr)
} else if !pathExists {
glog.Warningf("Warning: Unmount skipped because path does not exist: %v", dir)
return nil
}
return diskTearDown(c.manager, *c, dir, c.mounter) return diskTearDown(c.manager, *c, dir, c.mounter)
} }
......
...@@ -413,6 +413,12 @@ func (c *rbdUnmounter) TearDown() error { ...@@ -413,6 +413,12 @@ func (c *rbdUnmounter) TearDown() error {
} }
func (c *rbdUnmounter) TearDownAt(dir string) error { func (c *rbdUnmounter) TearDownAt(dir string) error {
if pathExists, pathErr := volutil.PathExists(dir); pathErr != nil {
return fmt.Errorf("Error checking if path exists: %v", pathErr)
} else if !pathExists {
glog.Warningf("Warning: Unmount skipped because path does not exist: %v", dir)
return nil
}
return diskTearDown(c.manager, *c, dir, c.mounter) return diskTearDown(c.manager, *c, dir, c.mounter)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment