From 77a9ef23c7be6850fb8589402cff21007d02a6b0 Mon Sep 17 00:00:00 2001 From: dtarasov7 <44495304+dtarasov7@users.noreply.github.com> Date: Thu, 26 Jan 2023 09:27:34 +0300 Subject: [PATCH] Stage: Create directory for mount if it doesn't exist --- pkg/csi/node.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pkg/csi/node.go b/pkg/csi/node.go index 2186b759..72f6554f 100644 --- a/pkg/csi/node.go +++ b/pkg/csi/node.go @@ -151,6 +151,21 @@ func (ns *nodeService) NodeStageVolume(ctx context.Context, } } + // Check if directory exists + mountDirExists, err := ns.checkIfDirExists(mountDir) + if err != nil { + return nil, status.Errorf(codes.Internal, "could not verify that [%s] is a dir: [%v]", mountDir, err) + } + if !mountDirExists { + // Directory doesn't exest + klog.Infof("Path [%s] does not exist. Make it\n", mountDir) + if err := os.MkdirAll(mountDir, 0750); err != nil { + return nil, status.Error(codes.Internal, + fmt.Sprintf("unable to mkdir at path [%s] - [%s] ", + mountDir, err.Error())) + } + } + // Mounting as the device is not yet mounted klog.Infof("Mounting device [%s] to folder [%s] of type [%s] with flags [%v]", devicePath, mountDir, fsType, mountFlags)