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 <[email protected]>
  • Loading branch information
FrankYang0529 committed Apr 26, 2024
1 parent ba59a87 commit 840caa7
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 31 deletions.
18 changes: 9 additions & 9 deletions Dockerfile.dapper
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions iscsi/iscsi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
5 changes: 2 additions & 3 deletions iscsi/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 1 addition & 3 deletions longhorndev/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
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 --timeout=5m

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

0 comments on commit 840caa7

Please sign in to comment.