@@ -124,15 +124,38 @@ func (mounter *CSIProxyMounter) RemovePodDir(target string) error {
124
124
return nil
125
125
}
126
126
127
- // Delete the given directory with plugin context. CSI proxy does a check for path prefix
127
+ // UnmountDevice uses target path to find the volume id first, and then
128
+ // call DismountVolume through csi-proxy. If succeeded, it will delete the given path
129
+ // at last step. CSI proxy does a check for path prefix
128
130
// based on context
129
- func (mounter * CSIProxyMounter ) RemovePluginDir (target string ) error {
131
+ func (mounter * CSIProxyMounter ) UnmountDevice (target string ) error {
132
+ target = mount .NormalizeWindowsPath (target )
133
+ if exists , err := mounter .ExistsPath (target ); ! exists {
134
+ return err
135
+ }
136
+ idRequest := & volumeapi.VolumeIDFromMountRequest {
137
+ Mount : target ,
138
+ }
139
+ idResponse , err := mounter .VolumeClient .GetVolumeIDFromMount (context .Background (), idRequest )
140
+ if err != nil {
141
+ return err
142
+ }
143
+ volumeId := idResponse .GetVolumeId ()
144
+
145
+ dismountRequest := & volumeapi.DismountVolumeRequest {
146
+ Path : target ,
147
+ VolumeId : volumeId ,
148
+ }
149
+ _ , err = mounter .VolumeClient .DismountVolume (context .Background (), dismountRequest )
150
+ if err != nil {
151
+ return err
152
+ }
130
153
rmdirRequest := & fsapi.RmdirRequest {
131
- Path : mount . NormalizeWindowsPath ( target ) ,
154
+ Path : target ,
132
155
Context : fsapi .PathContext_PLUGIN ,
133
156
Force : true ,
134
157
}
135
- _ , err : = mounter .FsClient .Rmdir (context .Background (), rmdirRequest )
158
+ _ , err = mounter .FsClient .Rmdir (context .Background (), rmdirRequest )
136
159
if err != nil {
137
160
return err
138
161
}
@@ -249,5 +272,8 @@ func (mounter *CSIProxyMounter) ExistsPath(path string) (bool, error) {
249
272
& fsapi.PathExistsRequest {
250
273
Path : mount .NormalizeWindowsPath (path ),
251
274
})
275
+ if err != nil {
276
+ return false , err
277
+ }
252
278
return isExistsResponse .Exists , err
253
279
}
0 commit comments