mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-07 11:13:48 +00:00
Merge pull request #81745 from codenrhoden/mv-hasmountrefs
mv HasMountRefs from mount pkg to vol/util
This commit is contained in:
commit
f1453953b7
@ -302,23 +302,6 @@ func checkForNetDev(options []string) bool {
|
|||||||
return false
|
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.
|
// PathWithinBase checks if give path is within given base directory.
|
||||||
func PathWithinBase(fullPath, basePath string) bool {
|
func PathWithinBase(fullPath, basePath string) bool {
|
||||||
rel, err := filepath.Rel(basePath, fullPath)
|
rel, err := filepath.Rel(basePath, fullPath)
|
||||||
|
@ -23,7 +23,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/api/errors"
|
"k8s.io/apimachinery/pkg/api/errors"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
@ -967,7 +967,7 @@ func (og *operationGenerator) GenerateUnmountDeviceFunc(
|
|||||||
}
|
}
|
||||||
refs, err := deviceMountableVolumePlugin.GetDeviceMountRefs(deviceMountPath)
|
refs, err := deviceMountableVolumePlugin.GetDeviceMountRefs(deviceMountPath)
|
||||||
|
|
||||||
if err != nil || mount.HasMountRefs(deviceMountPath, refs) {
|
if err != nil || util.HasMountRefs(deviceMountPath, refs) {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = fmt.Errorf("The device mount path %q is still mounted by other references %v", deviceMountPath, refs)
|
err = fmt.Errorf("The device mount path %q is still mounted by other references %v", deviceMountPath, refs)
|
||||||
}
|
}
|
||||||
|
@ -573,3 +573,20 @@ func GetPodVolumeNames(pod *v1.Pod) (mounts sets.String, devices sets.String) {
|
|||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user