Skip to content

Commit c22afe9

Browse files
Use golangci-lint as linter for Go (#1671)
* use golangci-lint as linter for Go instead of golint * Update hack/verify-golangci-lint.sh Co-authored-by: Andrey Velichkevich <[email protected]> * specify golangci-lint version Co-authored-by: Andrey Velichkevich <[email protected]> * fix echo comment Co-authored-by: Andrey Velichkevich <[email protected]> * fix echo comment Co-authored-by: Andrey Velichkevich <[email protected]> * fix lint * fix gofmt * fix generated codes * close the connection for early stopping without using defer * do not create or delete any resources within gomega.Eventually * add condition to return error in getKatibJob func * remove comment out lines * simplify some codes Co-authored-by: Andrey Velichkevich <[email protected]> * remove an unnecessary variable Co-authored-by: Andrey Velichkevich <[email protected]> * fix golangci-lint error Co-authored-by: Andrey Velichkevich <[email protected]> Co-authored-by: Andrey Velichkevich <[email protected]>
1 parent b0e9174 commit c22afe9

File tree

38 files changed

+421
-332
lines changed

38 files changed

+421
-332
lines changed

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
HAS_LINT := $(shell command -v golint;)
1+
HAS_LINT := $(shell command -v golangci-lint;)
22
COMMIT := v1beta1-$(shell git rev-parse --short=7 HEAD)
33
KATIB_REGISTRY := docker.io/kubeflowkatib
44

@@ -14,10 +14,10 @@ fmt:
1414

1515
lint:
1616
ifndef HAS_LINT
17-
go get -u golang.org/x/lint/golint
18-
echo "installing golint"
17+
go get -u github.com/golangci/golangci-lint/cmd/[email protected]
18+
echo "golangci-lint has been installed"
1919
endif
20-
hack/verify-golint.sh
20+
hack/verify-golangci-lint.sh
2121

2222
vet:
2323
go vet ./pkg/... ./cmd/...

cmd/metricscollector/v1beta1/file-metricscollector/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,6 @@ func watchMetricsFile(mFile string, stopRules stopRulesFlag, filters []string) {
308308
if err != nil {
309309
klog.Fatalf("Could not connect to Early Stopping service, error: %v", err)
310310
}
311-
defer conn.Close()
312311
c := api.NewEarlyStoppingClient(conn)
313312

314313
setTrialStatusReq := &api.SetTrialStatusRequest{
@@ -320,9 +319,9 @@ func watchMetricsFile(mFile string, stopRules stopRulesFlag, filters []string) {
320319
if err != nil {
321320
klog.Fatalf("Set Trial status error: %v", err)
322321
}
322+
conn.Close()
323323

324324
klog.Infof("Trial status is successfully updated")
325-
326325
}
327326
}
328327
}

hack/.golint_failures

Whitespace-only changes.

hack/verify-golangci-lint.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2021 The Kubeflow Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -o errexit
18+
set -o pipefail
19+
20+
cd $(dirname "$0")/..
21+
22+
if ! which golangci-lint >/dev/null; then
23+
echo 'Can not find golangci-lint, install with: make lint'
24+
exit 1
25+
fi
26+
27+
echo 'Running golangci-lint'
28+
golangci-lint run --timeout 5m

hack/verify-golint.sh

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

pkg/apis/controller/common/v1beta1/common_types.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,14 +200,14 @@ const (
200200
StdOutCollector CollectorKind = "StdOut"
201201

202202
FileCollector CollectorKind = "File"
203-
DefaultFilePath = "/var/log/katib/metrics.log"
203+
DefaultFilePath string = "/var/log/katib/metrics.log"
204204

205205
TfEventCollector CollectorKind = "TensorFlowEvent"
206-
DefaultTensorflowEventDirPath = "/var/log/katib/tfevent/"
206+
DefaultTensorflowEventDirPath string = "/var/log/katib/tfevent/"
207207

208208
PrometheusMetricCollector CollectorKind = "PrometheusMetric"
209-
DefaultPrometheusPath = "/metrics"
210-
DefaultPrometheusPort = 8080
209+
DefaultPrometheusPath string = "/metrics"
210+
DefaultPrometheusPort int = 8080
211211

212212
CustomCollector CollectorKind = "Custom"
213213

pkg/apis/controller/experiments/v1beta1/util.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ import (
2323
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2424
)
2525

26-
const (
27-
cleanDataFinalizer = "clean-data-in-db"
28-
)
29-
3026
func getCondition(exp *Experiment, condType ExperimentConditionType) *ExperimentCondition {
3127
if exp.Status.Conditions != nil {
3228
for _, condition := range exp.Status.Conditions {

pkg/controller.v1beta1/experiment/experiment_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ func (r *ReconcileExperiment) ReconcileExperiment(instance *experimentsv1beta1.E
278278
}
279279
reconcileRequired := !instance.IsCompleted()
280280
if reconcileRequired {
281-
r.ReconcileTrials(instance, trials.Items)
281+
return r.ReconcileTrials(instance, trials.Items)
282282
}
283283

284284
return nil

pkg/controller.v1beta1/experiment/experiment_controller_suite_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,19 @@ func TestMain(m *testing.M) {
4646
filepath.Join("..", "..", "..", "manifests", "v1beta1", "components", "crd"),
4747
},
4848
}
49-
apis.AddToScheme(scheme.Scheme)
50-
5149
var err error
50+
if err = apis.AddToScheme(scheme.Scheme); err != nil {
51+
stdlog.Fatal(err)
52+
}
53+
5254
if cfg, err = t.Start(); err != nil {
5355
stdlog.Fatal(err)
5456
}
5557

5658
code := m.Run()
57-
t.Stop()
59+
if err = t.Stop(); err != nil {
60+
stdlog.Fatal(err)
61+
}
5862
os.Exit(code)
5963
}
6064

0 commit comments

Comments
 (0)