From 5c0a06bde3c3e2f4922f44973a30c18519d2aff7 Mon Sep 17 00:00:00 2001 From: Ce Gao Date: Wed, 11 Sep 2019 12:18:46 -0500 Subject: [PATCH] feat: Replace gometalinter with golangci-lint (#1081) * feat: Replace gometaliner with golangci-lint Signed-off-by: Ce Gao * fix: Fix go version Signed-off-by: Ce Gao * fix: Update goveralls Signed-off-by: Ce Gao --- .travis.yml | 9 +++-- linter_config.json | 37 -------------------- pkg/controller.v1/tensorflow/job_test.go | 8 +++-- pkg/controller.v1/tensorflow/pod_test.go | 16 +++++---- pkg/controller.v1/tensorflow/service_test.go | 4 ++- 5 files changed, 23 insertions(+), 51 deletions(-) delete mode 100644 linter_config.json diff --git a/.travis.yml b/.travis.yml index 3738623fc9..f3af0ba66a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,22 +1,21 @@ language: go go: - - "1.10" + - "1.12" go_import_path: github.com/kubeflow/tf-operator install: # get coveralls.io support - go get github.com/mattn/goveralls - - go get -u github.com/alecthomas/gometalinter - - gometalinter --install + - curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(go env GOPATH)/bin v1.18.0 - go install ./vendor/k8s.io/code-generator/cmd/openapi-gen script: - hack/verify-codegen.sh - go build -o tf-operator.v1 github.com/kubeflow/tf-operator/cmd/tf-operator.v1 - go build -o backend github.com/kubeflow/tf-operator/dashboard/backend - - gometalinter --config=linter_config.json --vendor ./... + - golangci-lint run ./... # We customize the build step because by default # Travis runs go test -v ./... which will include the vendor # directory. @@ -24,7 +23,7 @@ script: # For now though we just run all tests in pkg. # And we can not use ** because goveralls uses filepath.Match # to match ignore files and it does not support it. - - goveralls -service=travis-ci -v -package ./pkg/... -ignore "pkg/client/*/*.go,pkg/client/*/*/*.go,pkg/client/*/*/*/*.go,pkg/client/*/*/*/*/*.go,pkg/client/*/*/*/*/*/*.go,pkg/client/*/*/*/*/*/*/*.go,pkg/util/testutil/*.go,pkg/apis/tensorflow/*/zz_generated.*.go,pkg/apis/tensorflow/*/*_generated.go,pkg/apis/common/*/zz_generated.*.go,pkg/apis/common/*/*_generated.go" + - goveralls -service=travis-ci -v -package ./pkg/... -ignore "pkg/client/*/*.go,pkg/client/*/*/*.go,pkg/client/*/*/*/*.go,pkg/client/*/*/*/*/*.go,pkg/client/*/*/*/*/*/*.go,pkg/client/*/*/*/*/*/*/*.go,pkg/util/*.go,pkg/util/*/*.go,pkg/apis/tensorflow/*/zz_generated.*.go,pkg/apis/tensorflow/*/*_generated.go,pkg/apis/common/*/zz_generated.*.go,pkg/apis/common/*/*_generated.go" notifications: webhooks: https://www.travisbuddy.com/ diff --git a/linter_config.json b/linter_config.json deleted file mode 100644 index 1b7bcf9b85..0000000000 --- a/linter_config.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "Vendor": true, - "DisableAll": true, - "Enable": [ - "vet", - "safesql", - "errcheck", - "goconst", - "goimports", - "varcheck", - "gosec", - "gotype", - "staticcheck", - "lll", - "unconvert", - "misspell", - "unconvert" - ], - "Aggregate": true, - "WarnUnmatchedNolint": true, - "LineLength": 240, - "Exclude": [ - "redundant return statement", - "comment or be unexported", - "comment on exported", - "pkg/apis/common/v1/zz_generated.deepcopy.go", - "pkg/apis/common/v1/zz_generated.defaults.go", - "pkg/apis/common/v1/openapi_generated.go", - "pkg/apis/tensorflow/validation/validation_test.go", - "pkg/apis/tensorflow/v1/zz_generated.deepcopy.go", - "pkg/apis/tensorflow/v1/zz_generated.defaults.go", - "pkg/apis/tensorflow/v1/openapi_generated.go", - "dashboard/backend/handler/api_handler.go" - ], - "Deadline": "600s", - "Skip": ["pkg/client"] -} diff --git a/pkg/controller.v1/tensorflow/job_test.go b/pkg/controller.v1/tensorflow/job_test.go index 383e7c99cf..4286a93430 100644 --- a/pkg/controller.v1/tensorflow/job_test.go +++ b/pkg/controller.v1/tensorflow/job_test.go @@ -68,7 +68,9 @@ func TestAddTFJob(t *testing.T) { stopCh := make(chan struct{}) run := func(<-chan struct{}) { - ctr.Run(testutil.ThreadCount, stopCh) + if err := ctr.Run(testutil.ThreadCount, stopCh); err != nil { + t.Errorf("Failed to run the controller: %v", err) + } } go run(stopCh) @@ -139,7 +141,9 @@ func TestCopyLabelsAndAnnotation(t *testing.T) { stopCh := make(chan struct{}) run := func(<-chan struct{}) { - ctr.Run(testutil.ThreadCount, stopCh) + if err := ctr.Run(testutil.ThreadCount, stopCh); err != nil { + t.Errorf("Failed to run the controller: %v", err) + } } go run(stopCh) diff --git a/pkg/controller.v1/tensorflow/pod_test.go b/pkg/controller.v1/tensorflow/pod_test.go index fe67394cff..cd86403a77 100644 --- a/pkg/controller.v1/tensorflow/pod_test.go +++ b/pkg/controller.v1/tensorflow/pod_test.go @@ -66,7 +66,9 @@ func TestAddPod(t *testing.T) { stopCh := make(chan struct{}) run := func(<-chan struct{}) { - ctr.Run(testutil.ThreadCount, stopCh) + if err := ctr.Run(testutil.ThreadCount, stopCh); err != nil { + t.Errorf("Failed to run the controller: %v", err) + } } go run(stopCh) @@ -166,7 +168,7 @@ func TestRestartPolicy(t *testing.T) { specRestartPolicy := common.RestartPolicyExitCode tfJob.Spec.TFReplicaSpecs[tfv1.TFReplicaTypeWorker].RestartPolicy = specRestartPolicy return tc{ - tfJob: tfJob, + tfJob: tfJob, expectedRestartPolicy: v1.RestartPolicyNever, expectedType: tfv1.TFReplicaTypeWorker, } @@ -176,7 +178,7 @@ func TestRestartPolicy(t *testing.T) { specRestartPolicy := common.RestartPolicyNever tfJob.Spec.TFReplicaSpecs[tfv1.TFReplicaTypeWorker].RestartPolicy = specRestartPolicy return tc{ - tfJob: tfJob, + tfJob: tfJob, expectedRestartPolicy: v1.RestartPolicyNever, expectedType: tfv1.TFReplicaTypeWorker, } @@ -186,7 +188,7 @@ func TestRestartPolicy(t *testing.T) { specRestartPolicy := common.RestartPolicyAlways tfJob.Spec.TFReplicaSpecs[tfv1.TFReplicaTypeWorker].RestartPolicy = specRestartPolicy return tc{ - tfJob: tfJob, + tfJob: tfJob, expectedRestartPolicy: v1.RestartPolicyAlways, expectedType: tfv1.TFReplicaTypeWorker, } @@ -196,7 +198,7 @@ func TestRestartPolicy(t *testing.T) { specRestartPolicy := common.RestartPolicyOnFailure tfJob.Spec.TFReplicaSpecs[tfv1.TFReplicaTypeWorker].RestartPolicy = specRestartPolicy return tc{ - tfJob: tfJob, + tfJob: tfJob, expectedRestartPolicy: v1.RestartPolicyOnFailure, expectedType: tfv1.TFReplicaTypeWorker, } @@ -249,7 +251,9 @@ func TestExitCode(t *testing.T) { stopCh := make(chan struct{}) run := func(<-chan struct{}) { - ctr.Run(testutil.ThreadCount, stopCh) + if err := ctr.Run(testutil.ThreadCount, stopCh); err != nil { + t.Errorf("Failed to run the controller: %v", err) + } } go run(stopCh) diff --git a/pkg/controller.v1/tensorflow/service_test.go b/pkg/controller.v1/tensorflow/service_test.go index d212864dc7..a01c0b30bf 100644 --- a/pkg/controller.v1/tensorflow/service_test.go +++ b/pkg/controller.v1/tensorflow/service_test.go @@ -64,7 +64,9 @@ func TestAddService(t *testing.T) { stopCh := make(chan struct{}) run := func(<-chan struct{}) { - ctr.Run(testutil.ThreadCount, stopCh) + if err := ctr.Run(testutil.ThreadCount, stopCh); err != nil { + t.Errorf("Failed to run the controller: %v", err) + } } go run(stopCh)