Skip to content

Commit 41e64de

Browse files
YashasG98GouthamML
authored andcommitted
[OKE-36786] NodeUnpublish should return success when path is not present
1 parent 117682f commit 41e64de

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

pkg/csi/driver/bv_node.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,10 @@ func (d BlockVolumeNodeDriver) NodeUnpublishVolume(ctx context.Context, req *csi
664664
isRawBlockVolume, rbvCheckErr := hostUtil.PathIsDevice(req.TargetPath)
665665

666666
if rbvCheckErr != nil {
667+
if alreadyDeletedPathCheck(rbvCheckErr) {
668+
logger.With(zap.Error(rbvCheckErr)).With("mountPath", req.TargetPath).Warn("mount point not found, marking unpublish success")
669+
return &csi.NodeUnpublishVolumeResponse{}, nil
670+
}
667671
logger.With(zap.Error(rbvCheckErr)).Error("failed to check if it is a device file")
668672
return nil, status.Errorf(codes.Internal, rbvCheckErr.Error())
669673
}
@@ -751,6 +755,13 @@ func getDevicePathAndAttachmentType(path []string) (string, string, error) {
751755
return "", "", errors.New("unable to determine the attachment type")
752756
}
753757

758+
func alreadyDeletedPathCheck(err error) bool {
759+
if err == nil {
760+
return false
761+
}
762+
return strings.Contains(err.Error(), "does not exist")
763+
}
764+
754765
// NodeGetCapabilities returns the supported capabilities of the node server
755766
func (d BlockVolumeNodeDriver) NodeGetCapabilities(ctx context.Context, req *csi.NodeGetCapabilitiesRequest) (*csi.NodeGetCapabilitiesResponse, error) {
756767
var nscaps []*csi.NodeServiceCapability

pkg/csi/driver/bv_node_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package driver
1616

1717
import (
18+
"fmt"
1819
"testing"
1920
)
2021

@@ -81,3 +82,33 @@ func Test_getDevicePathAndAttachmentType(t *testing.T) {
8182
})
8283
}
8384
}
85+
86+
func Test_alreadyDeletedPathCheck(t *testing.T) {
87+
type args struct {
88+
err error
89+
}
90+
tests := []struct {
91+
name string
92+
args args
93+
want bool
94+
}{
95+
{
96+
"Error contains 'does not exist'",
97+
args{err: fmt.Errorf("path /some/path does not exist")},
98+
true,
99+
},
100+
{
101+
"Nil error",
102+
args{err: nil},
103+
false,
104+
},
105+
}
106+
for _, tt := range tests {
107+
t.Run(tt.name, func(t *testing.T) {
108+
got := alreadyDeletedPathCheck(tt.args.err)
109+
if got != tt.want {
110+
t.Errorf("alreadyDeletedPathCheck() = %v, want %v", got, tt.want)
111+
}
112+
})
113+
}
114+
}

0 commit comments

Comments
 (0)