Skip to content

Commit d6b0ddb

Browse files
authored
Merge pull request #2962 from kolyshkin/imports
Fix local imports, add appropriate linter
2 parents bae1093 + b36394b commit d6b0ddb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+142
-148
lines changed

.github/workflows/test.yml

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,6 @@
11
name: Test
22
on: [push, pull_request]
33
jobs:
4-
lint:
5-
env:
6-
GOLANGCI_LINT_V: 1.34.1
7-
strategy:
8-
matrix:
9-
environment-variables: [build/config/plain.sh, build/config/libpfm4.sh, build/config/libipmctl.sh]
10-
runs-on: ubuntu-20.04
11-
timeout-minutes: 10
12-
steps:
13-
- name: Install Go
14-
uses: actions/setup-go@v1
15-
with:
16-
go-version: 1.17
17-
- name: Install golangci-lint
18-
run: >
19-
cd /tmp &&
20-
mkdir -p $(go env GOPATH)/bin &&
21-
wget -q https://github.com/golangci/golangci-lint/releases/download/v${GOLANGCI_LINT_V}/golangci-lint-${GOLANGCI_LINT_V}-linux-amd64.tar.gz &&
22-
tar xf golangci-lint-${GOLANGCI_LINT_V}-linux-amd64.tar.gz &&
23-
mv golangci-lint-${GOLANGCI_LINT_V}-linux-amd64/golangci-lint $(go env GOPATH)/bin &&
24-
rm -fr golangci-lint-*
25-
- name: Checkout code
26-
uses: actions/checkout@v2
27-
- name: Run golangci-lint
28-
run: |
29-
set -e
30-
source ${{ matrix.environment-variables }}
31-
if [[ "${BUILD_PACKAGES}" != "" ]]; then sudo apt-get update; sudo apt-get install ${BUILD_PACKAGES}; fi
32-
make -e lint
334
test:
345
strategy:
356
matrix:
@@ -40,13 +11,16 @@ jobs:
4011
timeout-minutes: 30
4112
steps:
4213
- name: Install Go
43-
uses: actions/setup-go@v1
14+
uses: actions/setup-go@v2
4415
with:
4516
go-version: ${{ matrix.go-versions }}
4617
- name: Checkout code
4718
uses: actions/checkout@v2
4819
- name: Run presubmit checks
49-
run: GOFLAGS="$GO_FLAGS" make presubmit
20+
run: |
21+
source ${{ matrix.environment-variables }}
22+
if [[ "${BUILD_PACKAGES}" != "" ]]; then sudo apt-get update; sudo apt-get install ${BUILD_PACKAGES}; fi
23+
make -e presubmit
5024
- name: Run tests
5125
env:
5226
GOLANG_VERSION: ${{ matrix.go-versions }}

.golangci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ run:
77
min-confidence: 0
88
gofmt:
99
simplify: true
10+
goimports:
11+
local-prefixes: github.com/google/cadvisor
1012
linters:
1113
disable-all: true
1214
enable:
@@ -22,6 +24,7 @@ linters:
2224
- typecheck
2325
- golint
2426
- gofmt
27+
- goimports
2528
issues:
2629
max-issues-per-linter: 0
2730
max-same-issues: 0

Makefile

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
# limitations under the License.
1414

1515
GO := go
16+
GOLANGCI_VER := v1.42.1
1617
pkgs = $(shell $(GO) list ./... | grep -v vendor)
1718
cmd_pkgs = $(shell cd cmd && $(GO) list ./... | grep -v vendor)
1819
arch ?= $(shell go env GOARCH)
19-
go_path = $(shell go env GOPATH)
2020

2121
ifeq ($(arch), amd64)
2222
Dockerfile_tag := ''
@@ -62,13 +62,8 @@ tidy:
6262

6363
format:
6464
@echo ">> formatting code"
65-
@$(GO) fmt $(pkgs)
66-
@cd cmd && $(GO) fmt $(cmd_pkgs)
67-
68-
vet:
69-
@echo ">> vetting code"
70-
@$(GO) vet $(pkgs)
71-
@cd cmd && $(GO) vet $(cmd_pkgs)
65+
@# goimports is a superset of gofmt.
66+
@goimports -w -local github.com/google/cadvisor .
7267

7368
build: assets
7469
@echo ">> building binaries"
@@ -88,19 +83,22 @@ docker-%:
8883
docker-build:
8984
@docker run --rm -w /go/src/github.com/google/cadvisor -v ${PWD}:/go/src/github.com/google/cadvisor golang:1.17 make build
9085

91-
presubmit: vet
92-
@echo ">> checking go formatting"
93-
@./build/check_gofmt.sh
86+
presubmit: lint
9487
@echo ">> checking go mod tidy"
9588
@./build/check_gotidy.sh
9689
@echo ">> checking file boilerplate"
9790
@./build/check_boilerplate.sh
9891

9992
lint:
93+
@# This assumes GOPATH/bin is in $PATH -- if not, the target will fail.
94+
@if ! golangci-lint version; then \
95+
echo ">> installing golangci-lint $(GOLANGCI_VER)"; \
96+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin $(GOLANGCI_VER); \
97+
fi
10098
@echo ">> running golangci-lint using configuration at .golangci.yml"
101-
@GOFLAGS="$(GO_FLAGS)" $(go_path)/bin/golangci-lint run
99+
@golangci-lint run
102100

103101
clean:
104102
@rm -f *.test cadvisor
105103

106-
.PHONY: all build docker format release test test-integration vet presubmit tidy
104+
.PHONY: all build docker format release test test-integration lint presubmit tidy

accelerators/nvidia_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414
package accelerators
1515

1616
import (
17-
"github.com/google/cadvisor/stats"
1817
"io/ioutil"
1918
"os"
2019
"path/filepath"
2120
"testing"
2221

22+
"github.com/google/cadvisor/stats"
23+
2324
"github.com/mindprince/gonvml"
2425
"github.com/stretchr/testify/assert"
2526
)

build/check_gofmt.sh

Lines changed: 0 additions & 27 deletions
This file was deleted.

client/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
"path"
2929
"strings"
3030

31-
"github.com/google/cadvisor/info/v1"
31+
v1 "github.com/google/cadvisor/info/v1"
3232

3333
"k8s.io/klog/v2"
3434
)

client/v2/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
"strings"
2828

2929
v1 "github.com/google/cadvisor/info/v1"
30-
"github.com/google/cadvisor/info/v2"
30+
v2 "github.com/google/cadvisor/info/v2"
3131
)
3232

3333
// Client represents the base URL for a cAdvisor client.

client/v2/client_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ import (
2424
"testing"
2525
"time"
2626

27-
"github.com/google/cadvisor/info/v1"
28-
"github.com/google/cadvisor/info/v2"
2927
"github.com/stretchr/testify/assert"
28+
29+
v1 "github.com/google/cadvisor/info/v1"
30+
v2 "github.com/google/cadvisor/info/v2"
3031
)
3132

3233
func cadvisorTestClient(path string, expectedPostObj *v1.ContainerInfoRequest, replyObj interface{}, t *testing.T) (*Client, *httptest.Server, error) {

cmd/cadvisor_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ import (
1818
"flag"
1919
"testing"
2020

21-
"github.com/google/cadvisor/container"
2221
"github.com/stretchr/testify/assert"
22+
23+
"github.com/google/cadvisor/container"
2324
)
2425

2526
func TestTcpMetricsAreDisabledByDefault(t *testing.T) {

cmd/internal/container/mesos/client.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,17 @@ package mesos
1616

1717
import (
1818
"fmt"
19+
"net/url"
20+
"sync"
21+
1922
"github.com/Rican7/retry"
2023
"github.com/Rican7/retry/strategy"
21-
"github.com/mesos/mesos-go/api/v1/lib"
24+
mesos "github.com/mesos/mesos-go/api/v1/lib"
2225
"github.com/mesos/mesos-go/api/v1/lib/agent"
2326
"github.com/mesos/mesos-go/api/v1/lib/agent/calls"
2427
mclient "github.com/mesos/mesos-go/api/v1/lib/client"
2528
"github.com/mesos/mesos-go/api/v1/lib/encoding/codecs"
2629
"github.com/mesos/mesos-go/api/v1/lib/httpcli"
27-
"net/url"
28-
"sync"
2930
)
3031

3132
const (

0 commit comments

Comments
 (0)