11/*
2- Copyright 2024 The Kubernetes Authors.
2+ Copyright 2025 The Kubernetes Authors.
33
44Licensed under the Apache License, Version 2.0 (the "License");
55you may not use this file except in compliance with the License.
@@ -95,8 +95,10 @@ func (csiCS *CSIControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
9595 // Create copy of the requestedVolume
9696 tempReqVol := (* requestedVolume )
9797 // Mask VolumeEncryptionKey
98- tempReqVol .VolumeEncryptionKey = & provider.VolumeEncryptionKey {CRN : "********" }
99- ctxLogger .Info ("Volume request after masking encryption key" , zap .Reflect ("Volume" , tempReqVol ))
98+ if requestedVolume .VolumeEncryptionKey != nil {
99+ tempReqVol .VolumeEncryptionKey = & provider.VolumeEncryptionKey {CRN : "********" }
100+ }
101+ ctxLogger .Info ("Volume request" , zap .Reflect ("Volume" , tempReqVol ))
100102 }
101103
102104 if err != nil {
@@ -152,7 +154,7 @@ func (csiCS *CSIControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
152154 if providerError .RetrivalFailed == providerError .GetErrorType (err ) {
153155 return nil , commonError .GetCSIError (ctxLogger , commonError .ObjectNotFound , requestID , err , "creation" )
154156 }
155- return nil , commonError .GetCSIError (ctxLogger , commonError . InternalError , requestID , err , "creation" )
157+ return nil , commonError .GetCSIBackendError (ctxLogger , requestID , err )
156158 }
157159
158160 // return csi volume object
@@ -193,7 +195,7 @@ func (csiCS *CSIControllerServer) DeleteVolume(ctx context.Context, req *csi.Del
193195
194196 err = session .DeleteVolume (volume )
195197 if err != nil {
196- return nil , commonError .GetCSIError (ctxLogger , commonError . InternalError , requestID , err )
198+ return nil , commonError .GetCSIBackendError (ctxLogger , requestID , err )
197199 }
198200 return & csi.DeleteVolumeResponse {}, nil
199201}
@@ -263,7 +265,7 @@ func (csiCS *CSIControllerServer) ControllerPublishVolume(ctx context.Context, r
263265 if providerError .GetErrorType (err ) == providerError .NodeNotFound {
264266 return nil , commonError .GetCSIError (ctxLogger , commonError .ObjectNotFound , requestID , err )
265267 }
266- return nil , commonError .GetCSIError (ctxLogger , commonError . InternalError , requestID , err )
268+ return nil , commonError .GetCSIBackendError (ctxLogger , requestID , err )
267269 }
268270
269271 //Pass in the VPCVolumeAttachment ID for efficient retrival in WaitForAttachVolume()
@@ -274,7 +276,7 @@ func (csiCS *CSIControllerServer) ControllerPublishVolume(ctx context.Context, r
274276 response , err = sess .WaitForAttachVolume (volumeAttachmentReq )
275277 if err != nil {
276278 //retry gap is constant in the common lib i.e 10 seconds and number of retries are 4*Retry configure in the driver
277- return nil , commonError .GetCSIError (ctxLogger , commonError . InternalError , requestID , err )
279+ return nil , commonError .GetCSIBackendError (ctxLogger , requestID , err )
278280 }
279281
280282 ctxLogger .Info ("Attachment response" , zap .Reflect ("Response" , response ))
@@ -318,12 +320,12 @@ func (csiCS *CSIControllerServer) ControllerUnpublishVolume(ctx context.Context,
318320 }
319321 response , err := sess .DetachVolume (volumeAttachmentReq )
320322 if err != nil {
321- return nil , commonError .GetCSIError (ctxLogger , commonError . InternalError , requestID , err )
323+ return nil , commonError .GetCSIBackendError (ctxLogger , requestID , err )
322324 }
323325 err = sess .WaitForDetachVolume (volumeAttachmentReq )
324326 if err != nil {
325327 //retry gap is constant in the common lib i.e 10 seconds and number of retries are 4*Retry configure in the driver
326- return nil , commonError .GetCSIError (ctxLogger , commonError . InternalError , requestID , err )
328+ return nil , commonError .GetCSIBackendError (ctxLogger , requestID , err )
327329 }
328330 ctxLogger .Info ("Detach response" , zap .Reflect ("response" , response ))
329331 return & csi.ControllerUnpublishVolumeResponse {}, nil
@@ -357,7 +359,7 @@ func (csiCS *CSIControllerServer) ValidateVolumeCapabilities(ctx context.Context
357359 if providerError .RetrivalFailed == providerError .GetErrorType (err ) {
358360 return nil , commonError .GetCSIError (ctxLogger , commonError .ObjectNotFound , requestID , err , volumeID )
359361 }
360- return nil , commonError .GetCSIError (ctxLogger , commonError . InternalError , requestID , err )
362+ return nil , commonError .GetCSIBackendError (ctxLogger , requestID , err )
361363 }
362364
363365 // Setup Response
@@ -396,7 +398,7 @@ func (csiCS *CSIControllerServer) ListVolumes(ctx context.Context, req *csi.List
396398 } else if strings .Contains (errCode , "StartVolumeIDNotFound" ) {
397399 return nil , commonError .GetCSIError (ctxLogger , commonError .StartVolumeIDNotFound , requestID , err , req .StartingToken )
398400 }
399- return nil , commonError .GetCSIError (ctxLogger , commonError . ListVolumesFailed , requestID , err )
401+ return nil , commonError .GetCSIBackendError (ctxLogger , requestID , err )
400402 }
401403
402404 entries := []* csi.ListVolumesResponse_Entry {}
@@ -536,7 +538,7 @@ func (csiCS *CSIControllerServer) DeleteSnapshot(ctx context.Context, req *csi.D
536538 ctxLogger .Info ("Snapshot not found. Returning success without deletion..." )
537539 return & csi.DeleteSnapshotResponse {}, nil
538540 }
539- return nil , commonError .GetCSIError (ctxLogger , commonError . InternalError , requestID , err )
541+ return nil , commonError .GetCSIBackendError (ctxLogger , requestID , err )
540542 }
541543 return & csi.DeleteSnapshotResponse {}, nil
542544}
@@ -649,7 +651,7 @@ func (csiCS *CSIControllerServer) ControllerExpandVolume(ctx context.Context, re
649651 ctxLogger , requestID := utils .GetContextLogger (ctx , false )
650652 // populate requestID in the context
651653 _ = context .WithValue (ctx , provider .RequestID , requestID )
652-
654+ defer metrics . UpdateDurationFromStart ( ctxLogger , "ControllerExpandVolume" , time . Now ())
653655 ctxLogger .Info ("CSIControllerServer-ControllerExpandVolume" , zap .Reflect ("Request" , req ))
654656 volumeID := req .GetVolumeId ()
655657 capacity := req .GetCapacityRange ().GetRequiredBytes ()
@@ -668,7 +670,7 @@ func (csiCS *CSIControllerServer) ControllerExpandVolume(ctx context.Context, re
668670 // Volume not found
669671 if volDetail == nil && err == nil {
670672 return nil , commonError .GetCSIError (ctxLogger , commonError .ObjectNotFound , requestID , nil , volumeID )
671- } else if err != nil { // In case of other errors apart from volume not found
673+ } else if err != nil { // In case of other errors apart from volume not found
672674 return nil , commonError .GetCSIError (ctxLogger , commonError .InternalError , requestID , err )
673675 }
674676
@@ -678,7 +680,7 @@ func (csiCS *CSIControllerServer) ControllerExpandVolume(ctx context.Context, re
678680 }
679681 _ , err = session .ExpandVolume (volumeExpansionReq )
680682 if err != nil {
681- return nil , commonError .GetCSIError (ctxLogger , commonError . InternalError , requestID , err )
683+ return nil , commonError .GetCSIBackendError (ctxLogger , requestID , err )
682684 }
683685 return & csi.ControllerExpandVolumeResponse {CapacityBytes : capacity , NodeExpansionRequired : true }, nil
684686}
0 commit comments