@@ -28,29 +28,47 @@ func formatAndMount(source, target, fstype string, options []string, m *mount.Sa
28
28
if ! strings .EqualFold (fstype , defaultWindowsFsType ) {
29
29
return fmt .Errorf ("GCE PD CSI driver can only supports %s file system, it does not support %s" , defaultWindowsFsType , fstype )
30
30
}
31
- proxy , ok := m .Interface .(* mounter.CSIProxyMounter )
32
- if ! ok {
33
- return fmt .Errorf ("could not cast to csi proxy class" )
31
+ switch m .Interface .(type ) {
32
+ case * mounter.CSIProxyMounterV1 :
33
+ proxy := m .Interface .(* mounter.CSIProxyMounterV1 )
34
+ return proxy .FormatAndMount (source , target , fstype , options )
35
+
36
+ case * mounter.CSIProxyMounterV1Beta :
37
+ proxy := m .Interface .(* mounter.CSIProxyMounterV1Beta )
38
+ return proxy .FormatAndMount (source , target , fstype , options )
34
39
}
35
- return proxy .FormatAndMount (source , target , fstype , options )
40
+
41
+ return fmt .Errorf ("Invalid interface type=%v" , m .Interface )
36
42
}
37
43
38
44
// Before mounting (which means creating symlink) in Windows, the targetPath should
39
45
// not exist. Currently kubelet creates the path beforehand, this is a workaround to
40
46
// remove the path first.
41
47
func preparePublishPath (path string , m * mount.SafeFormatAndMount ) error {
42
- proxy , ok := m .Interface .(* mounter.CSIProxyMounter )
43
- if ! ok {
44
- return fmt .Errorf ("could not cast to csi proxy class" )
45
- }
46
- exists , err := proxy .ExistsPath (path )
47
- if err != nil {
48
- return err
48
+ switch m .Interface .(type ) {
49
+ case * mounter.CSIProxyMounterV1 :
50
+ proxy := m .Interface .(* mounter.CSIProxyMounterV1 )
51
+ exists , err := proxy .ExistsPath (path )
52
+ if err != nil {
53
+ return err
54
+ }
55
+ if exists {
56
+ return proxy .RemovePodDir (path )
57
+ }
58
+ return nil
59
+ case * mounter.CSIProxyMounterV1Beta :
60
+ proxy := m .Interface .(* mounter.CSIProxyMounterV1Beta )
61
+ exists , err := proxy .ExistsPath (path )
62
+ if err != nil {
63
+ return err
64
+ }
65
+ if exists {
66
+ return proxy .RemovePodDir (path )
67
+ }
68
+ return nil
49
69
}
50
- if exists {
51
- return proxy .RemovePodDir (path )
52
- }
53
- return nil
70
+
71
+ return fmt .Errorf ("Invalid interface type=%v" , m .Interface )
54
72
}
55
73
56
74
// Before staging (which means creating symlink) in Windows, the targetPath should
@@ -60,19 +78,27 @@ func prepareStagePath(path string, m *mount.SafeFormatAndMount) error {
60
78
}
61
79
62
80
func cleanupPublishPath (path string , m * mount.SafeFormatAndMount ) error {
63
- proxy , ok := m .Interface .(* mounter.CSIProxyMounter )
64
- if ! ok {
65
- return fmt .Errorf ("could not cast to csi proxy class" )
81
+ switch m .Interface .(type ) {
82
+ case * mounter.CSIProxyMounterV1 :
83
+ proxy := m .Interface .(* mounter.CSIProxyMounterV1 )
84
+ return proxy .RemovePodDir (path )
85
+ case * mounter.CSIProxyMounterV1Beta :
86
+ proxy := m .Interface .(* mounter.CSIProxyMounterV1Beta )
87
+ return proxy .RemovePodDir (path )
66
88
}
67
- return proxy . RemovePodDir ( path )
89
+ return fmt . Errorf ( "Invalid interface type=%v" , m . Interface )
68
90
}
69
91
70
92
func cleanupStagePath (path string , m * mount.SafeFormatAndMount ) error {
71
- proxy , ok := m .Interface .(* mounter.CSIProxyMounter )
72
- if ! ok {
73
- return fmt .Errorf ("could not cast to csi proxy class" )
93
+ switch m .Interface .(type ) {
94
+ case * mounter.CSIProxyMounterV1 :
95
+ proxy := m .Interface .(* mounter.CSIProxyMounterV1 )
96
+ return proxy .UnmountDevice (path )
97
+ case * mounter.CSIProxyMounterV1Beta :
98
+ proxy := m .Interface .(* mounter.CSIProxyMounterV1Beta )
99
+ return proxy .UnmountDevice (path )
74
100
}
75
- return proxy . UnmountDevice ( path )
101
+ return fmt . Errorf ( "Invalid interface type=%v" , m . Interface )
76
102
}
77
103
78
104
// search Windows disk number by volumeID
@@ -85,18 +111,29 @@ func getDevicePath(ns *GCENodeServer, volumeID, partition string) (string, error
85
111
if err != nil {
86
112
return "" , fmt .Errorf ("error getting device name: %v" , err )
87
113
}
88
- proxy , ok := ns .Mounter .Interface .(* mounter.CSIProxyMounter )
89
- if ! ok {
90
- return "" , fmt .Errorf ("could not cast to csi proxy class" )
114
+
115
+ switch ns .Mounter .Interface .(type ) {
116
+ case * mounter.CSIProxyMounterV1 :
117
+ proxy := ns .Mounter .Interface .(* mounter.CSIProxyMounterV1 )
118
+ return proxy .GetDevicePath (deviceName , partition , volumeKey .Name )
119
+ case * mounter.CSIProxyMounterV1Beta :
120
+ proxy := ns .Mounter .Interface .(* mounter.CSIProxyMounterV1Beta )
121
+ return proxy .GetDevicePath (deviceName , partition , volumeKey .Name )
91
122
}
92
- return proxy .GetDevicePath (deviceName , partition , volumeKey .Name )
123
+
124
+ return "" , fmt .Errorf ("Invalid interface type=%v" , ns .Mounter .Interface )
125
+
93
126
}
94
127
95
128
func getBlockSizeBytes (devicePath string , m * mount.SafeFormatAndMount ) (int64 , error ) {
96
- proxy , ok := m .Interface .(* mounter.CSIProxyMounter )
97
- if ! ok {
98
- return 0 , fmt .Errorf ("could not cast to csi proxy class" )
129
+ switch m .Interface .(type ) {
130
+ case * mounter.CSIProxyMounterV1 :
131
+ proxy := m .Interface .(* mounter.CSIProxyMounterV1 )
132
+ return proxy .GetBlockSizeBytes (devicePath )
133
+ case * mounter.CSIProxyMounterV1Beta :
134
+ proxy := m .Interface .(* mounter.CSIProxyMounterV1Beta )
135
+ return proxy .GetBlockSizeBytes (devicePath )
99
136
}
137
+ return 0 , fmt .Errorf ("Invalid interface type=%v" , m .Interface )
100
138
101
- return proxy .GetBlockSizeBytes (devicePath )
102
139
}
0 commit comments