Skip to content

Commit f0e9876

Browse files
committed
use v1 and v1beta clients depending on which named pipes are available
1 parent 3c4c4d0 commit f0e9876

File tree

7 files changed

+802
-420
lines changed

7 files changed

+802
-420
lines changed

Diff for: pkg/gce-pd-csi-driver/utils_windows.go

+68-31
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,47 @@ func formatAndMount(source, target, fstype string, options []string, m *mount.Sa
2828
if !strings.EqualFold(fstype, defaultWindowsFsType) {
2929
return fmt.Errorf("GCE PD CSI driver can only supports %s file system, it does not support %s", defaultWindowsFsType, fstype)
3030
}
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)
3439
}
35-
return proxy.FormatAndMount(source, target, fstype, options)
40+
41+
return fmt.Errorf("Invalid interface type=%v", m.Interface)
3642
}
3743

3844
// Before mounting (which means creating symlink) in Windows, the targetPath should
3945
// not exist. Currently kubelet creates the path beforehand, this is a workaround to
4046
// remove the path first.
4147
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
4969
}
50-
if exists {
51-
return proxy.RemovePodDir(path)
52-
}
53-
return nil
70+
71+
return fmt.Errorf("Invalid interface type=%v", m.Interface)
5472
}
5573

5674
// Before staging (which means creating symlink) in Windows, the targetPath should
@@ -60,19 +78,27 @@ func prepareStagePath(path string, m *mount.SafeFormatAndMount) error {
6078
}
6179

6280
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)
6688
}
67-
return proxy.RemovePodDir(path)
89+
return fmt.Errorf("Invalid interface type=%v", m.Interface)
6890
}
6991

7092
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)
74100
}
75-
return proxy.UnmountDevice(path)
101+
return fmt.Errorf("Invalid interface type=%v", m.Interface)
76102
}
77103

78104
// search Windows disk number by volumeID
@@ -85,18 +111,29 @@ func getDevicePath(ns *GCENodeServer, volumeID, partition string) (string, error
85111
if err != nil {
86112
return "", fmt.Errorf("error getting device name: %v", err)
87113
}
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)
91122
}
92-
return proxy.GetDevicePath(deviceName, partition, volumeKey.Name)
123+
124+
return "", fmt.Errorf("Invalid interface type=%v", ns.Mounter.Interface)
125+
93126
}
94127

95128
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)
99136
}
137+
return 0, fmt.Errorf("Invalid interface type=%v", m.Interface)
100138

101-
return proxy.GetBlockSizeBytes(devicePath)
102139
}

0 commit comments

Comments
 (0)