Skip to content

Commit 3c4c4d0

Browse files
committed
WIP checkpoint before cloning to beta
1 parent 0285632 commit 3c4c4d0

File tree

1 file changed

+91
-75
lines changed

1 file changed

+91
-75
lines changed

Diff for: pkg/mount-manager/safe-mounter_windows.go

+91-75
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,19 @@ import (
2626
"strings"
2727

2828
csiproxyclient "github.com/kubernetes-csi/csi-proxy/client"
29-
"github.com/kubernetes-csi/csi-proxy/client/apiversion"
3029

3130
diskapi "github.com/kubernetes-csi/csi-proxy/client/api/disk/v1"
32-
diskclient "github.com/kubernetes-csi/csi-proxy/client/groups/disk/v1"
31+
diskclientv1 "github.com/kubernetes-csi/csi-proxy/client/groups/disk/v1"
32+
diskclientv1beta2 "github.com/kubernetes-csi/csi-proxy/client/groups/disk/v1beta2"
3333

34-
fsapi "github.com/kubernetes-csi/csi-proxy/client/api/filesystem/v1"
35-
fsclient "github.com/kubernetes-csi/csi-proxy/client/groups/filesystem/v1"
34+
fsapiv1 "github.com/kubernetes-csi/csi-proxy/client/api/filesystem/v1"
35+
fsapiv1beta1 "github.com/kubernetes-csi/csi-proxy/client/api/filesystem/v1beta1"
36+
fsclientv1 "github.com/kubernetes-csi/csi-proxy/client/groups/filesystem/v1"
37+
fsclientv1beta1 "github.com/kubernetes-csi/csi-proxy/client/groups/filesystem/v1beta1"
3638

3739
volumeapi "github.com/kubernetes-csi/csi-proxy/client/api/volume/v1"
38-
volumeclient "github.com/kubernetes-csi/csi-proxy/client/groups/volume/v1"
40+
volumeclientv1 "github.com/kubernetes-csi/csi-proxy/client/groups/volume/v1"
41+
volumeclientv1beta1 "github.com/kubernetes-csi/csi-proxy/client/groups/volume/v1beta1"
3942

4043
"k8s.io/klog"
4144
"k8s.io/mount-utils"
@@ -45,87 +48,86 @@ import (
4548
var _ mount.Interface = &CSIProxyMounter{}
4649

4750
type CSIProxyMounter struct {
48-
FsClient *fsclient.Client
49-
DiskClient *diskclient.Client
50-
VolumeClient *volumeclient.Client
51+
// DiskClientV1 *diskclientv1.Client
52+
// FsClientV1 *fsclientv1.Client
53+
// VolumeClientV1 *volumeclientv1.Client
54+
55+
// // compatibility mode with the beta client
56+
// DiskClientV1Beta2 *diskclientv1beta2.Client
57+
// FsClientV1Beta1 *fsclientv1beta1.Client
58+
// VolumeClientV1Beta1 *volumeclientv1beta1.Client
5159
}
5260

53-
var versionv1beta2 = apiversion.NewVersionOrPanic("v1beta2")
54-
var versionv1beta1 = apiversion.NewVersionOrPanic("v1beta1")
61+
var _ CSIProxyMounterInterface = &CSIProxyMounter{}
5562

56-
func getDiskClient() (*diskclient.Client, error) {
63+
func (mounter *CSIProxyMounter) pickDiskClient() error {
5764
var err error
58-
diskAPIVersions := []apiversion.Version{diskclient.Version, versionv1beta2}
59-
60-
// attempt to connect to one of the clients in order
61-
for _, apiVersion := range diskAPIVersions {
62-
pipePath := csiproxyclient.PipePath(diskclient.GroupName, apiVersion)
63-
klog.V(4).Infof("Attempting to connect to csi-proxy diskapi at path=%s", pipePath)
64-
diskClient, err := diskclient.NewClientWithPipePath(pipePath)
65-
if err == nil {
66-
klog.V(4).Infof("Connected to csi-proxy diskapi at path=%s", pipePath)
67-
return diskClient, nil
68-
}
69-
klog.V(4).Infof("Connection to csi-proxy diskapi at path=%s failed with error=%v, might retry with a different version", pipePath, err)
65+
var pipePath string
66+
pipePath = csiproxyclient.PipePath(diskclientv1.GroupName, diskclientv1.Version)
67+
if diskClient, err := diskclientv1.NewClient(); err == nil {
68+
mounter.DiskClientV1 = diskClient
69+
klog.V(4).Infof("Connected to csi-proxy diskapi at path=%s", pipePath)
70+
return nil
71+
}
72+
73+
pipePath = csiproxyclient.PipePath(diskclientv1beta2.GroupName, diskclientv1beta2.Version)
74+
if diskClient, err := diskclientv1beta2.NewClient(); err == nil {
75+
mounter.DiskClientV1Beta2 = diskClient
76+
klog.V(4).Infof("Connected to csi-proxy diskapi at path=%s", pipePath)
77+
return nil
7078
}
71-
return nil, fmt.Errorf("Couldn't connect to any csi-proxy diskapi server, last error %v", err)
79+
return fmt.Errorf("Couldn't connect to any csi-proxy diskapi server, last error=%v", err)
7280
}
7381

74-
func getFsClient() (*fsclient.Client, error) {
82+
func (mounter *CSIProxyMounter) pickFsClient() error {
7583
var err error
76-
diskAPIVersions := []apiversion.Version{fsclient.Version, versionv1beta1}
77-
78-
// attempt to connect to one of the clients in order
79-
for _, apiVersion := range diskAPIVersions {
80-
pipePath := csiproxyclient.PipePath(fsclient.GroupName, apiVersion)
81-
klog.V(4).Infof("Attempting to connect to csi-proxy fsapi at path=%s", pipePath)
82-
fsClient, err := fsclient.NewClientWithPipePath(pipePath)
83-
if err == nil {
84-
klog.V(4).Infof("Connected to csi-proxy fsapi at path=%s", pipePath)
85-
return fsClient, nil
86-
}
87-
klog.V(4).Infof("Connection to csi-proxy fsapi at path=%s failed with error=%v, might retry with a different version", pipePath, err)
84+
var pipePath string
85+
pipePath = csiproxyclient.PipePath(fsclientv1.GroupName, fsclientv1.Version)
86+
if fsClient, err := fsclientv1.NewClient(); err == nil {
87+
mounter.FsClientV1 = fsClient
88+
klog.V(4).Infof("Connected to csi-proxy fsapi at path=%s", pipePath)
89+
return nil
8890
}
89-
return nil, fmt.Errorf("Couldn't connect to any csi-proxy fsapi server, last error %v", err)
91+
92+
pipePath = csiproxyclient.PipePath(fsclientv1beta1.GroupName, fsclientv1beta1.Version)
93+
if fsClient, err := fsclientv1beta1.NewClient(); err == nil {
94+
mounter.FsClientV1Beta1 = fsClient
95+
klog.V(4).Infof("Connected to csi-proxy fsapi at path=%s", pipePath)
96+
return nil
97+
}
98+
return fmt.Errorf("Couldn't connect to any csi-proxy fsapi server, last error=%v", err)
9099
}
91100

92-
func getVolumeClient() (*volumeclient.Client, error) {
101+
func (mounter *CSIProxyMounter) pickVolumeClient() error {
93102
var err error
94-
diskAPIVersions := []apiversion.Version{volumeclient.Version, versionv1beta1}
95-
96-
// attempt to connect to one of the clients in order
97-
for _, apiVersion := range diskAPIVersions {
98-
pipePath := csiproxyclient.PipePath(volumeclient.GroupName, apiVersion)
99-
klog.V(4).Infof("Attempting to connect to csi-proxy volumeapi at path=%s", pipePath)
100-
volumeClient, err := volumeclient.NewClientWithPipePath(pipePath)
101-
if err == nil {
102-
klog.V(4).Infof("Connected to csi-proxy volumeapi at path=%s", pipePath)
103-
return volumeClient, nil
104-
}
105-
klog.V(4).Infof("Connection to csi-proxy volumeapi at path=%s failed with error=%v, might retry with a different version", pipePath, err)
103+
var pipePath string
104+
pipePath = csiproxyclient.PipePath(volumeclientv1.GroupName, volumeclientv1.Version)
105+
if volumeClient, err := volumeclientv1.NewClient(); err == nil {
106+
mounter.VolumeClientV1 = volumeClient
107+
klog.V(4).Infof("Connected to csi-proxy volumeapi at path=%s", pipePath)
108+
return nil
106109
}
107-
return nil, fmt.Errorf("Couldn't connect to any csi-proxy volumeapi server, last error %v", err)
108-
}
109110

111+
pipePath = csiproxyclient.PipePath(volumeclientv1beta1.GroupName, volumeclientv1beta1.Version)
112+
if volumeClient, err := volumeclientv1beta1.NewClient(); err == nil {
113+
mounter.VolumeClientV1Beta1 = volumeClient
114+
klog.V(4).Infof("Connected to csi-proxy volumeapi at path=%s", pipePath)
115+
return nil
116+
}
117+
return fmt.Errorf("Couldn't connect to any csi-proxy volumeapi server, last error=%v", err)
118+
}
110119
func NewCSIProxyMounter() (*CSIProxyMounter, error) {
111-
diskClient, err := getDiskClient()
112-
if err != nil {
120+
mounter := &CSIProxyMounter{}
121+
if err := mounter.pickDiskClient(); err != nil {
113122
return nil, err
114123
}
115-
116-
fsClient, err := getFsClient()
117-
if err != nil {
124+
if err := mounter.pickFsClient(); err != nil {
118125
return nil, err
119126
}
120-
volumeClient, err := getVolumeClient()
121-
if err != nil {
127+
if err := mounter.pickVolumeClient(); err != nil {
122128
return nil, err
123129
}
124-
return &CSIProxyMounter{
125-
FsClient: fsClient,
126-
DiskClient: diskClient,
127-
VolumeClient: volumeClient,
128-
}, nil
130+
return mounter, nil
129131
}
130132

131133
func NewSafeMounter() (*mount.SafeFormatAndMount, error) {
@@ -157,16 +159,30 @@ func (mounter *CSIProxyMounter) MountSensitive(source string, target string, fst
157159
if err := os.MkdirAll(parentDir, 0755); err != nil {
158160
return err
159161
}
160-
linkRequest := &fsapi.LinkPathRequest{
161-
SourcePath: mount.NormalizeWindowsPath(source),
162-
TargetPath: mount.NormalizeWindowsPath(target),
163-
}
164-
response, err := mounter.FsClient.LinkPath(context.Background(), linkRequest)
165-
if err != nil {
166-
return err
167-
}
168-
if response.Error != "" {
169-
return errors.New(response.Error)
162+
if mounter.FsClientV1 != nil {
163+
linkRequest := &fsapiv1.LinkPathRequest{
164+
SourcePath: mount.NormalizeWindowsPath(source),
165+
TargetPath: mount.NormalizeWindowsPath(target),
166+
}
167+
response, err := mounter.FsClientV1.LinkPath(context.Background(), linkRequest)
168+
if err != nil {
169+
return err
170+
}
171+
if response.Error != "" {
172+
return errors.New(response.Error)
173+
}
174+
} else {
175+
linkRequest := &fsapiv1beta1.LinkPathRequest{
176+
SourcePath: mount.NormalizeWindowsPath(source),
177+
TargetPath: mount.NormalizeWindowsPath(target),
178+
}
179+
response, err := mounter.FsClientV1Beta1.LinkPath(context.Background(), linkRequest)
180+
if err != nil {
181+
return err
182+
}
183+
if response.Error != "" {
184+
return errors.New(response.Error)
185+
}
170186
}
171187
return nil
172188
}

0 commit comments

Comments
 (0)