Skip to content

Commit 88bde26

Browse files
changes implemented to include the return code only if Backend has no ReturnCode (#227)
* changes implemented to include the return code only if Backend has no ReturnCode Signed-off-by: Meetanshi-Gupta <[email protected]> * changes reverted in case of GetProviderSession call Signed-off-by: Meetanshi-Gupta <[email protected]> * funct name fixed Signed-off-by: Meetanshi-Gupta <[email protected]> * changes reverted Signed-off-by: Meetanshi-Gupta <[email protected]> * changed ExpandVolume -> ControllerExpandVolume Signed-off-by: Meetanshi-Gupta <[email protected]> --------- Signed-off-by: Meetanshi-Gupta <[email protected]>
1 parent c2a8d71 commit 88bde26

File tree

7 files changed

+35
-26
lines changed

7 files changed

+35
-26
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.23.8
55
require (
66
github.com/IBM/ibm-csi-common v1.1.20
77
github.com/IBM/ibmcloud-volume-interface v1.2.12
8-
github.com/IBM/ibmcloud-volume-vpc v1.1.17
8+
github.com/IBM/ibmcloud-volume-vpc v1.1.18
99
github.com/IBM/secret-utils-lib v1.1.13
1010
github.com/container-storage-interface/spec v1.11.0
1111
github.com/golang/glog v1.2.4

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ github.com/IBM/ibm-csi-common v1.1.20 h1:83tWmb+39G/Mm4E9nZwn5/EL0SMcyEyLJDN6hAS
1010
github.com/IBM/ibm-csi-common v1.1.20/go.mod h1:z9U3OmpKN92eUVdhhdbrr5kAT3MPRT9xwr6MVltLBFI=
1111
github.com/IBM/ibmcloud-volume-interface v1.2.12 h1:ehj+EJ+bno4ZKKy5CQoxNaHdb92EfVQN/KAtSBkkLaU=
1212
github.com/IBM/ibmcloud-volume-interface v1.2.12/go.mod h1:q+ngxRIR206Vy6xGTT+7etk+wAViT2dYrDByw8mjFYk=
13-
github.com/IBM/ibmcloud-volume-vpc v1.1.17 h1:OcsqVCwmcrjLJN99haGJqLKfdhqpElZiD7iUShmwQOc=
14-
github.com/IBM/ibmcloud-volume-vpc v1.1.17/go.mod h1:U8/cDWZ9tp3uFMpbMDk6GGLTwJAcaPkpkFnT9Q6IwMs=
13+
github.com/IBM/ibmcloud-volume-vpc v1.1.18 h1:HpTjcDhqpSlIPOFhNVgaEsO2KZpqSpucsCxRn0Bg2AA=
14+
github.com/IBM/ibmcloud-volume-vpc v1.1.18/go.mod h1:U8/cDWZ9tp3uFMpbMDk6GGLTwJAcaPkpkFnT9Q6IwMs=
1515
github.com/IBM/secret-common-lib v1.1.12 h1:BvQvQU3Ft3qHRus8ZtDbd4kc2wd71uS5RXsgWAbal1Y=
1616
github.com/IBM/secret-common-lib v1.1.12/go.mod h1:CFoEVlgj15dV18gzBoV+UMB6BXKVRvZxmUsn3DKa7wY=
1717
github.com/IBM/secret-utils-lib v1.1.13 h1:osQPjQh16fx8N0fZiPeZyXCyPYtuB1VoV/3HAxZ+Ep4=

pkg/ibmcsidriver/controller.go

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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 {
@@ -145,7 +147,7 @@ func (csiCS *CSIControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
145147
if providerError.RetrivalFailed == providerError.GetErrorType(err) {
146148
return nil, commonError.GetCSIError(ctxLogger, commonError.ObjectNotFound, requestID, err, "creation")
147149
}
148-
return nil, commonError.GetCSIError(ctxLogger, commonError.InternalError, requestID, err, "creation")
150+
return nil, commonError.GetCSIBackendError(ctxLogger, requestID, err)
149151
}
150152

151153
// return csi volume object
@@ -186,7 +188,7 @@ func (csiCS *CSIControllerServer) DeleteVolume(ctx context.Context, req *csi.Del
186188

187189
err = session.DeleteVolume(volume)
188190
if err != nil {
189-
return nil, commonError.GetCSIError(ctxLogger, commonError.InternalError, requestID, err)
191+
return nil, commonError.GetCSIBackendError(ctxLogger, requestID, err)
190192
}
191193
return &csi.DeleteVolumeResponse{}, nil
192194
}
@@ -238,7 +240,7 @@ func (csiCS *CSIControllerServer) ControllerPublishVolume(ctx context.Context, r
238240
// Volume not found
239241
if volDetail == nil && err == nil {
240242
return nil, commonError.GetCSIError(ctxLogger, commonError.ObjectNotFound, requestID, nil, volumeID)
241-
} else if err != nil { // In case of other errors apart from volume not found
243+
} else if err != nil { // In case of other errors apart from volume not found
242244
return nil, commonError.GetCSIError(ctxLogger, commonError.InternalError, requestID, err)
243245
}
244246

@@ -256,7 +258,7 @@ func (csiCS *CSIControllerServer) ControllerPublishVolume(ctx context.Context, r
256258
if providerError.GetErrorType(err) == providerError.NodeNotFound {
257259
return nil, commonError.GetCSIError(ctxLogger, commonError.ObjectNotFound, requestID, err)
258260
}
259-
return nil, commonError.GetCSIError(ctxLogger, commonError.InternalError, requestID, err)
261+
return nil, commonError.GetCSIBackendError(ctxLogger, requestID, err)
260262
}
261263

262264
//Pass in the VPCVolumeAttachment ID for efficient retrival in WaitForAttachVolume()
@@ -267,7 +269,7 @@ func (csiCS *CSIControllerServer) ControllerPublishVolume(ctx context.Context, r
267269
response, err = sess.WaitForAttachVolume(volumeAttachmentReq)
268270
if err != nil {
269271
//retry gap is constant in the common lib i.e 10 seconds and number of retries are 4*Retry configure in the driver
270-
return nil, commonError.GetCSIError(ctxLogger, commonError.InternalError, requestID, err)
272+
return nil, commonError.GetCSIBackendError(ctxLogger, requestID, err)
271273
}
272274

273275
ctxLogger.Info("Attachment response", zap.Reflect("Response", response))
@@ -311,12 +313,12 @@ func (csiCS *CSIControllerServer) ControllerUnpublishVolume(ctx context.Context,
311313
}
312314
response, err := sess.DetachVolume(volumeAttachmentReq)
313315
if err != nil {
314-
return nil, commonError.GetCSIError(ctxLogger, commonError.InternalError, requestID, err)
316+
return nil, commonError.GetCSIBackendError(ctxLogger, requestID, err)
315317
}
316318
err = sess.WaitForDetachVolume(volumeAttachmentReq)
317319
if err != nil {
318320
//retry gap is constant in the common lib i.e 10 seconds and number of retries are 4*Retry configure in the driver
319-
return nil, commonError.GetCSIError(ctxLogger, commonError.InternalError, requestID, err)
321+
return nil, commonError.GetCSIBackendError(ctxLogger, requestID, err)
320322
}
321323
ctxLogger.Info("Detach response", zap.Reflect("response", response))
322324
return &csi.ControllerUnpublishVolumeResponse{}, nil
@@ -350,7 +352,7 @@ func (csiCS *CSIControllerServer) ValidateVolumeCapabilities(ctx context.Context
350352
if providerError.RetrivalFailed == providerError.GetErrorType(err) {
351353
return nil, commonError.GetCSIError(ctxLogger, commonError.ObjectNotFound, requestID, err, volumeID)
352354
}
353-
return nil, commonError.GetCSIError(ctxLogger, commonError.InternalError, requestID, err)
355+
return nil, commonError.GetCSIBackendError(ctxLogger, requestID, err)
354356
}
355357

356358
// Setup Response
@@ -389,7 +391,7 @@ func (csiCS *CSIControllerServer) ListVolumes(ctx context.Context, req *csi.List
389391
} else if strings.Contains(errCode, "StartVolumeIDNotFound") {
390392
return nil, commonError.GetCSIError(ctxLogger, commonError.StartVolumeIDNotFound, requestID, err, req.StartingToken)
391393
}
392-
return nil, commonError.GetCSIError(ctxLogger, commonError.ListVolumesFailed, requestID, err)
394+
return nil, commonError.GetCSIBackendError(ctxLogger, requestID, err)
393395
}
394396

395397
entries := []*csi.ListVolumesResponse_Entry{}
@@ -528,7 +530,7 @@ func (csiCS *CSIControllerServer) DeleteSnapshot(ctx context.Context, req *csi.D
528530
ctxLogger.Info("Snapshot not found. Returning success without deletion...")
529531
return &csi.DeleteSnapshotResponse{}, nil
530532
}
531-
return nil, commonError.GetCSIError(ctxLogger, commonError.InternalError, requestID, err)
533+
return nil, commonError.GetCSIBackendError(ctxLogger, requestID, err)
532534
}
533535
return &csi.DeleteSnapshotResponse{}, nil
534536
}
@@ -626,7 +628,7 @@ func (csiCS *CSIControllerServer) ControllerExpandVolume(ctx context.Context, re
626628
ctxLogger, requestID := utils.GetContextLogger(ctx, false)
627629
// populate requestID in the context
628630
_ = context.WithValue(ctx, provider.RequestID, requestID)
629-
631+
defer metrics.UpdateDurationFromStart(ctxLogger, "ControllerExpandVolume", time.Now())
630632
ctxLogger.Info("CSIControllerServer-ControllerExpandVolume", zap.Reflect("Request", req))
631633
volumeID := req.GetVolumeId()
632634
capacity := req.GetCapacityRange().GetRequiredBytes()
@@ -645,7 +647,7 @@ func (csiCS *CSIControllerServer) ControllerExpandVolume(ctx context.Context, re
645647
// Volume not found
646648
if volDetail == nil && err == nil {
647649
return nil, commonError.GetCSIError(ctxLogger, commonError.ObjectNotFound, requestID, nil, volumeID)
648-
} else if err != nil { // In case of other errors apart from volume not found
650+
} else if err != nil { // In case of other errors apart from volume not found
649651
return nil, commonError.GetCSIError(ctxLogger, commonError.InternalError, requestID, err)
650652
}
651653

@@ -655,7 +657,7 @@ func (csiCS *CSIControllerServer) ControllerExpandVolume(ctx context.Context, re
655657
}
656658
_, err = session.ExpandVolume(volumeExpansionReq)
657659
if err != nil {
658-
return nil, commonError.GetCSIError(ctxLogger, commonError.InternalError, requestID, err)
660+
return nil, commonError.GetCSIBackendError(ctxLogger, requestID, err)
659661
}
660662
return &csi.ControllerExpandVolumeResponse{CapacityBytes: capacity, NodeExpansionRequired: true}, nil
661663
}

pkg/ibmcsidriver/controller_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ limitations under the License.
1818
package ibmcsidriver
1919

2020
import (
21+
"errors"
2122
"fmt"
2223
"net/http"
2324
"reflect"
@@ -170,7 +171,7 @@ func TestCreateVolumeArguments(t *testing.T) {
170171
expErrCode: codes.Internal,
171172
expVol: nil,
172173
libVolumeResponse: nil,
173-
libVolumeError: providerError.Message{Code: "FailedToPlaceOrder", Description: "Volume creation failed", Type: providerError.ProvisioningFailed},
174+
libVolumeError: errors.New("Trace Code: a0e1e74b-4686-42df-8663-5634fe0d3241, Code: InternalError , Description: Create Volume Failed, RC: 500 Internal Error"),
174175
},
175176
{
176177
name: "InvalidRequest lib error form create volume",
@@ -180,10 +181,10 @@ func TestCreateVolumeArguments(t *testing.T) {
180181
VolumeCapabilities: stdVolCap,
181182
Parameters: stdParams,
182183
},
183-
expErrCode: codes.Internal,
184+
expErrCode: codes.InvalidArgument,
184185
expVol: nil,
185186
libVolumeResponse: nil,
186-
libVolumeError: providerError.Message{Code: "FailedToPlaceOrder", Description: "Volume creation failed", Type: providerError.InvalidRequest},
187+
libVolumeError: errors.New("Trace Code: a0e1e74b-4686-42df-8663-5634fe0d3241, Code: InvalidArgument , Description: Volume creation failed, RC: 400 Bad Request"),
187188
},
188189
{
189190
name: "Other error lib error form create volume",
@@ -193,10 +194,10 @@ func TestCreateVolumeArguments(t *testing.T) {
193194
VolumeCapabilities: stdVolCap,
194195
Parameters: stdParams,
195196
},
196-
expErrCode: codes.Internal,
197+
expErrCode: codes.InvalidArgument,
197198
expVol: nil,
198199
libVolumeResponse: nil,
199-
libVolumeError: providerError.Message{Code: "FailedToPlaceOrder", Description: "Volume creation failed", Type: providerError.Unauthenticated},
200+
libVolumeError: errors.New("Trace Code: a0e1e74b-4686-42df-8663-5634fe0d3241, Code: InvalidArgument , Description: Volume creation failed, RC: 400 Bad Request"),
200201
},
201202
{
202203
name: "Zone provided but region not provided as parameter",

vendor/github.com/IBM/ibmcloud-volume-vpc/common/vpcclient/client/request.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/IBM/ibmcloud-volume-vpc/common/vpcclient/models/error.go

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/modules.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ github.com/IBM/ibmcloud-volume-interface/lib/utils/reasoncode
2727
github.com/IBM/ibmcloud-volume-interface/provider/auth
2828
github.com/IBM/ibmcloud-volume-interface/provider/iam
2929
github.com/IBM/ibmcloud-volume-interface/provider/local
30-
# github.com/IBM/ibmcloud-volume-vpc v1.1.17
30+
# github.com/IBM/ibmcloud-volume-vpc v1.1.18
3131
## explicit; go 1.23.8
3232
github.com/IBM/ibmcloud-volume-vpc/block/provider
3333
github.com/IBM/ibmcloud-volume-vpc/block/utils

0 commit comments

Comments
 (0)