fix: 🐛 fix umount webdav server

fix umount webdav server

Signed-off-by: sys-liqian <lq1083301982@163.com>
dev
sys-liqian 1 year ago
parent 7051bb12b2
commit ff95639565

@ -0,0 +1,17 @@
GIT_COMMIT = $(shell git rev-parse HEAD)
BUILD_DATE = $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
PKG = github.com/sys-liqian/csi-driver-webdav
LDFLAGS = -X ${PKG}/pkg/webdav.driverVersion=${IMAGE_VERSION} -X ${PKG}/pkg/webdav.gitCommit=${GIT_COMMIT} -X ${PKG}/pkg/webdav.buildDate=${BUILD_DATE}
EXT_LDFLAGS = -s -w -extldflags "-static"
IMAGE_VERSION ?= v0.0.1
LOCAL_REPOSITORY ?= localhost:5000
.PHONY: go-build
go-build:
CGO_ENABLED=0 GOOS=linux GOARCH=$(ARCH) go build -a -ldflags "${LDFLAGS} ${EXT_LDFLAGS}" -o bin/webdavplugin ./cmd/webdav
.PHONY: build-local-image
build-local-image:
docker build --network host -t $(LOCAL_REPOSITORY)/webdavplugin:$(IMAGE_VERSION) .

@ -5,7 +5,7 @@ metadata:
name: webdav-sc name: webdav-sc
provisioner: webdav.csi.io provisioner: webdav.csi.io
parameters: parameters:
share: http://172.25.16.2/remote.php/dav/files/admin share: http://172.25.16.2:5244/dav/data
csi.storage.k8s.io/provisioner-secret-name: "webdav-secrect" csi.storage.k8s.io/provisioner-secret-name: "webdav-secrect"
csi.storage.k8s.io/provisioner-secret-namespace: "default" csi.storage.k8s.io/provisioner-secret-namespace: "default"
csi.storage.k8s.io/node-publish-secret-name: "webdav-secrect" csi.storage.k8s.io/node-publish-secret-name: "webdav-secrect"

@ -101,6 +101,12 @@ func (c *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVolu
return nil, status.Errorf(codes.Internal, "failed to make subdirectory: %v", err.Error()) return nil, status.Errorf(codes.Internal, "failed to make subdirectory: %v", err.Error())
} }
defer func() {
if err = c.mounter.Unmount(targetPath); err != nil {
klog.Warningf("failed to unmount targetpath %s: %v", targetPath, err.Error())
}
}()
if mountPermissions > 0 { if mountPermissions > 0 {
// Reset directory permissions because of umask problems // Reset directory permissions because of umask problems
if err = os.Chmod(internalVolumePath, os.FileMode(mountPermissions)); err != nil { if err = os.Chmod(internalVolumePath, os.FileMode(mountPermissions)); err != nil {
@ -108,10 +114,6 @@ func (c *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVolu
} }
} }
if err = c.mounter.Unmount(targetPath); err != nil {
return nil, status.Errorf(codes.Internal, "failed to unmount targetpath %s %v", targetPath, err)
}
return &csi.CreateVolumeResponse{ return &csi.CreateVolumeResponse{
Volume: &csi.Volume{ Volume: &csi.Volume{
VolumeId: MakeVolumeId(sourcePath, req.Name), VolumeId: MakeVolumeId(sourcePath, req.Name),
@ -142,16 +144,18 @@ func (c *ControllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVolu
return nil, status.Errorf(codes.Internal, fmt.Sprintf("mount failed: %v", err.Error())) return nil, status.Errorf(codes.Internal, fmt.Sprintf("mount failed: %v", err.Error()))
} }
defer func() {
if err = c.mounter.Unmount(targetPath); err != nil {
klog.Warningf("failed to unmount targetpath %s: %v", targetPath, err.Error())
}
}()
internalVolumePath := filepath.Join(targetPath, subDir) internalVolumePath := filepath.Join(targetPath, subDir)
klog.V(2).Infof("Removing subdirectory at %v", internalVolumePath) klog.V(2).Infof("Removing subdirectory at %v", internalVolumePath)
if err = os.RemoveAll(internalVolumePath); err != nil { if err = os.RemoveAll(internalVolumePath); err != nil {
return nil, status.Errorf(codes.Internal, "failed to delete subdirectory: %v", err.Error()) return nil, status.Errorf(codes.Internal, "failed to delete subdirectory: %v", err.Error())
} }
if err = c.mounter.Unmount(targetPath); err != nil {
return nil, status.Errorf(codes.Internal, "failed to unmount targetpath %s %v", targetPath, err)
}
return &csi.DeleteVolumeResponse{}, nil return &csi.DeleteVolumeResponse{}, nil
} }

@ -110,9 +110,20 @@ func (n *NodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpub
if len(targetPath) == 0 { if len(targetPath) == 0 {
return nil, status.Error(codes.InvalidArgument, "Target path missing in request") return nil, status.Error(codes.InvalidArgument, "Target path missing in request")
} }
klog.V(2).Infof("NodeUnpublishVolume: unmounting volume %s on %s", volumeID, targetPath)
err := n.mounter.Unmount(targetPath) notMnt, err := n.mounter.IsLikelyNotMountPoint(targetPath)
if err != nil {
if os.IsNotExist(err) {
return nil, status.Error(codes.NotFound, "Targetpath not found")
}
return nil, status.Error(codes.Internal, err.Error())
}
if notMnt {
return &csi.NodeUnpublishVolumeResponse{}, nil
}
klog.V(2).Infof("NodeUnpublishVolume: unmounting volume %s on %s", volumeID, targetPath)
err = n.mounter.Unmount(targetPath)
if err != nil { if err != nil {
return nil, status.Errorf(codes.Internal, "failed to unmount target %q: %v", targetPath, err) return nil, status.Errorf(codes.Internal, "failed to unmount target %q: %v", targetPath, err)
} }

Loading…
Cancel
Save