mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 05:57:25 +00:00
mv HasMountRefs from mount pkg to vol/util
HasMountRefs is only used internal to K8s and should not be moved out with the mount package. move it to pkg/volume/util instead.
This commit is contained in:
parent
bad4d0ee96
commit
a7830a2c6e
@ -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)
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user