diff --git a/pkg/cloud_provider/file/file.go b/pkg/cloud_provider/file/file.go index 4f542c72e..6dd3a5628 100644 --- a/pkg/cloud_provider/file/file.go +++ b/pkg/cloud_provider/file/file.go @@ -625,8 +625,8 @@ func GetInstanceNameFromURI(uri string) (project, location, name string, err err } func IsNotFoundErr(err error) bool { - apiErr, ok := err.(*googleapi.Error) - if !ok { + var apiErr *googleapi.Error + if !errors.As(err, &apiErr) { return false } @@ -718,7 +718,7 @@ func existingErrorCode(err error) *codes.Code { return nil } -// CodeForError returns a pointer to the grpc error code that maps to the http +// codeForError returns a pointer to the grpc error code that maps to the http // error code for the passed in user googleapi error or context error. Returns // codes.Internal if the given error is not a googleapi error caused by the user. // The following http error codes are considered user errors: @@ -729,7 +729,10 @@ func existingErrorCode(err error) *codes.Code { // The following errors are considered context errors: // (1) "context deadline exceeded", returns grpc DeadlineExceeded, // (2) "context canceled", returns grpc Canceled -func CodeForError(err error) *codes.Code { +func codeForError(err error) *codes.Code { + if err == nil { + return nil + } if errCode := existingErrorCode(err); errCode != nil { return errCode } @@ -743,6 +746,15 @@ func CodeForError(err error) *codes.Code { return util.ErrCodePtr(codes.Internal) } +// Status error returns the error as a grpc status error, and +// sets the grpc error code according to CodeForError. +func StatusError(err error) error { + if err == nil { + return nil + } + return status.Error(*codeForError(err), err.Error()) +} + // This function returns the backup URI, the region that was picked to be the backup resource location and error. func CreateBackupURI(obj *ServiceInstance, backupName string, backupLocation string) (string, string, error) { region, err := deduceRegion(obj, backupLocation) diff --git a/pkg/cloud_provider/file/file_test.go b/pkg/cloud_provider/file/file_test.go index 799a32468..914e7fb66 100644 --- a/pkg/cloud_provider/file/file_test.go +++ b/pkg/cloud_provider/file/file_test.go @@ -581,10 +581,15 @@ func TestCodeForError(t *testing.T) { err: status.Error(codes.Aborted, "aborted error"), expectedErrCode: util.ErrCodePtr(codes.Aborted), }, + { + name: "nil error", + err: nil, + expectedErrCode: nil, + }, } for _, test := range cases { - errCode := CodeForError(test.err) + errCode := codeForError(test.err) if (test.expectedErrCode == nil) != (errCode == nil) { t.Errorf("test %v failed: got %v, expected %v", test.name, errCode, test.expectedErrCode) } @@ -594,6 +599,32 @@ func TestCodeForError(t *testing.T) { } } +func TestStatusError(t *testing.T) { + cases := []struct { + name string + err error + expectedErr error + }{ + { + name: "404 googleapi error", + err: &googleapi.Error{Code: http.StatusNotFound}, + expectedErr: status.Error(codes.NotFound, ""), + }, + { + name: "nil error", + err: nil, + expectedErr: nil, + }, + } + + for _, test := range cases { + err := StatusError(test.err) + if (test.expectedErr == nil) != (err == nil) { + t.Errorf("test %v failed: got %v, expected %v", test.name, err, test.expectedErr) + } + } +} + func TestIsUserError(t *testing.T) { cases := []struct { name string diff --git a/pkg/csi_driver/controller.go b/pkg/csi_driver/controller.go index 8e03ef252..1ae0736db 100644 --- a/pkg/csi_driver/controller.go +++ b/pkg/csi_driver/controller.go @@ -213,7 +213,7 @@ func (s *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVolu _, err = s.config.fileService.GetBackup(ctx, id) if err != nil { klog.Errorf("Failed to get volume %v source snapshot %v: %v", name, id, err.Error()) - return nil, status.Error(*file.CodeForError(err), err.Error()) + return nil, file.StatusError(err) } sourceSnapshotId = id } @@ -223,7 +223,7 @@ func (s *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVolu filer, err := s.config.fileService.GetInstance(ctx, newFiler) // No error is returned if the instance is not found during CreateVolume. if err != nil && !file.IsNotFoundErr(err) { - return nil, status.Error(*file.CodeForError(err), err.Error()) + return nil, file.StatusError(err) } if filer != nil { @@ -262,7 +262,7 @@ func (s *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVolu // In case of abort, the CIDR IP is released and available for reservation defer s.config.ipAllocator.ReleaseIPRange(reservedIPRange) if err != nil { - return nil, err + return nil, file.StatusError(err) } // Adding the reserved IP range to the instance object @@ -272,7 +272,7 @@ func (s *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVolu // Add labels. labels, err := extractLabels(param, s.config.driver.config.Name) if err != nil { - return nil, err + return nil, file.StatusError(err) } newFiler.Labels = labels @@ -285,7 +285,7 @@ func (s *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVolu } if createErr != nil { klog.Errorf("Create volume for volume Id %s failed: %v", volumeID, createErr.Error()) - return nil, status.Error(*file.CodeForError(createErr), createErr.Error()) + return nil, file.StatusError(createErr) } } resp := &csi.CreateVolumeResponse{Volume: s.fileInstanceToCSIVolume(filer, modeInstance, sourceSnapshotId)} @@ -364,7 +364,10 @@ func (s *controllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVolu duration := time.Since(start) s.config.metricsManager.RecordOperationMetrics(err, methodDeleteVolume, modeMultishare, duration) klog.Infof("Deletevolume response %+v error %v, for request: %+v", response, err, req) - return response, err + if err != nil { + return response, file.StatusError(err) + } + return response, nil } filer, _, err := getFileInstanceFromID(volumeID) @@ -385,7 +388,7 @@ func (s *controllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVolu if file.IsNotFoundErr(err) { return &csi.DeleteVolumeResponse{}, nil } - return nil, status.Error(*file.CodeForError(err), err.Error()) + return nil, file.StatusError(err) } if filer.State == "DELETING" { @@ -395,7 +398,7 @@ func (s *controllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVolu err = s.config.fileService.DeleteInstance(ctx, filer) if err != nil { klog.Errorf("Delete volume for volume Id %s failed: %v", volumeID, err.Error()) - return nil, status.Error(*file.CodeForError(err), err.Error()) + return nil, file.StatusError(err) } klog.Infof("DeleteVolume succeeded for volume %v", volumeID) @@ -422,7 +425,7 @@ func (s *controllerServer) ValidateVolumeCapabilities(ctx context.Context, req * filer.Project = s.config.cloud.Project newFiler, err := s.config.fileService.GetInstance(ctx, filer) if err != nil && !file.IsNotFoundErr(err) { - return nil, status.Error(*file.CodeForError(err), err.Error()) + return nil, file.StatusError(err) } if newFiler == nil { return nil, status.Errorf(codes.NotFound, "volume %v doesn't exist", volumeID) @@ -682,7 +685,7 @@ func (s *controllerServer) ControllerExpandVolume(ctx context.Context, req *csi. filer.Project = s.config.cloud.Project filer, err = s.config.fileService.GetInstance(ctx, filer) if err != nil { - return nil, status.Error(*file.CodeForError(err), err.Error()) + return nil, file.StatusError(err) } if filer.State != "READY" { return nil, fmt.Errorf("lolume %q is not yet ready, current state %q", volumeID, filer.State) @@ -698,7 +701,7 @@ func (s *controllerServer) ControllerExpandVolume(ctx context.Context, req *csi. hasPendingOps, err := s.config.fileService.HasOperations(ctx, filer, "update", false /* done */) if err != nil { - return nil, status.Error(*file.CodeForError(err), err.Error()) + return nil, file.StatusError(err) } if hasPendingOps { @@ -708,7 +711,7 @@ func (s *controllerServer) ControllerExpandVolume(ctx context.Context, req *csi. filer.Volume.SizeBytes = reqBytes newfiler, err := s.config.fileService.ResizeInstance(ctx, filer) if err != nil { - return nil, status.Error(*file.CodeForError(err), err.Error()) + return nil, file.StatusError(err) } klog.Infof("Controller expand volume succeeded for volume %v, new size(bytes): %v", volumeID, newfiler.Volume.SizeBytes) @@ -877,12 +880,12 @@ func (s *controllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateSn backupInfo, err := s.config.fileService.GetBackup(ctx, backupUri) if err != nil { if !file.IsNotFoundErr(err) { - return nil, status.Error(*file.CodeForError(err), err.Error()) + return nil, file.StatusError(err) } } else { backupSourceCSIHandle, err := util.BackupVolumeSourceToCSIVolumeHandle(backupInfo.SourceInstance, backupInfo.SourceShare) if err != nil { - return nil, status.Errorf(codes.Internal, "Cannot determine volume handle from back source instance %s, share %s", backupInfo.SourceInstance, backupInfo.SourceShare) + return nil, status.Errorf(codes.InvalidArgument, "Cannot determine volume handle from back source instance %s, share %s", backupInfo.SourceInstance, backupInfo.SourceShare) } if backupSourceCSIHandle != volumeID { return nil, status.Errorf(codes.AlreadyExists, "Backup already exists with a different source volume %s, input source volume %s", backupSourceCSIHandle, volumeID) @@ -896,7 +899,8 @@ func (s *controllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateSn } tp, err := util.ParseTimestamp(backupInfo.Backup.CreateTime) if err != nil { - return nil, status.Errorf(codes.Internal, "failed to parse create timestamp for backup %v", backupInfo.Backup.Name) + err = fmt.Errorf("failed to parse create timestamp for backup %v: %w", backupInfo.Backup.Name, err) + return nil, file.StatusError(err) } klog.V(4).Infof("CreateSnapshot success for volume %v, Backup Id: %v", volumeID, backupInfo.Backup.Name) return &csi.CreateSnapshotResponse{ @@ -913,13 +917,11 @@ func (s *controllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateSn backupObj, err := s.config.fileService.CreateBackup(ctx, filer, req.Name, util.GetBackupLocation(req.GetParameters())) if err != nil { klog.Errorf("Create snapshot for volume Id %s failed: %v", volumeID, err.Error()) - if err != nil { - return nil, status.Error(*file.CodeForError(err), err.Error()) - } + return nil, file.StatusError(err) } tp, err := util.ParseTimestamp(backupObj.CreateTime) if err != nil { - return nil, status.Error(codes.Internal, err.Error()) + return nil, file.StatusError(err) } resp := &csi.CreateSnapshotResponse{ Snapshot: &csi.Snapshot{ @@ -958,7 +960,7 @@ func (s *controllerServer) DeleteSnapshot(ctx context.Context, req *csi.DeleteSn klog.Infof("Volume snapshot with ID %v not found", id) return &csi.DeleteSnapshotResponse{}, nil } - return nil, status.Error(*file.CodeForError(err), err.Error()) + return nil, file.StatusError(err) } if backupInfo.Backup.State == "DELETING" { @@ -967,7 +969,7 @@ func (s *controllerServer) DeleteSnapshot(ctx context.Context, req *csi.DeleteSn if err = s.config.fileService.DeleteBackup(ctx, id); err != nil { klog.Errorf("Delete snapshot for backup Id %s failed: %v", id, err.Error()) - return nil, status.Error(*file.CodeForError(err), err.Error()) + return nil, file.StatusError(err) } return &csi.DeleteSnapshotResponse{}, nil diff --git a/pkg/csi_driver/multishare_controller.go b/pkg/csi_driver/multishare_controller.go index 14f65c0a7..61adb6948 100644 --- a/pkg/csi_driver/multishare_controller.go +++ b/pkg/csi_driver/multishare_controller.go @@ -156,7 +156,7 @@ func (m *MultishareController) CreateVolume(ctx context.Context, req *csi.Create // If no eligible instance found, the ops manager may decide to create a new instance. Prepare a multishare instacne object for such a scenario. instance, err := m.generateNewMultishareInstance(util.NewMultishareInstancePrefix+string(uuid.NewUUID()), req, maxSharesPerInstance) if err != nil { - return nil, err + return nil, file.StatusError(err) } if m.featureMaxSharePerInstance && m.descOverrideMaxSharesPerInstance != "" && m.descOverrideMinShareSizeBytes != "" { @@ -173,22 +173,24 @@ func (m *MultishareController) CreateVolume(ctx context.Context, req *csi.Create workflow, share, err := m.opsManager.setupEligibleInstanceAndStartWorkflow(ctx, req, instance) if err != nil { - return nil, err + return nil, file.StatusError(err) } if share != nil { - return m.getShareAndGenerateCSICreateVolumeResponse(ctx, instanceScPrefix, share, maxShareSizeSizeBytes) + resp, err := m.getShareAndGenerateCSICreateVolumeResponse(ctx, instanceScPrefix, share, maxShareSizeSizeBytes) + return resp, file.StatusError(err) } // lock released. poll for op. err = m.waitOnWorkflow(ctx, workflow) if err != nil { - return nil, status.Errorf(*file.CodeForError(err), "Create Volume failed, operation %q poll error: %v", workflow.opName, err) + return nil, file.StatusError(fmt.Errorf("Create Volume failed, operation %q poll error: %w", workflow.opName, err)) } klog.Infof("Poll for operation %s (type %s) completed", workflow.opName, workflow.opType.String()) if workflow.opType == util.ShareCreate { - return m.getShareAndGenerateCSICreateVolumeResponse(ctx, instanceScPrefix, workflow.share, maxShareSizeSizeBytes) + resp, err := m.getShareAndGenerateCSICreateVolumeResponse(ctx, instanceScPrefix, workflow.share, maxShareSizeSizeBytes) + return resp, file.StatusError(err) } var shareCreateWorkflow *Workflow @@ -197,11 +199,11 @@ func (m *MultishareController) CreateVolume(ctx context.Context, req *csi.Create case util.InstanceCreate, util.InstanceUpdate: newShare, err = generateNewShare(util.ConvertVolToShareName(req.Name), workflow.instance, req) if err != nil { - return nil, err + return nil, file.StatusError(err) } shareCreateWorkflow, err = m.opsManager.startShareCreateWorkflowSafe(ctx, newShare) if err != nil { - return nil, err + return nil, file.StatusError(err) } default: return nil, status.Errorf(codes.Internal, "Create Volume failed, unknown workflow %v detected", workflow.opType) @@ -210,15 +212,16 @@ func (m *MultishareController) CreateVolume(ctx context.Context, req *csi.Create // lock released. poll for share create op. err = m.waitOnWorkflow(ctx, shareCreateWorkflow) if err != nil { - return nil, status.Errorf(*file.CodeForError(err), "%s operation %q poll error: %v", shareCreateWorkflow.opType.String(), shareCreateWorkflow.opName, err) + return nil, file.StatusError(fmt.Errorf("%v operation %q poll error: %w", shareCreateWorkflow.opType, shareCreateWorkflow.opName, err)) } - return m.getShareAndGenerateCSICreateVolumeResponse(ctx, instanceScPrefix, newShare, maxShareSizeSizeBytes) + resp, err := m.getShareAndGenerateCSICreateVolumeResponse(ctx, instanceScPrefix, newShare, maxShareSizeSizeBytes) + return resp, file.StatusError(err) } func (m *MultishareController) getShareAndGenerateCSICreateVolumeResponse(ctx context.Context, instancePrefix string, s *file.Share, maxShareSizeSizeBytes int64) (*csi.CreateVolumeResponse, error) { share, err := m.cloud.File.GetShare(ctx, s) if err != nil { - return nil, status.Errorf(codes.Internal, err.Error()) + return nil, err } if share.State != "READY" { @@ -251,32 +254,31 @@ func (m *MultishareController) DeleteVolume(ctx context.Context, req *csi.Delete // If share not found, proceed to instance/shrink check. if file.IsNotFoundErr(err) { err = m.startAndWaitForInstanceDeleteOrShrink(ctx, req.VolumeId) - if err != nil { - return nil, err + if err == nil { // If NO error + return &csi.DeleteVolumeResponse{}, nil } - return &csi.DeleteVolumeResponse{}, nil } - return nil, status.Error(codes.Internal, err.Error()) + return nil, file.StatusError(err) } workflow, err := m.opsManager.checkAndStartShareDeleteWorkflow(ctx, share) if err != nil { - return nil, err + return nil, file.StatusError(err) } // Poll for share delete to complete if workflow != nil { err = m.waitOnWorkflow(ctx, workflow) if err != nil { - return nil, status.Errorf(*file.CodeForError(err), "%s operation %q poll error: %v", workflow.opType.String(), workflow.opName, err) + return nil, file.StatusError(fmt.Errorf("%v operation %q poll error: %w", workflow.opType, workflow.opName, err)) } } // Check whether instance can be shrinked or deleted. err = m.startAndWaitForInstanceDeleteOrShrink(ctx, req.VolumeId) if err != nil { - return nil, err + return nil, file.StatusError(err) } return &csi.DeleteVolumeResponse{}, nil } @@ -303,7 +305,7 @@ func (m *MultishareController) startAndWaitForInstanceDeleteOrShrink(ctx context } err = m.waitOnWorkflow(ctx, workflow) if err != nil { - return status.Errorf(*file.CodeForError(err), "%s operation %q poll error: %v", workflow.opType.String(), workflow.opName, err) + return fmt.Errorf("%v operation %q poll error: %w", workflow.opType, workflow.opName, err) } return nil } @@ -323,7 +325,7 @@ func (m *MultishareController) ControllerExpandVolume(ctx context.Context, req * var err error maxShareSizeBytes, err = m.GetShareMaxSizeFromPV(ctx, volumeId) if err != nil { - return nil, status.Error(codes.Internal, err.Error()) + return nil, file.StatusError(err) } klog.Infof("maxShareSizeBytes %d", maxShareSizeBytes) } @@ -353,11 +355,11 @@ func (m *MultishareController) ControllerExpandVolume(ctx context.Context, req * }, Name: shareName, }) - if err != nil { - return nil, status.Errorf(codes.Internal, err.Error()) - } if share == nil || file.IsNotFoundErr(err) { - return nil, status.Errorf(codes.Internal, "Couldn't find share with name %q", volumeId) + return nil, status.Errorf(codes.NotFound, "Couldn't find share with name %q", volumeId) + } + if err != nil { + return nil, file.StatusError(err) } if share.CapacityBytes >= reqBytes { @@ -370,12 +372,12 @@ func (m *MultishareController) ControllerExpandVolume(ctx context.Context, req * workflow, err := m.opsManager.checkAndStartInstanceOrShareExpandWorkflow(ctx, share, reqBytes) if err != nil { - return nil, err + return nil, file.StatusError(err) } err = m.waitOnWorkflow(ctx, workflow) if err != nil { - return nil, status.Errorf(*file.CodeForError(err), "wait on %s operation %q failed with error: %v", workflow.opType.String(), workflow.opName, err) + return nil, file.StatusError(fmt.Errorf("wait on %v operation %q failed with error: %w", workflow.opType, workflow.opName, err)) } klog.Infof("Wait for operation %s (type %s) completed", workflow.opName, workflow.opType.String()) @@ -383,26 +385,28 @@ func (m *MultishareController) ControllerExpandVolume(ctx context.Context, req * case util.InstanceUpdate: workflow, err = m.opsManager.startShareExpandWorkflowSafe(ctx, share, reqBytes) if err != nil { - return nil, err + return nil, file.StatusError(err) } case util.ShareUpdate: - return m.getShareAndGenerateCSIControllerExpandVolumeResponse(ctx, share, reqBytes) + resp, err := m.getShareAndGenerateCSIControllerExpandVolumeResponse(ctx, share, reqBytes) + return resp, file.StatusError(err) default: return nil, status.Errorf(codes.Internal, "Controller Expand Volume failed, unknown workflow %v detected", workflow.opType) } err = m.waitOnWorkflow(ctx, workflow) if err != nil { - return nil, status.Errorf(*file.CodeForError(err), "wait on share expansion op %q failed with error: %v", workflow.opName, err) + return nil, file.StatusError(fmt.Errorf("wait on share expansion op %q failed with error: %w", workflow.opName, err)) } - return m.getShareAndGenerateCSIControllerExpandVolumeResponse(ctx, share, reqBytes) + resp, err := m.getShareAndGenerateCSIControllerExpandVolumeResponse(ctx, share, reqBytes) + return resp, file.StatusError(err) } func (m *MultishareController) getShareAndGenerateCSIControllerExpandVolumeResponse(ctx context.Context, share *file.Share, reqBytes int64) (*csi.ControllerExpandVolumeResponse, error) { share, err := m.cloud.File.GetShare(ctx, share) if err != nil { - return nil, status.Errorf(codes.Internal, err.Error()) + return nil, err } if share.CapacityBytes < reqBytes { return nil, status.Errorf(codes.Aborted, "expand volume operation succeeded but share capacity [%d]bytes smaller than requested [%d]bytes", share.CapacityBytes, reqBytes) @@ -483,7 +487,7 @@ func (m *MultishareController) generateNewMultishareInstance(instanceName string if m.isRegional { location, err = util.GetRegionFromZone(location) if err != nil { - return nil, status.Errorf(codes.Internal, "failed to get region for regional cluster: %v", err.Error()) + return nil, status.Errorf(codes.InvalidArgument, "failed to get region for regional cluster: %v", err.Error()) } } labels, err := extractInstanceLabels(req.GetParameters(), m.driver.config.Name, m.clustername, location) @@ -513,7 +517,7 @@ func (m *MultishareController) generateNewMultishareInstance(instanceName string func generateNewShare(name string, parent *file.MultishareInstance, req *csi.CreateVolumeRequest) (*file.Share, error) { if parent == nil { - return nil, status.Error(codes.Internal, "parent mulishare instance is empty") + return nil, status.Error(codes.Internal, "parent multishare instance is empty") } // The share size request is already validated in CreateVolume call targetSizeBytes, err := getShareRequestCapacity(req.CapacityRange, util.ConfigurablePackMinShareSizeBytes, util.MaxShareSizeBytes) @@ -773,22 +777,22 @@ func (m *MultishareController) GetShareMaxSizeFromPV(ctx context.Context, volHan if targetPV == nil { targetPV, err = m.findTargetPVFromKubeApiServer(ctx, volHandle) if err != nil { - return 0, err + return 0, file.StatusError(err) } } if targetPV == nil { - return 0, fmt.Errorf("target PV with volume handle %v not found, cannot determine the capacity range for the volume", volHandle) + return 0, status.Errorf(codes.InvalidArgument, "target PV with volume handle %v not found, cannot determine the capacity range for the volume", volHandle) } - // If volume atttributes does not catpure the max share size, it must be created with the feature disabled. + // If volume atttributes does not capture the max share size, it must be created with the feature disabled. v, ok := targetPV.Spec.CSI.VolumeAttributes[attrMaxShareSize] if !ok { return util.MaxShareSizeBytes, nil } val, err := resource.ParseQuantity(v) if err != nil { - return 0, err + return 0, file.StatusError(err) } return val.Value(), nil } diff --git a/pkg/csi_driver/multishare_controller_test.go b/pkg/csi_driver/multishare_controller_test.go index 15c8656e5..8068117f2 100644 --- a/pkg/csi_driver/multishare_controller_test.go +++ b/pkg/csi_driver/multishare_controller_test.go @@ -1219,7 +1219,7 @@ func TestMultishareDeleteVolume(t *testing.T) { errorExpected bool }{ { - name: "share not found, instance not found, succes response", + name: "share not found, instance not found, success response", req: &csi.DeleteVolumeRequest{ VolumeId: testVolId, }, diff --git a/pkg/csi_driver/multishare_ops_manager.go b/pkg/csi_driver/multishare_ops_manager.go index 047304c87..69a1f084a 100644 --- a/pkg/csi_driver/multishare_ops_manager.go +++ b/pkg/csi_driver/multishare_ops_manager.go @@ -73,7 +73,7 @@ func (m *MultishareOpsManager) setupEligibleInstanceAndStartWorkflow(ctx context ops, err := m.listMultishareResourceRunningOps(ctx) if err != nil { - return nil, nil, status.Error(codes.Internal, err.Error()) + return nil, nil, err } createShareOp := containsOpWithShareName(shareName, util.ShareCreate, ops) if createShareOp != nil { @@ -117,7 +117,7 @@ func (m *MultishareOpsManager) setupEligibleInstanceAndStartWorkflow(ctx context needExpand, targetBytes, err := m.instanceNeedsExpand(ctx, share, share.CapacityBytes) if err != nil { - return nil, nil, status.Error(codes.Internal, err.Error()) + return nil, nil, err } if needExpand { @@ -204,7 +204,7 @@ func (m *MultishareOpsManager) startShareCreateWorkflowSafe(ctx context.Context, defer m.Unlock() ops, err := m.listMultishareResourceRunningOps(ctx) if err != nil { - return nil, status.Error(codes.Internal, err.Error()) + return nil, err } return m.startShareWorkflow(ctx, &Workflow{share: share, opType: util.ShareCreate}, ops) @@ -458,7 +458,7 @@ func (m *MultishareOpsManager) checkAndStartInstanceOrShareExpandWorkflow(ctx co ops, err := m.listMultishareResourceRunningOps(ctx) if err != nil { - return nil, status.Error(codes.Internal, err.Error()) + return nil, err } expandShareOp, err := containsOpWithShareTarget(share, util.ShareUpdate, ops) @@ -478,12 +478,12 @@ func (m *MultishareOpsManager) checkAndStartInstanceOrShareExpandWorkflow(ctx co instance, err := m.cloud.File.GetMultishareInstance(ctx, share.Parent) if err != nil { - return nil, status.Error(codes.Internal, err.Error()) + return nil, err } needExpand, targetBytes, err := m.instanceNeedsExpand(ctx, share, reqBytes-share.CapacityBytes) if err != nil { - return nil, status.Error(codes.Internal, err.Error()) + return nil, err } if needExpand { instance.CapacityBytes = targetBytes @@ -500,7 +500,7 @@ func (m *MultishareOpsManager) startShareExpandWorkflowSafe(ctx context.Context, defer m.Unlock() ops, err := m.listMultishareResourceRunningOps(ctx) if err != nil { - return nil, status.Error(codes.Internal, err.Error()) + return nil, err } share.CapacityBytes = reqBytes @@ -513,7 +513,7 @@ func (m *MultishareOpsManager) checkAndStartShareDeleteWorkflow(ctx context.Cont ops, err := m.listMultishareResourceRunningOps(ctx) if err != nil { - return nil, status.Error(codes.Internal, err.Error()) + return nil, err } // If we find a running delete share op, poll for that to complete. @@ -534,7 +534,7 @@ func (m *MultishareOpsManager) checkAndStartInstanceDeleteOrShrinkWorkflow(ctx c ops, err := m.listMultishareResourceRunningOps(ctx) if err != nil { - return nil, status.Error(codes.Internal, err.Error()) + return nil, err } err = m.verifyNoRunningInstanceOrShareOpsForInstance(instance, ops) @@ -551,7 +551,7 @@ func (m *MultishareOpsManager) checkAndStartInstanceDeleteOrShrinkWorkflow(ctx c if file.IsNotFoundErr(err) { return nil, nil } - return nil, status.Error(codes.Internal, err.Error()) + return nil, err } shares, err := m.cloud.File.ListShares(ctx, &file.ListFilter{Project: instance.Project, Location: instance.Location, InstanceName: instance.Name}) @@ -559,7 +559,7 @@ func (m *MultishareOpsManager) checkAndStartInstanceDeleteOrShrinkWorkflow(ctx c if file.IsNotFoundErr(err) { return nil, nil } - return nil, status.Error(codes.Internal, err.Error()) + return nil, err } // Check for delete @@ -569,7 +569,7 @@ func (m *MultishareOpsManager) checkAndStartInstanceDeleteOrShrinkWorkflow(ctx c if file.IsNotFoundErr(err) { return nil, nil } - return nil, status.Error(codes.Internal, err.Error()) + return nil, err } return w, err } @@ -592,7 +592,7 @@ func (m *MultishareOpsManager) checkAndStartInstanceDeleteOrShrinkWorkflow(ctx c if file.IsNotFoundErr(err) { return nil, nil } - return nil, status.Error(codes.Internal, err.Error()) + return nil, err } return w, err }