...
1
16
17 package flexvolume
18
19 import (
20 "fmt"
21 "os"
22
23 "k8s.io/klog/v2"
24 "k8s.io/mount-utils"
25 "k8s.io/utils/exec"
26
27 "k8s.io/kubernetes/pkg/volume"
28 )
29
30
31 type flexVolumeUnmounter struct {
32 *flexVolume
33
34 runner exec.Interface
35 }
36
37 var _ volume.Unmounter = &flexVolumeUnmounter{}
38
39
40 func (f *flexVolumeUnmounter) TearDown() error {
41 path := f.GetPath()
42 return f.TearDownAt(path)
43 }
44
45 func (f *flexVolumeUnmounter) TearDownAt(dir string) error {
46 pathExists, pathErr := mount.PathExists(dir)
47 if pathErr != nil {
48
49 klog.Warningf("Error checking path: %v", pathErr)
50 } else {
51 if !pathExists {
52 klog.Warningf("Warning: Unmount skipped because path does not exist: %v", dir)
53 return nil
54 }
55 }
56
57 call := f.plugin.NewDriverCall(unmountCmd)
58 call.Append(dir)
59 _, err := call.Run()
60 if isCmdNotSupportedErr(err) {
61 err = (*unmounterDefaults)(f).TearDownAt(dir)
62 }
63 if err != nil {
64 return err
65 }
66
67
68 if pathExists, pathErr := mount.PathExists(dir); pathErr != nil {
69 return fmt.Errorf("error checking if path exists: %w", pathErr)
70 } else if !pathExists {
71 return nil
72 }
73 return os.Remove(dir)
74 }
75
View as plain text