From 840caa738efb51cf3832c14a41d14b917a3984e1 Mon Sep 17 00:00:00 2001 From: PoAn Yang Date: Fri, 26 Apr 2024 14:00:02 +0800 Subject: [PATCH] fix: golangci-lint error Signed-off-by: PoAn Yang --- Dockerfile.dapper | 18 +++++++++--------- iscsi/iscsi_test.go | 3 +-- iscsi/target.go | 5 ++--- longhorndev/dev.go | 4 +--- scripts/validate | 16 ++-------------- 5 files changed, 15 insertions(+), 31 deletions(-) diff --git a/Dockerfile.dapper b/Dockerfile.dapper index 6060817..83ff64d 100644 --- a/Dockerfile.dapper +++ b/Dockerfile.dapper @@ -24,25 +24,25 @@ RUN apt-get update && \ RUN rm -f /bin/sh && ln -s /bin/bash /bin/sh # Install Go & tools -ENV GOLANG_ARCH_amd64=amd64 GOLANG_ARCH_arm=armv6l GOLANG_ARCH=GOLANG_ARCH_${ARCH} \ +ENV GOLANG_ARCH_amd64=amd64 GOLANG_ARCH_arm64=arm64 GOLANG_ARCH=GOLANG_ARCH_${ARCH} \ GOPATH=/go PATH=/go/bin:/usr/local/go/bin:${PATH} SHELL=/bin/bash -RUN wget -O - https://storage.googleapis.com/golang/go1.14.1.linux-${!GOLANG_ARCH}.tar.gz | tar -xzf - -C /usr/local +RUN wget -O - https://storage.googleapis.com/golang/go1.21.3.linux-${!GOLANG_ARCH}.tar.gz | tar -xzf - -C /usr/local RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.55.2 # Docker ENV DOCKER_URL_amd64=https://download.docker.com/linux/ubuntu/dists/xenial/pool/stable/amd64/docker-ce_17.03.3~ce-0~ubuntu-xenial_amd64.deb \ - DOCKER_URL_arm=https://download.docker.com/linux/ubuntu/dists/xenial/pool/stable/arm64/docker-ce_18.06.1~ce~3-0~ubuntu_arm64.deb \ + DOCKER_URL_arm64=https://download.docker.com/linux/ubuntu/dists/xenial/pool/stable/arm64/docker-ce_18.06.1~ce~3-0~ubuntu_arm64.deb \ DOCKER_URL=DOCKER_URL_${ARCH} RUN wget ${!DOCKER_URL} -O docker_ce_${ARCH} && dpkg -i docker_ce_${ARCH} # Build TGT -RUN cd /usr/src && \ - git clone https://github.com/rancher/tgt.git && \ - cd tgt && \ - git checkout 3a8bc4823b5390e046f7aa8231ed262c0365c42c && \ - ./scripts/build-pkg.sh deb && \ - dpkg -i ./pkg/tgt_*.deb +# RUN cd /usr/src && \ +# git clone https://github.com/rancher/tgt.git && \ +# cd tgt && \ +# git checkout 3a8bc4823b5390e046f7aa8231ed262c0365c42c && \ +# ./scripts/build-pkg.sh deb && \ +# dpkg -i ./pkg/tgt_*.deb VOLUME /tmp ENV TMPDIR /tmp diff --git a/iscsi/iscsi_test.go b/iscsi/iscsi_test.go index 90319d0..cb567c3 100644 --- a/iscsi/iscsi_test.go +++ b/iscsi/iscsi_test.go @@ -76,12 +76,11 @@ func (s *TestSuite) TestFlow(c *C) { t := "iqn.2014-09.io.longhorn:flow" tid := 1 lun := 1 - tmptid := -1 err = CheckForInitiatorExistence(s.nsexec) c.Assert(err, IsNil) - tmptid, err = GetTargetTid(t) + tmptid, err := GetTargetTid(t) c.Assert(err, IsNil) c.Assert(tmptid, Equals, -1) diff --git a/iscsi/target.go b/iscsi/target.go index 640766a..995101c 100644 --- a/iscsi/target.go +++ b/iscsi/target.go @@ -12,8 +12,8 @@ import ( "github.com/pkg/errors" - lhtypes "github.com/longhorn/go-common-libs/types" lhexec "github.com/longhorn/go-common-libs/exec" + lhtypes "github.com/longhorn/go-common-libs/types" ) var ( @@ -385,12 +385,11 @@ func FindNextAvailableTargetID() (int, error) { System information: ... */ - tid := -1 scanner := bufio.NewScanner(strings.NewReader(output)) for scanner.Scan() { if strings.HasPrefix(scanner.Text(), "Target ") { tidString := strings.Fields(strings.Split(scanner.Text(), ":")[0])[1] - tid, err = strconv.Atoi(tidString) + tid, err := strconv.Atoi(tidString) if err != nil { return -1, errors.Wrapf(err, "BUG: Failed to parse %s", tidString) } diff --git a/longhorndev/dev.go b/longhorndev/dev.go index 5752ec6..35170ea 100644 --- a/longhorndev/dev.go +++ b/longhorndev/dev.go @@ -308,6 +308,7 @@ func (d *LonghornDevice) FinishUpgrade() (err error) { err = errors.Wrapf(err, "error waiting for the socket") } break + default: } close(stopCh) close(socketError) @@ -448,17 +449,14 @@ func (d *LonghornDevice) Expand(size int64) (err error) { return fmt.Errorf("device %v: fail to refresh iSCSI initiator: %v", d.name, err) } logrus.Infof("Device %v: Expanded frontend %v size to %d", d.name, d.frontend, size) - break case types.FrontendTGTISCSI: logrus.Infof("Device %v: Frontend is expanding the target %v", d.name, d.scsiDevice.Target) if err := d.scsiDevice.ExpandTarget(size); err != nil { return fmt.Errorf("device %v: fail to expand target %v: %v", d.name, d.scsiDevice.Target, err) } logrus.Infof("Device %v: Expanded frontend %v size to %d, users need to refresh/rescan the initiator by themselves", d.name, d.frontend, size) - break case "": logrus.Infof("Device %v: skip expansion since the frontend not enabled", d.name) - break default: return fmt.Errorf("failed to expand device %v: unknown frontend %v", d.name, d.frontend) } diff --git a/scripts/validate b/scripts/validate index 3081c0a..5c83da0 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 --timeout=5m echo Running: go fmt test -z "$(go fmt ${PACKAGES} | tee /dev/stderr)"