Skip to content

Commit e2bf307

Browse files
Include the return code only if Backend has no ReturnCode (#226)
* Include the return code only if Backend has no ReturnCode Signed-off-by: Meetanshi-Gupta <[email protected]> * Reverting few changes as need to Include the return code only if Backend has no ReturnCode Signed-off-by: Meetanshi-Gupta <[email protected]> * error code changed to nclude the return code only if Backend has no ReturnCode Signed-off-by: Meetanshi-Gupta <[email protected]> * Error code changes done 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 8ce582c commit e2bf307

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
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2024 The Kubernetes Authors.
2+
Copyright 2025 The Kubernetes Authors.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you 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
}

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)