Skip to content

Commit

Permalink
fix: golangci-lint error
Browse files Browse the repository at this point in the history
Signed-off-by: PoAn Yang <poan.yang@suse.com>
  • Loading branch information
FrankYang0529 authored and innobead committed Apr 26, 2024
1 parent ddbf249 commit 2190a31
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 25 deletions.
3 changes: 2 additions & 1 deletion pkg/client/share_manager_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
rpc "github.com/longhorn/types/pkg/generated/smrpc"
"github.com/pkg/errors"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/protobuf/types/known/emptypb"

"github.com/longhorn/longhorn-share-manager/pkg/types"
Expand All @@ -18,7 +19,7 @@ type ShareManagerClient struct {
}

func NewShareManagerClient(address string) (*ShareManagerClient, error) {
conn, err := grpc.Dial(address, grpc.WithInsecure())
conn, err := grpc.Dial(address, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
return nil, errors.Wrapf(err, "failed to connect share manager service to %v", address)
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/rpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ func (s *ShareManagerServer) FilesystemTrim(ctx context.Context, req *smrpc.File
log.Infof("Trimming mounted filesystem %v", mountPath)

mounter := mount.New("")
notMounted, err := mount.IsNotMountPoint(mounter, mountPath)
if notMounted {
isMountPoint, err := mounter.IsMountPoint(mountPath)
if !isMountPoint {
return &emptypb.Empty{}, grpcstatus.Errorf(grpccodes.InvalidArgument, "%v is not a mount point", mountPath)
}
if err != nil {
Expand Down Expand Up @@ -135,11 +135,11 @@ func (s *ShareManagerServer) unmount(vol volume.Volume) error {
mountPath := types.GetMountPath(vol.Name)

mounter := mount.New("")
notMounted, err := mount.IsNotMountPoint(mounter, mountPath)
isMountPoint, err := mounter.IsMountPoint(mountPath)
if err != nil {
return errors.Wrapf(err, "failed to check mount point %v", mountPath)
}
if notMounted {
if !isMountPoint {
return nil
}

Expand Down Expand Up @@ -255,12 +255,12 @@ func (s *ShareManagerServer) Mount(ctx context.Context, req *emptypb.Empty) (res
}()

mounter := mount.New("")
notMounted, err := mount.IsNotMountPoint(mounter, mountPath)
isMountPoint, err := mounter.IsMountPoint(mountPath)
if err != nil {
err = errors.Wrapf(err, "failed to check mount point %v", mountPath)
return &emptypb.Empty{}, grpcstatus.Errorf(grpccodes.Internal, err.Error())
}
if notMounted {
if !isMountPoint {
log.Info("Mounting volume")
err = s.mount(vol, devicePath, mountPath)
if err != nil {
Expand Down
6 changes: 4 additions & 2 deletions pkg/server/nfs/nfs_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ NFS_Core_Param
RQUOTA_Port = 0;
Enable_NLM = false;
Enable_RQUOTA = false;
Enable_UDP = false;
Enable_UDP = false;
fsid_device = false;
Protocols = 4;
}
Expand Down Expand Up @@ -163,7 +163,9 @@ func getUpdatedGaneshConfig(config []byte) []byte {
LogPath: logPath,
}

template.Must(template.New("Ganesha_Config").Parse(string(config))).Execute(&tmplBuf, tmplVals)
if err := template.Must(template.New("Ganesha_Config").Parse(string(config))).Execute(&tmplBuf, tmplVals); err != nil {
logrus.WithError(err).Warn("Failed to parse ganesha config")
}

return tmplBuf.Bytes()
}
4 changes: 2 additions & 2 deletions pkg/volume/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ func CheckDeviceValid(devicePath string) bool {
}

func CheckMountValid(mountPath string) bool {
notMnt, err := mount.IsNotMountPoint(mount.New(""), mountPath)
return err == nil && !notMnt
isMountPoint, err := mount.New("").IsMountPoint(mountPath)
return err == nil && isMountPoint
}

func MountVolume(devicePath, mountPath, fsType string, mountOptions []string) error {
Expand Down
16 changes: 2 additions & 14 deletions scripts/validate
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,8 @@ PACKAGES="$(find -name '*.go' | xargs -I{} dirname {} | cut -f2 -d/ | sort -u |
echo Running: go vet
go vet ${PACKAGES}

if [ ! -z "${DRONE_REPO}" ] && [ ! -z "${DRONE_PULL_REQUEST}" ]; then
wget https://github.com/$DRONE_REPO/pull/$DRONE_PULL_REQUEST.patch
echo "Running: golangci-lint run --new-from-patch=${DRONE_PULL_REQUEST}.patch"
golangci-lint run --new-from-patch="${DRONE_PULL_REQUEST}.patch"
rm "${DRONE_PULL_REQUEST}.patch"
elif [ ! -z "${DRONE_COMMIT_REF}" ]; then
echo "Running: golangci-lint run --new-from-rev=${DRONE_COMMIT_REF}"
golangci-lint run --new-from-rev=${DRONE_COMMIT_REF}
else
git symbolic-ref -q HEAD && REV="origin/HEAD" || REV="HEAD^"
headSHA=$(git rev-parse --short=12 ${REV})
echo "Running: golangci-lint run --new-from-rev=${headSHA}"
golangci-lint run --new-from-rev=${headSHA}
fi
echo "Running: golangci-lint"
golangci-lint run --new-from-rev=${headSHA}

echo Running: go fmt
test -z "$(go fmt ${PACKAGES} | tee /dev/stderr)"

0 comments on commit 2190a31

Please sign in to comment.