Skip to content

Commit

Permalink
fix: golint errors
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Su <[email protected]>
  • Loading branch information
derekbit authored and mergify[bot] committed Sep 9, 2024
1 parent bab7e06 commit 6867e52
Show file tree
Hide file tree
Showing 16 changed files with 68 additions and 67 deletions.
2 changes: 1 addition & 1 deletion app/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ func startManager(c *cli.Context) error {
debugHandler := http.DefaultServeMux
logger.Infof("Debug Server listening on %s", debugAddress)
if err := http.ListenAndServe(debugAddress, debugHandler); err != nil && !errors.Is(err, http.ErrServerClosed) {
logger.Errorf(fmt.Sprintf("ListenAndServe: %s", err))
logger.WithError(err).Error("Failed to start debug server")
}
}()

Expand Down
2 changes: 1 addition & 1 deletion app/get_proc_arg.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func getPodLogAsString(kubeClient *clientset.Clientset, namespace, name string)
return "", nil
} else if !strings.HasPrefix(strLogs[0], "Proc found") {
// unexpected result
return "", fmt.Errorf(string(logs))
return "", fmt.Errorf("%s", string(logs))
}
logrus.Info(strLogs[0])
return strLogs[1], nil
Expand Down
2 changes: 1 addition & 1 deletion controller/engine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2092,7 +2092,7 @@ func (ec *EngineController) waitForV2EngineRebuild(e *longhorn.Engine, replicaNa
continue
}
if rebuildingStatus.State == engineapi.ProcessStateError || rebuildingStatus.Error != "" {
return fmt.Errorf(rebuildingStatus.Error)
return errors.New(rebuildingStatus.Error)
}
if rebuildingStatus.State == engineapi.ProcessStateComplete {
return nil
Expand Down
2 changes: 1 addition & 1 deletion controller/kubernetes_pod_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ func isCSIPluginPod(obj interface{}) bool {
}
}

if pod.OwnerReferences != nil && len(pod.OwnerReferences) > 0 {
if len(pod.OwnerReferences) > 0 {
for _, ownerRef := range pod.OwnerReferences {
if ownerRef.Kind != types.KubernetesKindDaemonSet {
continue
Expand Down
2 changes: 1 addition & 1 deletion controller/monitor/snapshot_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ func (m *SnapshotMonitor) syncHashStatusFromEngineReplicas(engine *longhorn.Engi
}

if status.State == string(engineapi.ProcessStateInProgress) {
return fmt.Errorf(string(engineapi.ProcessStateInProgress))
return errors.New(string(engineapi.ProcessStateInProgress))
}
}

Expand Down
2 changes: 1 addition & 1 deletion controller/node_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1728,7 +1728,7 @@ func (nc *NodeController) syncBackingImageEvictionRequested(node *longhorn.Node)
logMessage = "Requesting backing image copy eviction"
}

backingImageLog.Infof(logMessage)
backingImageLog.Infof("%s", logMessage)
if _, err := nc.ds.UpdateBackingImage(backingImageToSync.BackingImage); err != nil {
backingImageLog.Warnf("Failed to %s, will enqueue then resync the node", strings.ToLower(logMessage))
nc.enqueueNodeRateLimited(node)
Expand Down
4 changes: 2 additions & 2 deletions controller/system_backup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ func (c *SystemBackupController) WaitForVolumeBackupToComplete(backups map[strin
case longhorn.BackupStateCompleted:
delete(backups, name)
case longhorn.BackupStateError:
return errors.Wrapf(fmt.Errorf(backup.Status.Error), "failed creating Volume backup %v", name)
return errors.Wrapf(fmt.Errorf("%s", backup.Status.Error), "failed creating Volume backup %v", name)
}
}

Expand Down Expand Up @@ -926,7 +926,7 @@ func (c *SystemBackupController) WaitForBackingImageBackupToComplete(backupBacki
case longhorn.BackupStateCompleted:
delete(backupBackingImages, name)
case longhorn.BackupStateError:
log.Warnf(errors.Wrapf(fmt.Errorf(backupBackingImage.Status.Error), "Failed to create BackingImage backup %v", name).Error())
log.Warnf("Failed to create BackingImage backup %v: %v", name, backupBackingImage.Status.Error)
return
}
}
Expand Down
2 changes: 1 addition & 1 deletion controller/system_restore_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ type FakeSystemBackupTargetClient struct {
func (c *FakeSystemBackupTargetClient) UploadSystemBackup(name, localFile, longhornVersion, longhornGitCommit, managerImage, engineImage string) (string, error) {
switch name {
case TestSystemBackupNameUploadFailed, TestSystemRestoreNameUploadFailed:
return "", fmt.Errorf(name)
return "", fmt.Errorf("%v", name)
case TestSystemBackupNameUploadExceedTimeout, TestSystemRestoreNameUploadExceedTimeout:
time.Sleep(datastore.SystemBackupTimeout * 2)
}
Expand Down
2 changes: 1 addition & 1 deletion controller/system_rollout_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ func (c *SystemRolloutController) recordErrorState(record *systemRolloutRecord,
fmt.Sprintf("%v: %v", record.message, err),
)

log.WithError(fmt.Errorf(err)).Error(record.message)
log.WithError(fmt.Errorf("%v", err)).Error(record.message)
c.eventRecorder.Event(systemRestore, corev1.EventTypeWarning, constant.EventReasonFailed, util.CapitalizeFirstLetter(record.message))

c.cacheErrors.Reset()
Expand Down
12 changes: 6 additions & 6 deletions csi/controller_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (cs *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
// check size of source and requested
srcVolSizeBytes, err := strconv.ParseInt(longhornSrcVol.Size, 10, 64)
if err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
return nil, status.Errorf(codes.Internal, "%v", err)
}
if reqVolSizeBytes != srcVolSizeBytes {
return nil, status.Errorf(codes.OutOfRange, "failed to clone volume: the requested size (%v bytes) is different than the source volume size (%v bytes)", reqVolSizeBytes, srcVolSizeBytes)
Expand Down Expand Up @@ -1082,7 +1082,7 @@ func (cs *ControllerServer) ControllerExpandVolume(ctx context.Context, req *csi

existVol, err := cs.apiClient.Volume.ById(volumeID)
if err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
return nil, status.Errorf(codes.Internal, "%v", err)
}
if existVol == nil {
return nil, status.Errorf(codes.NotFound, "volume %s missing", volumeID)
Expand All @@ -1095,7 +1095,7 @@ func (cs *ControllerServer) ControllerExpandVolume(ctx context.Context, req *csi
}
existingSize, err := strconv.ParseInt(existVol.Size, 10, 64)
if err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
return nil, status.Errorf(codes.Internal, "%v", err)
}

isOnlineExpansion := existVol.State == string(longhorn.VolumeStateAttached)
Expand All @@ -1106,9 +1106,9 @@ func (cs *ControllerServer) ControllerExpandVolume(ctx context.Context, req *csi
// TODO: This manual error code parsing should be refactored once Longhorn API implements error code response
// https://github.com/longhorn/longhorn/issues/1875
if matched, _ := regexp.MatchString("failed to schedule .* more bytes to disk", err.Error()); matched {
return nil, status.Errorf(codes.OutOfRange, err.Error())
return nil, status.Errorf(codes.OutOfRange, "%v", err)
}
return nil, status.Errorf(codes.Internal, err.Error())
return nil, status.Errorf(codes.Internal, "%v", err)
}

// kubernetes doesn't support volume shrinking and the csi spec specifies to return true
Expand All @@ -1135,7 +1135,7 @@ func (cs *ControllerServer) ControllerExpandVolume(ctx context.Context, req *csi

volumeSize, err := strconv.ParseInt(existVol.Size, 10, 64)
if err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
return nil, status.Errorf(codes.Internal, "%v", err)
}

if !isOnlineExpansion {
Expand Down
30 changes: 15 additions & 15 deletions csi/node_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func (ns *NodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
_, err := os.Stat(devicePath)
if err != nil {
if !os.IsNotExist(err) {
return nil, status.Errorf(codes.Internal, errors.Wrapf(err, "failed to stat device %s", devicePath).Error())
return nil, status.Errorf(codes.Internal, "failed to stat device %s: %v", devicePath, err)
}
}

Expand Down Expand Up @@ -234,15 +234,15 @@ func (ns *NodeServer) nodeStageSharedVolume(volumeID, shareEndpoint, targetPath

isMnt, err := ensureMountPoint(targetPath, mounter)
if err != nil {
return status.Errorf(codes.Internal, errors.Wrapf(err, "failed to prepare mount point for shared volume %v", volumeID).Error())
return status.Errorf(codes.Internal, "failed to prepare mount point for shared volume %v: %v", volumeID, err)
}
if isMnt {
return nil
}

uri, err := url.Parse(shareEndpoint)
if err != nil {
return status.Errorf(codes.InvalidArgument, errors.Wrapf(err, "invalid share endpoint %v for volume %v", shareEndpoint, volumeID).Error())
return status.Errorf(codes.InvalidArgument, "invalid share endpoint %v for volume %v: %v", shareEndpoint, volumeID, err)
}

// share endpoint is of the form nfs://server/export
Expand Down Expand Up @@ -302,7 +302,7 @@ func (ns *NodeServer) nodeStageMountVolume(volumeID, devicePath, stagingTargetPa

isMnt, err := ensureMountPoint(stagingTargetPath, mounter)
if err != nil {
return status.Errorf(codes.Internal, errors.Wrapf(err, "failed to prepare mount point %v for volume %v", stagingTargetPath, volumeID).Error())
return status.Errorf(codes.Internal, "failed to prepare mount point %v for volume %v: %v", stagingTargetPath, volumeID, err)
}
if isMnt {
return nil
Expand All @@ -327,20 +327,20 @@ func (ns *NodeServer) nodePublishBlockVolume(volumeID, devicePath, targetPath st

// we ensure the parent directory exists and is valid
if _, err := ensureDirectory(filepath.Dir(targetPath)); err != nil {
return status.Errorf(codes.Internal, errors.Wrapf(err, "failed to prepare mount point for block device %v", devicePath).Error())
return status.Errorf(codes.Internal, "failed to prepare mount point for block device %v: %v", devicePath, err)
}

// create file where we can bind mount the device to
if err := makeFile(targetPath); err != nil {
return status.Errorf(codes.Internal, errors.Wrapf(err, "failed to create file %v", targetPath).Error())
return status.Errorf(codes.Internal, "failed to create file %v: %v", targetPath, err)
}

log.Infof("Bind mounting device %v at %v", devicePath, targetPath)
if err := mounter.Mount(devicePath, targetPath, "", []string{"bind"}); err != nil {
if removeErr := os.Remove(targetPath); removeErr != nil {
return status.Errorf(codes.Internal, errors.Wrapf(removeErr, "failed to remove mount target %q", targetPath).Error())
return status.Errorf(codes.Internal, "failed to remove mount target %q: %v", targetPath, removeErr)
}
return status.Errorf(codes.Internal, errors.Wrapf(err, "failed to bind mount %q at %q", devicePath, targetPath).Error())
return status.Errorf(codes.Internal, "failed to bind mount %q at %q: %v", devicePath, targetPath, err)
}
return nil
}
Expand All @@ -361,7 +361,7 @@ func (ns *NodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpu
}

if err := unmountAndCleanupMountPoint(targetPath, mount.New("")); err != nil {
return nil, status.Errorf(codes.Internal, errors.Wrapf(err, "failed to cleanup volume %s mount point %v", volumeID, targetPath).Error())
return nil, status.Errorf(codes.Internal, "failed to cleanup volume %s mount point %v: %v", volumeID, targetPath, err)
}

log.Infof("Volume %s unmounted from path %s", volumeID, targetPath)
Expand Down Expand Up @@ -454,7 +454,7 @@ func (ns *NodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStageVol
devicePath := volume.Controllers[0].Endpoint
diskFormat, err := getDiskFormat(devicePath)
if err != nil {
return nil, status.Errorf(codes.Internal, errors.Wrapf(err, "failed to evaluate device filesystem %v format", devicePath).Error())
return nil, status.Errorf(codes.Internal, "failed to evaluate device filesystem %v format: %v", devicePath, err)
}

log.Infof("Volume %v device %v contains filesystem of format %v", volumeID, devicePath, diskFormat)
Expand Down Expand Up @@ -644,13 +644,13 @@ func (ns *NodeServer) NodeGetVolumeStats(ctx context.Context, req *csi.NodeGetVo
if errors.Is(err, unix.ENOENT) {
return nil, status.Errorf(codes.NotFound, "volume %v is not mounted on path %v", volumeID, volumePath)
}
return nil, status.Errorf(codes.Internal, errors.Wrapf(err, "failed to check volume mode for volume path %v", volumePath).Error())
return nil, status.Errorf(codes.Internal, "failed to check volume mode for volume path %v: %v", volumePath, err)
}

if isBlockVolume {
volCapacity, err := strconv.ParseInt(existVol.Size, 10, 64)
if err != nil {
return nil, status.Errorf(codes.Internal, errors.Wrapf(err, "failed to convert volume size %v for volume %v", existVol.Size, volumeID).Error())
return nil, status.Errorf(codes.Internal, "failed to convert volume size %v for volume %v: %v", existVol.Size, volumeID, err)
}
return &csi.NodeGetVolumeStatsResponse{
Usage: []*csi.VolumeUsage{
Expand All @@ -669,7 +669,7 @@ func (ns *NodeServer) NodeGetVolumeStats(ctx context.Context, req *csi.NodeGetVo
if errors.Is(err, unix.ENOENT) {
return nil, status.Errorf(codes.NotFound, "volume %v is not mounted on path %v", volumeID, volumePath)
}
return nil, status.Errorf(codes.Internal, errors.Wrapf(err, "failed to retrieve capacity statistics for volume path %v for volume %v", volumePath, volumeID).Error())
return nil, status.Errorf(codes.Internal, "failed to retrieve capacity statistics for volume path %v for volume %v: %v", volumePath, volumeID, err)
}

return &csi.NodeGetVolumeStatsResponse{
Expand Down Expand Up @@ -718,7 +718,7 @@ func (ns *NodeServer) NodeExpandVolume(ctx context.Context, req *csi.NodeExpandV

volume, err := ns.apiClient.Volume.ById(volumeID)
if err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
return nil, status.Errorf(codes.Internal, "%v", err)
}
if volume == nil {
return nil, status.Errorf(codes.NotFound, "volume %s missing", volumeID)
Expand Down Expand Up @@ -768,7 +768,7 @@ func (ns *NodeServer) NodeExpandVolume(ctx context.Context, req *csi.NodeExpandV

// blindly resize the encrypto device
if err := crypto.ResizeEncryptoDevice(volumeID, passphrase); err != nil {
return "", status.Errorf(codes.InvalidArgument, errors.Wrapf(err, "failed to resize crypto device %v for volume %v node expansion", devicePath, volumeID).Error())
return "", status.Errorf(codes.InvalidArgument, "failed to resize crypto device %v for volume %v node expansion: %v", devicePath, volumeID, err)
}

return devicePath, nil
Expand Down
2 changes: 1 addition & 1 deletion engineapi/backups.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,5 +475,5 @@ func (e *EngineBinary) BackupRestoreStatus(*longhorn.Engine) (map[string]*longho
// CleanupBackupMountPoints calls engine binary
// TODO: Deprecated, replaced by gRPC proxy, just to match the interface
func (e *EngineBinary) CleanupBackupMountPoints() error {
return fmt.Errorf(ErrNotImplement)
return errors.New(ErrNotImplement)
}
4 changes: 2 additions & 2 deletions engineapi/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,11 @@ func (e *EngineBinary) ReplicaModeUpdate(engine *longhorn.Engine, url, mode stri
}

func (e *EngineBinary) MetricsGet(*longhorn.Engine) (*Metrics, error) {
return nil, fmt.Errorf(ErrNotImplement)
return nil, errors.New(ErrNotImplement)
}

func (e *EngineBinary) RemountReadOnlyVolume(*longhorn.Engine) error {
return fmt.Errorf(ErrNotImplement)
return errors.New(ErrNotImplement)
}

// addFlags always adds required flags to args. In addition, if the engine version is high enough, it adds additional
Expand Down
Loading

0 comments on commit 6867e52

Please sign in to comment.