@@ -17,7 +17,6 @@ limitations under the License.
1717package cinder
1818
1919import (
20- "fmt"
2120 "strconv"
2221
2322 "github.com/container-storage-interface/spec/lib/go/csi"
@@ -86,7 +85,7 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
8685 volumes , err := cloud .GetVolumesByName (volName )
8786 if err != nil {
8887 klog .Errorf ("Failed to query for existing Volume during CreateVolume: %v" , err )
89- return nil , status .Error (codes .Internal , fmt . Sprintf ( "Failed to get volumes: %s " , err ) )
88+ return nil , status .Errorf (codes .Internal , "Failed to get volumes: %v " , err )
9089 }
9190
9291 if len (volumes ) == 1 {
@@ -139,7 +138,7 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
139138
140139 if err != nil {
141140 klog .Errorf ("Failed to CreateVolume: %v" , err )
142- return nil , status .Error (codes .Internal , fmt . Sprintf ( "CreateVolume failed with error %v" , err ) )
141+ return nil , status .Errorf (codes .Internal , "CreateVolume failed with error %v" , err )
143142
144143 }
145144
@@ -163,7 +162,7 @@ func (cs *controllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVol
163162 return & csi.DeleteVolumeResponse {}, nil
164163 }
165164 klog .Errorf ("Failed to DeleteVolume: %v" , err )
166- return nil , status .Error (codes .Internal , fmt . Sprintf ( "DeleteVolume failed with error %v" , err ) )
165+ return nil , status .Errorf (codes .Internal , "DeleteVolume failed with error %v" , err )
167166 }
168167
169168 klog .V (4 ).Infof ("DeleteVolume: Successfully deleted volume %s" , volID )
@@ -194,34 +193,34 @@ func (cs *controllerServer) ControllerPublishVolume(ctx context.Context, req *cs
194193 if cpoerrors .IsNotFound (err ) {
195194 return nil , status .Errorf (codes .NotFound , "[ControllerPublishVolume] Volume %s not found" , volumeID )
196195 }
197- return nil , status .Error (codes .Internal , fmt . Sprintf ( "[ControllerPublishVolume] get volume failed with error %v" , err ) )
196+ return nil , status .Errorf (codes .Internal , "[ControllerPublishVolume] get volume failed with error %v" , err )
198197 }
199198
200199 _ , err = cs .Cloud .GetInstanceByID (instanceID )
201200 if err != nil {
202201 if cpoerrors .IsNotFound (err ) {
203202 return nil , status .Errorf (codes .NotFound , "[ControllerPublishVolume] Instance %s not found" , instanceID )
204203 }
205- return nil , status .Error (codes .Internal , fmt . Sprintf ( "[ControllerPublishVolume] GetInstanceByID failed with error %v" , err ) )
204+ return nil , status .Errorf (codes .Internal , "[ControllerPublishVolume] GetInstanceByID failed with error %v" , err )
206205 }
207206
208207 _ , err = cs .Cloud .AttachVolume (instanceID , volumeID )
209208 if err != nil {
210209 klog .Errorf ("Failed to AttachVolume: %v" , err )
211- return nil , status .Error (codes .Internal , fmt . Sprintf ( "[ControllerPublishVolume] Attach Volume failed with error %v" , err ) )
210+ return nil , status .Errorf (codes .Internal , "[ControllerPublishVolume] Attach Volume failed with error %v" , err )
212211
213212 }
214213
215214 err = cs .Cloud .WaitDiskAttached (instanceID , volumeID )
216215 if err != nil {
217216 klog .Errorf ("Failed to WaitDiskAttached: %v" , err )
218- return nil , status .Error (codes .Internal , fmt . Sprintf ( "[ControllerPublishVolume] failed to attach volume: %v" , err ) )
217+ return nil , status .Errorf (codes .Internal , "[ControllerPublishVolume] failed to attach volume: %v" , err )
219218 }
220219
221220 devicePath , err := cs .Cloud .GetAttachmentDiskPath (instanceID , volumeID )
222221 if err != nil {
223222 klog .Errorf ("Failed to GetAttachmentDiskPath: %v" , err )
224- return nil , status .Error (codes .Internal , fmt . Sprintf ( "[ControllerPublishVolume] failed to get device path of attached volume : %v" , err ) )
223+ return nil , status .Errorf (codes .Internal , "[ControllerPublishVolume] failed to get device path of attached volume: %v" , err )
225224 }
226225
227226 klog .V (4 ).Infof ("ControllerPublishVolume %s on %s is successful" , volumeID , instanceID )
@@ -251,7 +250,7 @@ func (cs *controllerServer) ControllerUnpublishVolume(ctx context.Context, req *
251250 klog .V (3 ).Infof ("ControllerUnpublishVolume assuming volume %s is detached, because node %s does not exist" , volumeID , instanceID )
252251 return & csi.ControllerUnpublishVolumeResponse {}, nil
253252 }
254- return nil , status .Error (codes .Internal , fmt . Sprintf ( "[ControllerUnpublishVolume] GetInstanceByID failed with error %v" , err ) )
253+ return nil , status .Errorf (codes .Internal , "[ControllerUnpublishVolume] GetInstanceByID failed with error %v" , err )
255254 }
256255
257256 err = cs .Cloud .DetachVolume (instanceID , volumeID )
@@ -261,7 +260,7 @@ func (cs *controllerServer) ControllerUnpublishVolume(ctx context.Context, req *
261260 return & csi.ControllerUnpublishVolumeResponse {}, nil
262261 }
263262 klog .Errorf ("Failed to DetachVolume: %v" , err )
264- return nil , status .Error (codes .Internal , fmt . Sprintf ( "ControllerUnpublishVolume Detach Volume failed with error %v" , err ) )
263+ return nil , status .Errorf (codes .Internal , "ControllerUnpublishVolume Detach Volume failed with error %v" , err )
265264 }
266265
267266 err = cs .Cloud .WaitDiskDetached (instanceID , volumeID )
@@ -271,7 +270,7 @@ func (cs *controllerServer) ControllerUnpublishVolume(ctx context.Context, req *
271270 klog .V (3 ).Infof ("ControllerUnpublishVolume assuming volume %s is detached, because it was deleted in the meanwhile" , volumeID )
272271 return & csi.ControllerUnpublishVolumeResponse {}, nil
273272 }
274- return nil , status .Error (codes .Internal , fmt . Sprintf ( "ControllerUnpublishVolume failed with error %v" , err ) )
273+ return nil , status .Errorf (codes .Internal , "ControllerUnpublishVolume failed with error %v" , err )
275274 }
276275
277276 klog .V (4 ).Infof ("ControllerUnpublishVolume %s on %s" , volumeID , instanceID )
@@ -283,8 +282,7 @@ func (cs *controllerServer) ListVolumes(ctx context.Context, req *csi.ListVolume
283282 klog .V (4 ).Infof ("ListVolumes: called with %+#v request" , req )
284283
285284 if req .MaxEntries < 0 {
286- return nil , status .Error (codes .InvalidArgument , fmt .Sprintf (
287- "[ListVolumes] Invalid max entries request %v, must not be negative " , req .MaxEntries ))
285+ return nil , status .Errorf (codes .InvalidArgument , "[ListVolumes] Invalid max entries request %v, must not be negative " , req .MaxEntries )
288286 }
289287 maxEntries := int (req .MaxEntries )
290288
@@ -294,7 +292,7 @@ func (cs *controllerServer) ListVolumes(ctx context.Context, req *csi.ListVolume
294292 if cpoerrors .IsInvalidError (err ) {
295293 return nil , status .Errorf (codes .Aborted , "[ListVolumes] Invalid request: %v" , err )
296294 }
297- return nil , status .Error (codes .Internal , fmt . Sprintf ( "ListVolumes failed with error %v" , err ) )
295+ return nil , status .Errorf (codes .Internal , "ListVolumes failed with error %v" , err )
298296 }
299297
300298 ventries := make ([]* csi.ListVolumesResponse_Entry , 0 , len (vlist ))
@@ -378,7 +376,7 @@ func (cs *controllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS
378376 snap , err = cs .Cloud .CreateSnapshot (name , volumeID , & properties )
379377 if err != nil {
380378 klog .Errorf ("Failed to Create snapshot: %v" , err )
381- return nil , status .Error (codes .Internal , fmt . Sprintf ( "CreateSnapshot failed with error %v" , err ) )
379+ return nil , status .Errorf (codes .Internal , "CreateSnapshot failed with error %v" , err )
382380 }
383381
384382 klog .V (3 ).Infof ("CreateSnapshot %s from volume with ID: %s" , name , volumeID )
@@ -392,7 +390,7 @@ func (cs *controllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS
392390 err = cs .Cloud .WaitSnapshotReady (snap .ID )
393391 if err != nil {
394392 klog .Errorf ("Failed to WaitSnapshotReady: %v" , err )
395- return nil , status .Error (codes .Internal , fmt . Sprintf ( "CreateSnapshot failed with error %v" , err ) )
393+ return nil , status .Errorf (codes .Internal , "CreateSnapshot failed with error %v" , err )
396394 }
397395
398396 return & csi.CreateSnapshotResponse {
@@ -423,7 +421,7 @@ func (cs *controllerServer) DeleteSnapshot(ctx context.Context, req *csi.DeleteS
423421 return & csi.DeleteSnapshotResponse {}, nil
424422 }
425423 klog .Errorf ("Failed to Delete snapshot: %v" , err )
426- return nil , status .Error (codes .Internal , fmt . Sprintf ( "DeleteSnapshot failed with error %v" , err ) )
424+ return nil , status .Errorf (codes .Internal , "DeleteSnapshot failed with error %v" , err )
427425 }
428426 return & csi.DeleteSnapshotResponse {}, nil
429427}
@@ -438,7 +436,7 @@ func (cs *controllerServer) ListSnapshots(ctx context.Context, req *csi.ListSnap
438436 klog .V (3 ).Infof ("Snapshot %s not found" , snapshotID )
439437 return & csi.ListSnapshotsResponse {}, nil
440438 }
441- return nil , status .Errorf (codes .Internal , "Failed to GetSnapshot %s : %v" , snapshotID , err )
439+ return nil , status .Errorf (codes .Internal , "Failed to GetSnapshot %s: %v" , snapshotID , err )
442440 }
443441
444442 ctime := timestamppb .New (snap .CreatedAt )
@@ -532,9 +530,9 @@ func (cs *controllerServer) ValidateVolumeCapabilities(ctx context.Context, req
532530 _ , err := cs .Cloud .GetVolume (volumeID )
533531 if err != nil {
534532 if cpoerrors .IsNotFound (err ) {
535- return nil , status .Error (codes .NotFound , fmt . Sprintf ( "ValidateVolumeCapabiltites Volume %s not found" , volumeID ) )
533+ return nil , status .Errorf (codes .NotFound , "ValidateVolumeCapabiltites Volume %s not found" , volumeID )
536534 }
537- return nil , status .Error (codes .Internal , fmt . Sprintf ( "ValidateVolumeCapabiltites %v" , err ) )
535+ return nil , status .Errorf (codes .Internal , "ValidateVolumeCapabiltites %v" , err )
538536 }
539537
540538 for _ , cap := range reqVolCap {
@@ -575,7 +573,7 @@ func (cs *controllerServer) ControllerGetVolume(ctx context.Context, req *csi.Co
575573 if cpoerrors .IsNotFound (err ) {
576574 return nil , status .Errorf (codes .NotFound , "Volume %s not found" , volumeID )
577575 }
578- return nil , status .Error (codes .Internal , fmt . Sprintf ( "ControllerGetVolume failed with error %v" , err ) )
576+ return nil , status .Errorf (codes .Internal , "ControllerGetVolume failed with error %v" , err )
579577 }
580578
581579 ventry := csi.ControllerGetVolumeResponse {
@@ -620,7 +618,7 @@ func (cs *controllerServer) ControllerExpandVolume(ctx context.Context, req *csi
620618 if cpoerrors .IsNotFound (err ) {
621619 return nil , status .Error (codes .NotFound , "Volume not found" )
622620 }
623- return nil , status .Error (codes .Internal , fmt . Sprintf ( "GetVolume failed with error %v" , err ) )
621+ return nil , status .Errorf (codes .Internal , "GetVolume failed with error %v" , err )
624622 }
625623
626624 if volume .Size >= volSizeGB {
@@ -634,15 +632,15 @@ func (cs *controllerServer) ControllerExpandVolume(ctx context.Context, req *csi
634632
635633 err = cs .Cloud .ExpandVolume (volumeID , volume .Status , volSizeGB )
636634 if err != nil {
637- return nil , status .Errorf (codes .Internal , fmt . Sprintf ( "Could not resize volume %q to size %v: %v" , volumeID , volSizeGB , err ) )
635+ return nil , status .Errorf (codes .Internal , "Could not resize volume %q to size %v: %v" , volumeID , volSizeGB , err )
638636 }
639637
640638 // we need wait for the volume to be available or InUse, it might be error_extending in some scenario
641639 targetStatus := []string {openstack .VolumeAvailableStatus , openstack .VolumeInUseStatus }
642640 err = cs .Cloud .WaitVolumeTargetStatus (volumeID , targetStatus )
643641 if err != nil {
644642 klog .Errorf ("Failed to WaitVolumeTargetStatus of volume %s: %v" , volumeID , err )
645- return nil , status .Error (codes .Internal , fmt . Sprintf ( "[ControllerExpandVolume] Volume %s not in target state after resize operation : %v" , volumeID , err ) )
643+ return nil , status .Errorf (codes .Internal , "[ControllerExpandVolume] Volume %s not in target state after resize operation: %v" , volumeID , err )
646644 }
647645
648646 klog .V (4 ).Infof ("ControllerExpandVolume resized volume %v to size %v" , volumeID , volSizeGB )
0 commit comments