@@ -17,6 +17,7 @@ import (
17
17
"github.com/golang/glog"
18
18
"github.com/golang/protobuf/jsonpb"
19
19
"google.golang.org/grpc"
20
+ "google.golang.org/grpc/credentials/insecure"
20
21
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21
22
)
22
23
@@ -55,7 +56,7 @@ func NewControllerService(targetEndpoint, namespace string, peerpodvolumeClientS
55
56
}
56
57
57
58
func (s * ControllerService ) redirect (ctx context.Context , req interface {}, fn func (context.Context , csi.ControllerClient )) error {
58
- conn , err := grpc .Dial (s .TargetEndpoint , grpc .WithInsecure (), grpc .WithBlock ( ))
59
+ conn , err := grpc .Dial (s .TargetEndpoint , grpc .WithBlock (), grpc .WithTransportCredentials ( insecure . NewCredentials () ))
59
60
if err != nil {
60
61
return err
61
62
}
@@ -99,7 +100,7 @@ func (s *ControllerService) CreateVolume(ctx context.Context, req *csi.CreateVol
99
100
}
100
101
_ , err = s .PeerpodvolumeClient .PeerpodV1alpha1 ().PeerpodVolumes (s .Namespace ).Create (context .Background (), newPeerpodvolume , metav1.CreateOptions {})
101
102
if err != nil {
102
- glog .Error ("Error happens while creating peerPodVolume with volumeID: %v, err: %v" , volumeID , err .Error ())
103
+ glog .Errorf ("Error happens while creating peerPodVolume with volumeID: %v, err: %v" , volumeID , err .Error ())
103
104
} else {
104
105
glog .Infof ("Peerpodvolume object is created" )
105
106
}
@@ -122,7 +123,7 @@ func (s *ControllerService) DeleteVolume(ctx context.Context, req *csi.DeleteVol
122
123
} else {
123
124
ppErr := s .PeerpodvolumeClient .PeerpodV1alpha1 ().PeerpodVolumes (s .Namespace ).Delete (context .Background (), volumeID , metav1.DeleteOptions {})
124
125
if ppErr != nil {
125
- glog .Warning ("Failed to delete to Peerpodvolume by volumeID: %v, err: %v" , volumeID , ppErr .Error ())
126
+ glog .Warningf ("Failed to delete to Peerpodvolume by volumeID: %v, err: %v" , volumeID , ppErr .Error ())
126
127
} else {
127
128
glog .Infof ("The peerPodVolume is deleted, volumeID: %v" , volumeID )
128
129
}
@@ -179,15 +180,15 @@ func (s *ControllerService) ControllerPublishVolume(ctx context.Context, req *cs
179
180
savedPeerpodvolume .Spec .WrapperControllerPublishVolumeRes = string (resJsonString )
180
181
savedPeerpodvolume , err = s .PeerpodvolumeClient .PeerpodV1alpha1 ().PeerpodVolumes (s .Namespace ).Update (context .Background (), savedPeerpodvolume , metav1.UpdateOptions {})
181
182
if err != nil {
182
- glog .Error ("Error happens while Update PeerpodVolume in ControllerPublishVolume, err: %v" , err .Error ())
183
+ glog .Errorf ("Error happens while Update PeerpodVolume in ControllerPublishVolume, err: %v" , err .Error ())
183
184
return
184
185
}
185
186
savedPeerpodvolume .Status = v1alpha1.PeerpodVolumeStatus {
186
187
State : v1alpha1 .ControllerPublishVolumeCached ,
187
188
}
188
189
_ , err = s .PeerpodvolumeClient .PeerpodV1alpha1 ().PeerpodVolumes (s .Namespace ).UpdateStatus (context .Background (), savedPeerpodvolume , metav1.UpdateOptions {})
189
190
if err != nil {
190
- glog .Error ("Error happens while Update PeerpodVolume status to ControllerPublishVolumeCached, err: %v" , err .Error ())
191
+ glog .Errorf ("Error happens while Update PeerpodVolume status to ControllerPublishVolumeCached, err: %v" , err .Error ())
191
192
}
192
193
}
193
194
return
@@ -210,10 +211,11 @@ func (s *ControllerService) ControllerUnpublishVolume(ctx context.Context, req *
210
211
req .NodeId = savedPeerpodvolume .Spec .VMID
211
212
glog .Infof ("The modified ControllerUnpublishVolumeRequest is :%v" , req )
212
213
ctx := context .Background ()
213
- s .redirect (ctx , req , func (ctx context.Context , client csi.ControllerClient ) {
214
+ // TODO: error check
215
+ _ = s .redirect (ctx , req , func (ctx context.Context , client csi.ControllerClient ) {
214
216
response , err := client .ControllerUnpublishVolume (ctx , req )
215
217
if err != nil {
216
- glog .Error ("Failed to run ControllerUnpublishVolume with modified ControllerUnpublishVolume, err: %v" , err .Error ())
218
+ glog .Errorf ("Failed to run ControllerUnpublishVolume with modified ControllerUnpublishVolume, err: %v" , err .Error ())
217
219
} else {
218
220
glog .Infof ("The ControllerUnpublishVolumeResponse for peer pod is :%v" , response )
219
221
}
@@ -242,15 +244,15 @@ func (s *ControllerService) ControllerUnpublishVolume(ctx context.Context, req *
242
244
savedPeerpodvolume .Spec .WrapperNodeUnstageVolumeReq = ""
243
245
updatedSavedPeerpodvolume , err := s .PeerpodvolumeClient .PeerpodV1alpha1 ().PeerpodVolumes (s .Namespace ).Update (context .Background (), savedPeerpodvolume , metav1.UpdateOptions {})
244
246
if err != nil {
245
- glog .Error ("Error happens while clean PeerpodVolume specs, err: %v" , err .Error ())
247
+ glog .Errorf ("Error happens while clean PeerpodVolume specs, err: %v" , err .Error ())
246
248
}
247
249
248
250
updatedSavedPeerpodvolume .Status = v1alpha1.PeerpodVolumeStatus {
249
251
State : "" ,
250
252
}
251
253
_ , err = s .PeerpodvolumeClient .PeerpodV1alpha1 ().PeerpodVolumes (s .Namespace ).UpdateStatus (context .Background (), updatedSavedPeerpodvolume , metav1.UpdateOptions {})
252
254
if err != nil {
253
- glog .Error ("Error happens while Update PeerpodVolume status to ControllerUnpublishVolumeApplied, err: %v" , err .Error ())
255
+ glog .Errorf ("Error happens while Update PeerpodVolume status to ControllerUnpublishVolumeApplied, err: %v" , err .Error ())
254
256
}
255
257
256
258
res = & csi.ControllerUnpublishVolumeResponse {}
@@ -359,15 +361,16 @@ func (s *ControllerService) SyncHandler(peerPodVolume *peerpodvolumeV1alpha1.Pee
359
361
wrapperRequest := peerPodVolume .Spec .WrapperControllerPublishVolumeReq
360
362
var modifiedRequest csi.ControllerPublishVolumeRequest
361
363
if err := (& jsonpb.Unmarshaler {}).Unmarshal (bytes .NewReader ([]byte (wrapperRequest )), & modifiedRequest ); err != nil {
362
- glog .Error ("Failed to convert to ControllerPublishVolumeRequest, err: %v" , err .Error ())
364
+ glog .Errorf ("Failed to convert to ControllerPublishVolumeRequest, err: %v" , err .Error ())
363
365
} else {
364
366
modifiedRequest .NodeId = vsiID
365
367
glog .Infof ("The modified ControllerPublishVolumeRequest is :%v" , modifiedRequest )
366
368
ctx := context .Background ()
367
- s .redirect (ctx , modifiedRequest , func (ctx context.Context , client csi.ControllerClient ) {
369
+ // TODO: error check
370
+ _ = s .redirect (ctx , modifiedRequest , func (ctx context.Context , client csi.ControllerClient ) {
368
371
response , err := client .ControllerPublishVolume (ctx , & modifiedRequest )
369
372
if err != nil {
370
- glog .Error ("Failed to reproduce ControllerPublishVolume with modified ControllerPublishVolumeRequest, err: %v" , err .Error ())
373
+ glog .Errorf ("Failed to reproduce ControllerPublishVolume with modified ControllerPublishVolumeRequest, err: %v" , err .Error ())
371
374
} else {
372
375
glog .Infof ("The ControllerPublishVolumeResponse for peer pod is :%v" , response )
373
376
var resBuf bytes.Buffer
@@ -382,15 +385,15 @@ func (s *ControllerService) SyncHandler(peerPodVolume *peerpodvolumeV1alpha1.Pee
382
385
peerPodVolume .Spec .DevicePath = devicePath
383
386
updatedPeerPodVolume , err := s .PeerpodvolumeClient .PeerpodV1alpha1 ().PeerpodVolumes (s .Namespace ).Update (context .Background (), peerPodVolume , metav1.UpdateOptions {})
384
387
if err != nil {
385
- glog .Error ("Error happens while Update PeerpodVolume with ControllerPublishVolumeResponse for peer pod, err: %v" , err .Error ())
388
+ glog .Errorf ("Error happens while Update PeerpodVolume with ControllerPublishVolumeResponse for peer pod, err: %v" , err .Error ())
386
389
return
387
390
}
388
391
updatedPeerPodVolume .Status = v1alpha1.PeerpodVolumeStatus {
389
392
State : v1alpha1 .ControllerPublishVolumeApplied ,
390
393
}
391
394
_ , err = s .PeerpodvolumeClient .PeerpodV1alpha1 ().PeerpodVolumes (s .Namespace ).UpdateStatus (context .Background (), updatedPeerPodVolume , metav1.UpdateOptions {})
392
395
if err != nil {
393
- glog .Error ("Error happens while Update PeerpodVolume status to ControllerPublishVolumeApplied, err: %v" , err .Error ())
396
+ glog .Errorf ("Error happens while Update PeerpodVolume status to ControllerPublishVolumeApplied, err: %v" , err .Error ())
394
397
}
395
398
}
396
399
})
0 commit comments