Skip to content

Commit

Permalink
avoid two level of status.Error
Browse files Browse the repository at this point in the history
  • Loading branch information
huww98 committed Apr 25, 2024
1 parent 2a6bab5 commit 8f3055c
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions pkg/disk/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ import (
"github.com/kubernetes-sigs/alibaba-cloud-csi-driver/pkg/version"
perrors "github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/timestamppb"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -861,8 +859,7 @@ func CheckDeviceAvailable(devicePath, volumeID, targetPath string) error {

func checkDeviceAvailable(mountinfoPath, devicePath, volumeID, targetPath string) error {
if devicePath == "" {
msg := "devicePath is empty, cannot used for Volume"
return status.Error(codes.Internal, msg)
return fmt.Errorf("devicePath is empty, cannot used for Volume")
}

mnts, err := mount.ParseMountInfo(mountinfoPath)
Expand All @@ -878,15 +875,14 @@ func checkDeviceAvailable(mountinfoPath, devicePath, volumeID, targetPath string
return nil
}
if newVolumeID != volumeID {
return status.Errorf(codes.Internal, "device [%s] associate with volumeID: [%s] rather than volumeID: [%s]", device, newVolumeID, volumeID)
return fmt.Errorf("device [%s] associate with volumeID: [%s] rather than volumeID: [%s]", device, newVolumeID, volumeID)
}

return nil
}

if !utils.IsFileExisting(devicePath) {
msg := fmt.Sprintf("devicePath(%s) is empty, cannot used for Volume", devicePath)
return status.Error(codes.Internal, msg)
return fmt.Errorf("devicePath(%s) is empty, cannot used for Volume", devicePath)
}

// check the device is used for system
Expand All @@ -895,8 +891,7 @@ func checkDeviceAvailable(mountinfoPath, devicePath, volumeID, targetPath string
}

if isDeviceMountedAt(mnts, devicePath, utils.KubeletRootDir) {
msg := fmt.Sprintf("devicePath(%s) is used as DataDisk for kubelet, cannot used fo Volume", devicePath)
return status.Error(codes.Internal, msg)
return fmt.Errorf("devicePath(%s) is used as DataDisk for kubelet, cannot used fo Volume", devicePath)
}
return nil
}
Expand Down

0 comments on commit 8f3055c

Please sign in to comment.