Skip to content

Commit

Permalink
When remove ephemeral csi failed, force remove it.
Browse files Browse the repository at this point in the history
  • Loading branch information
VinceCui committed Jul 18, 2023
1 parent 9aa487f commit bc41367
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
FROM golang:1.15.6 AS builder
FROM golang:1.15.6@sha256:9a3218c894d35d855c819fb6ec52333920fea69f90a793b6570620a128643363 AS builder

WORKDIR /go/src/github.com/alibaba/open-local
COPY . .
RUN make build && chmod +x bin/open-local

FROM alpine:3.9
FROM alpine:3.9@sha256:65b3a80ebe7471beecbc090c5b2cdd0aafeaefa0715f8f12e40dc918a3a70e32
LABEL maintainers="Alibaba Cloud Authors"
LABEL description="open-local is a local disk management system"
RUN apk update && apk upgrade && apk add util-linux coreutils e2fsprogs e2fsprogs-extra xfsprogs xfsprogs-extra blkid file open-iscsi jq
Expand Down
14 changes: 12 additions & 2 deletions pkg/csi/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package csi
import (
"encoding/json"
"fmt"
"io/fs"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -224,13 +225,22 @@ func (ns *nodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpu
}
}

ephemeralDevice, exist := ns.ephemeralVolumeStore.GetDevice(volumeID)

if err := ns.osTool.CleanupMountPoint(targetPath, ns.k8smounter, true /*extensiveMountPointCheck*/); err != nil {
return nil, status.Errorf(codes.Internal, "NodeUnpublishVolume: fail to umount volume %s for path %s: %s", volumeID, targetPath, err.Error())
if e1, ok := err.(*fs.PathError); ok && e1.Unwrap().Error() == "directory not empty" &&
exist && ephemeralDevice != "" {
log.Infof("NodeUnpublishVolume: failed to umount target path %s cause not empty, try to force remove it", targetPath)
if e2 := os.RemoveAll(targetPath); e2 != nil {
return nil, status.Errorf(codes.Internal, "NodeUnpublishVolume: fail to umount volume %s for path %s: %s, and failed to force remove it: %s", volumeID, targetPath, err.Error(), e2.Error())
}
} else {
return nil, status.Errorf(codes.Internal, "NodeUnpublishVolume: fail to umount volume %s for path %s: %s", volumeID, targetPath, err.Error())
}
}

// Step 3: delete ephemeral device
var err error
ephemeralDevice, exist := ns.ephemeralVolumeStore.GetDevice(volumeID)
if exist && ephemeralDevice != "" {
// /dev/mapper/yoda--pool0-yoda--5c523416--7288--4138--95e0--f9392995959f
if ns.spdkSupported {
Expand Down

0 comments on commit bc41367

Please sign in to comment.