From d3a561e5f196e57a8e8321c97fa27d385b02be2c Mon Sep 17 00:00:00 2001 From: PoAn Yang Date: Fri, 26 Apr 2024 16:08:01 +0800 Subject: [PATCH] fix: golangci-lint error Signed-off-by: PoAn Yang --- pkg/client/share_manager_client.go | 3 ++- pkg/rpc/server.go | 12 ++++++------ pkg/server/nfs/nfs_server.go | 6 ++++-- pkg/volume/volume.go | 4 ++-- scripts/validate | 16 ++-------------- 5 files changed, 16 insertions(+), 25 deletions(-) diff --git a/pkg/client/share_manager_client.go b/pkg/client/share_manager_client.go index 0f509e3b..38ca4713 100644 --- a/pkg/client/share_manager_client.go +++ b/pkg/client/share_manager_client.go @@ -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" @@ -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) } diff --git a/pkg/rpc/server.go b/pkg/rpc/server.go index 953fd151..2006520e 100644 --- a/pkg/rpc/server.go +++ b/pkg/rpc/server.go @@ -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 { @@ -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 } @@ -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 { diff --git a/pkg/server/nfs/nfs_server.go b/pkg/server/nfs/nfs_server.go index 0d622215..acb982cd 100644 --- a/pkg/server/nfs/nfs_server.go +++ b/pkg/server/nfs/nfs_server.go @@ -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; } @@ -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() } diff --git a/pkg/volume/volume.go b/pkg/volume/volume.go index 8caffdca..d5d3404a 100644 --- a/pkg/volume/volume.go +++ b/pkg/volume/volume.go @@ -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 { diff --git a/scripts/validate b/scripts/validate index 3081c0ac..79dac09c 100755 --- a/scripts/validate +++ b/scripts/validate @@ -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)"