mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 02:33:34 +00:00
cleanup: create k8s.io/mount-utils Mounter only once
Recently the k8s.io/mount-utils package added more runtime dectection. When creating a new Mounter, the detect is run every time. This is unfortunate, as it logs a message like the following: ``` mount_linux.go:283] Detected umount with safe 'not mounted' behavior ``` This message might be useful, so it probably good to keep it. In Ceph-CSI there are various locations where Mounter instances are created. Moving that to the DefaultNodeServer type reduces it to a single place. Some utility functions need to accept the additional parameter too, so that has been modified as well. See-also: kubernetes/kubernetes#109676 Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
committed by
mergify[bot]
parent
5ed305850f
commit
011d4fc81c
@ -24,12 +24,14 @@ import (
|
||||
"github.com/container-storage-interface/spec/lib/go/csi"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
mount "k8s.io/mount-utils"
|
||||
)
|
||||
|
||||
// DefaultNodeServer stores driver object.
|
||||
type DefaultNodeServer struct {
|
||||
Driver *CSIDriver
|
||||
Type string
|
||||
Driver *CSIDriver
|
||||
Type string
|
||||
Mounter mount.Interface
|
||||
}
|
||||
|
||||
// NodeExpandVolume returns unimplemented response.
|
||||
|
@ -38,6 +38,7 @@ import (
|
||||
"google.golang.org/grpc/status"
|
||||
"k8s.io/klog/v2"
|
||||
"k8s.io/kubernetes/pkg/volume"
|
||||
mount "k8s.io/mount-utils"
|
||||
)
|
||||
|
||||
func parseEndpoint(ep string) (string, string, error) {
|
||||
@ -61,8 +62,9 @@ func NewDefaultNodeServer(d *CSIDriver, t string, topology map[string]string) *D
|
||||
d.topology = topology
|
||||
|
||||
return &DefaultNodeServer{
|
||||
Driver: d,
|
||||
Type: t,
|
||||
Driver: d,
|
||||
Type: t,
|
||||
Mounter: mount.New(""),
|
||||
}
|
||||
}
|
||||
|
||||
@ -229,8 +231,12 @@ func panicHandler(
|
||||
// requested by the NodeGetVolumeStats CSI procedure.
|
||||
// It is shared for FileMode volumes, both the CephFS and RBD NodeServers call
|
||||
// this.
|
||||
func FilesystemNodeGetVolumeStats(ctx context.Context, targetPath string) (*csi.NodeGetVolumeStatsResponse, error) {
|
||||
isMnt, err := util.IsMountPoint(targetPath)
|
||||
func FilesystemNodeGetVolumeStats(
|
||||
ctx context.Context,
|
||||
mounter mount.Interface,
|
||||
targetPath string,
|
||||
) (*csi.NodeGetVolumeStatsResponse, error) {
|
||||
isMnt, err := util.IsMountPoint(mounter, targetPath)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return nil, status.Errorf(codes.InvalidArgument, "targetpath %s does not exist", targetPath)
|
||||
|
@ -26,6 +26,7 @@ import (
|
||||
"github.com/container-storage-interface/spec/lib/go/csi"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
mount "k8s.io/mount-utils"
|
||||
)
|
||||
|
||||
var fakeID = "fake-id"
|
||||
@ -87,7 +88,7 @@ func TestFilesystemNodeGetVolumeStats(t *testing.T) {
|
||||
|
||||
// retry until a mountpoint is found
|
||||
for {
|
||||
stats, err := FilesystemNodeGetVolumeStats(context.TODO(), cwd)
|
||||
stats, err := FilesystemNodeGetVolumeStats(context.TODO(), mount.New(""), cwd)
|
||||
if err != nil && cwd != "/" && strings.HasSuffix(err.Error(), "is not mounted") {
|
||||
// try again with the parent directory
|
||||
cwd = filepath.Dir(cwd)
|
||||
|
Reference in New Issue
Block a user