diff --git a/pkg/util/mount/mount.go b/pkg/util/mount/mount.go index 5f0fe1867f4..fe39605c9c9 100644 --- a/pkg/util/mount/mount.go +++ b/pkg/util/mount/mount.go @@ -302,23 +302,6 @@ func checkForNetDev(options []string) bool { return false } -// HasMountRefs checks if the given mountPath has mountRefs. -// TODO: this is a workaround for the unmount device issue caused by gci mounter. -// In GCI cluster, if gci mounter is used for mounting, the container started by mounter -// script will cause additional mounts created in the container. Since these mounts are -// irrelevant to the original mounts, they should be not considered when checking the -// mount references. Current solution is to filter out those mount paths that contain -// the string of original mount path. -// Plan to work on better approach to solve this issue. -func HasMountRefs(mountPath string, mountRefs []string) bool { - for _, ref := range mountRefs { - if !strings.Contains(ref, mountPath) { - return true - } - } - return false -} - // PathWithinBase checks if give path is within given base directory. func PathWithinBase(fullPath, basePath string) bool { rel, err := filepath.Rel(basePath, fullPath) diff --git a/pkg/volume/util/operationexecutor/operation_generator.go b/pkg/volume/util/operationexecutor/operation_generator.go index 79245d18afc..e49488e0bfa 100644 --- a/pkg/volume/util/operationexecutor/operation_generator.go +++ b/pkg/volume/util/operationexecutor/operation_generator.go @@ -23,7 +23,7 @@ import ( "strings" "time" - "k8s.io/api/core/v1" + v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" @@ -967,7 +967,7 @@ func (og *operationGenerator) GenerateUnmountDeviceFunc( } refs, err := deviceMountableVolumePlugin.GetDeviceMountRefs(deviceMountPath) - if err != nil || mount.HasMountRefs(deviceMountPath, refs) { + if err != nil || util.HasMountRefs(deviceMountPath, refs) { if err == nil { err = fmt.Errorf("The device mount path %q is still mounted by other references %v", deviceMountPath, refs) } diff --git a/pkg/volume/util/util.go b/pkg/volume/util/util.go index 89dfb21f045..ee5b8aa47c2 100644 --- a/pkg/volume/util/util.go +++ b/pkg/volume/util/util.go @@ -576,3 +576,20 @@ func addContainerVolumes(containers []v1.Container, mounts, devices sets.String) } } } + +// HasMountRefs checks if the given mountPath has mountRefs. +// TODO: this is a workaround for the unmount device issue caused by gci mounter. +// In GCI cluster, if gci mounter is used for mounting, the container started by mounter +// script will cause additional mounts created in the container. Since these mounts are +// irrelevant to the original mounts, they should be not considered when checking the +// mount references. Current solution is to filter out those mount paths that contain +// the string of original mount path. +// Plan to work on better approach to solve this issue. +func HasMountRefs(mountPath string, mountRefs []string) bool { + for _, ref := range mountRefs { + if !strings.Contains(ref, mountPath) { + return true + } + } + return false +}