From ebf711a6484724bcf368ad91978c3f410d9b7e0d Mon Sep 17 00:00:00 2001 From: Kevin Lingerfelt Date: Thu, 20 Dec 2018 14:08:31 -0800 Subject: [PATCH 1/3] Add go linting to CI config Signed-off-by: Kevin Lingerfelt --- .travis.yml | 1 + Gopkg.lock | 15 +++++++++++++++ Gopkg.toml | 1 + bin/lint | 23 +++++++++++++++++++++++ cli/Dockerfile-bin | 2 +- controller/Dockerfile | 2 +- proxy-init/Dockerfile | 2 +- web/Dockerfile | 2 +- 8 files changed, 44 insertions(+), 4 deletions(-) create mode 100755 bin/lint diff --git a/.travis.yml b/.travis.yml index 72ac9e598bfc0..00fa96b8aed65 100644 --- a/.travis.yml +++ b/.travis.yml @@ -37,6 +37,7 @@ jobs: - ./bin/protoc-go.sh - go test -race -v ./... - go vet ./... + - ./bin/lint - language: node_js node_js: diff --git a/Gopkg.lock b/Gopkg.lock index 72e38641f0451..ff511b8e540e4 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -443,6 +443,17 @@ pruneopts = "" revision = "d9133f5469342136e669e85192a26056b587f503" +[[projects]] + branch = "master" + digest = "1:053024e8981dab276218a180e58f97034d06e8c4dd2e24c9365ad489104e1d90" + name = "golang.org/x/lint" + packages = [ + ".", + "golint", + ] + pruneopts = "" + revision = "8f45f776aaf18cebc8d65861cc70c33c60471952" + [[projects]] branch = "master" digest = "1:e8c91565d4707bd93aa70e096884ce533acc5deb2bbb500bb064f49de70acda0" @@ -525,6 +536,9 @@ name = "golang.org/x/tools" packages = [ "go/ast/astutil", + "go/gcexportdata", + "go/internal/gcimporter", + "go/types/typeutil", "imports", "internal/fastwalk", ] @@ -963,6 +977,7 @@ "github.com/sergi/go-diff/diffmatchpatch", "github.com/sirupsen/logrus", "github.com/spf13/cobra", + "golang.org/x/lint/golint", "golang.org/x/net/context", "google.golang.org/grpc", "google.golang.org/grpc/codes", diff --git a/Gopkg.toml b/Gopkg.toml index 9d027bda72900..60a1e12b94612 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -1,5 +1,6 @@ required = [ "github.com/golang/protobuf/protoc-gen-go", + "golang.org/x/lint/golint", "k8s.io/code-generator/cmd/client-gen", "k8s.io/code-generator/cmd/deepcopy-gen", "k8s.io/code-generator/cmd/defaulter-gen", diff --git a/bin/lint b/bin/lint new file mode 100755 index 0000000000000..bdad38a4253da --- /dev/null +++ b/bin/lint @@ -0,0 +1,23 @@ +#!/bin/bash + +set -eu + +cd "$(pwd -P)" + +bindir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +rootdir="$( cd $bindir/.. && pwd )" + +cd "$rootdir" + +# install golint from vendor +go install ./vendor/golang.org/x/lint/golint + +# use `go list` to exclude packages in vendor, ignore uncommented warnings +out=$(go list ./... | xargs golint | grep -v 'should have comment') || true + +if [ -n "$out" ]; then + echo "$out" + exit 1 +fi + +echo "all clean!" diff --git a/cli/Dockerfile-bin b/cli/Dockerfile-bin index 3f3deb3e98fdc..c0aae894fd602 100644 --- a/cli/Dockerfile-bin +++ b/cli/Dockerfile-bin @@ -1,5 +1,5 @@ ## compile binaries -FROM gcr.io/linkerd-io/go-deps:cd57a76a as golang +FROM gcr.io/linkerd-io/go-deps:4b31aa9b as golang WORKDIR /go/src/github.com/linkerd/linkerd2 COPY cli cli COPY controller/k8s controller/k8s diff --git a/controller/Dockerfile b/controller/Dockerfile index f9f9c081855e3..7853072aa6f3c 100644 --- a/controller/Dockerfile +++ b/controller/Dockerfile @@ -1,5 +1,5 @@ ## compile controller services -FROM gcr.io/linkerd-io/go-deps:cd57a76a as golang +FROM gcr.io/linkerd-io/go-deps:4b31aa9b as golang WORKDIR /go/src/github.com/linkerd/linkerd2 COPY controller/gen controller/gen COPY pkg pkg diff --git a/proxy-init/Dockerfile b/proxy-init/Dockerfile index 940c011fabced..a63d6455ba5f6 100644 --- a/proxy-init/Dockerfile +++ b/proxy-init/Dockerfile @@ -1,5 +1,5 @@ ## compile proxy-init utility -FROM gcr.io/linkerd-io/go-deps:cd57a76a as golang +FROM gcr.io/linkerd-io/go-deps:4b31aa9b as golang WORKDIR /go/src/github.com/linkerd/linkerd2 COPY ./proxy-init ./proxy-init RUN CGO_ENABLED=0 GOOS=linux go install -v ./proxy-init/ diff --git a/web/Dockerfile b/web/Dockerfile index 75c1ae32ca067..7f20995c7f6fe 100644 --- a/web/Dockerfile +++ b/web/Dockerfile @@ -26,7 +26,7 @@ COPY web/app . RUN $ROOT/bin/web build ## compile go server -FROM gcr.io/linkerd-io/go-deps:cd57a76a as golang +FROM gcr.io/linkerd-io/go-deps:4b31aa9b as golang WORKDIR /go/src/github.com/linkerd/linkerd2 RUN mkdir -p web COPY web/main.go web From 93299416d609f74cc5d8417363e3b1833deb6c70 Mon Sep 17 00:00:00 2001 From: Kevin Lingerfelt Date: Thu, 20 Dec 2018 14:39:21 -0800 Subject: [PATCH 2/3] Fix lint warnings Signed-off-by: Kevin Lingerfelt --- controller/api/proxy/server.go | 4 +++- controller/api/public/test_helper.go | 1 - controller/api/util/api_utils.go | 4 ++-- controller/ca/ca.go | 3 ++- controller/gen/apis/serviceprofile/v1alpha1/types.go | 2 +- pkg/util/http.go | 2 ++ 6 files changed, 10 insertions(+), 6 deletions(-) diff --git a/controller/api/proxy/server.go b/controller/api/proxy/server.go index e2515e511e69c..8ecf3852f22cb 100644 --- a/controller/api/proxy/server.go +++ b/controller/api/proxy/server.go @@ -20,7 +20,9 @@ type server struct { enableTLS bool } -// The proxy-api service serves service discovery and other information to the +// NewServer returns a new instance of the proxy-api server. +// +// The proxy-api server serves service discovery and other information to the // proxy. This implementation supports the "k8s" destination scheme and expects // destination paths to be of the form: // ..svc.cluster.local: diff --git a/controller/api/public/test_helper.go b/controller/api/public/test_helper.go index e4cb7c5b56ed7..1c3fe5d861e7c 100644 --- a/controller/api/public/test_helper.go +++ b/controller/api/public/test_helper.go @@ -122,7 +122,6 @@ type PodCounts struct { FailedPods uint64 } -// satisfies v1.API func (m *MockProm) Query(ctx context.Context, query string, ts time.Time) (model.Value, error) { m.rwLock.Lock() defer m.rwLock.Unlock() diff --git a/controller/api/util/api_utils.go b/controller/api/util/api_utils.go index aa46e067a99da..c351fb753e3bc 100644 --- a/controller/api/util/api_utils.go +++ b/controller/api/util/api_utils.go @@ -48,8 +48,8 @@ var ( } ) -// Parameters that are used to build requests for metrics data. This includes -// requests to StatSummary and TopRoutes +// StatsBaseRequestParams contains parameters that are used to build requests +// for metrics data. This includes requests to StatSummary and TopRoutes type StatsBaseRequestParams struct { TimeWindow string Namespace string diff --git a/controller/ca/ca.go b/controller/ca/ca.go index 460c4fd9689ab..74246ed53ea15 100644 --- a/controller/ca/ca.go +++ b/controller/ca/ca.go @@ -11,6 +11,7 @@ import ( "time" ) +// CA provides a certificate authority for TLS-enabled installs. // Issuing certificates concurrently is not supported. type CA struct { // validity is the duration for which issued certificates are valid. This @@ -104,7 +105,7 @@ func NewCA() (*CA, error) { return &ca, nil } -// TrustAnchorDER returns the PEM-encoded X.509 certificate of the trust anchor +// TrustAnchorPEM returns the PEM-encoded X.509 certificate of the trust anchor // (root CA). func (ca *CA) TrustAnchorPEM() string { return ca.rootPEM diff --git a/controller/gen/apis/serviceprofile/v1alpha1/types.go b/controller/gen/apis/serviceprofile/v1alpha1/types.go index e6681b3f859c9..4ff05245411da 100644 --- a/controller/gen/apis/serviceprofile/v1alpha1/types.go +++ b/controller/gen/apis/serviceprofile/v1alpha1/types.go @@ -62,7 +62,7 @@ type Range struct { // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -// MyResourceList is a list of MyResource resources +// ServiceProfileList is a list of ServiceProfile resources type ServiceProfileList struct { metav1.TypeMeta `json:",inline"` metav1.ListMeta `json:"metadata"` diff --git a/pkg/util/http.go b/pkg/util/http.go index 1a7370346e258..260579342ec5a 100644 --- a/pkg/util/http.go +++ b/pkg/util/http.go @@ -6,6 +6,7 @@ import ( httpPb "github.com/linkerd/linkerd2-proxy-api/go/http_types" ) +// ParseScheme converts a scheme string to protobuf // TODO: validate scheme func ParseScheme(scheme string) *httpPb.Scheme { value, ok := httpPb.Scheme_Registered_value[strings.ToUpper(scheme)] @@ -23,6 +24,7 @@ func ParseScheme(scheme string) *httpPb.Scheme { } } +// ParseMethod converts a method string to protobuf // TODO: validate method func ParseMethod(method string) *httpPb.HttpMethod { value, ok := httpPb.HttpMethod_Registered_value[strings.ToUpper(method)] From 7a349cbf793cd085b6ff9945a52fa5354b6670f5 Mon Sep 17 00:00:00 2001 From: Kevin Lingerfelt Date: Thu, 20 Dec 2018 15:25:17 -0800 Subject: [PATCH 3/3] Add note about bin/lint script in TEST.md Signed-off-by: Kevin Lingerfelt --- TEST.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/TEST.md b/TEST.md index ecf9bcde19bc7..17d0049e437a0 100644 --- a/TEST.md +++ b/TEST.md @@ -37,6 +37,12 @@ To analyze the Go code without running tests, run: go vet ./... ``` +To lint the Go code using golint, run: + +```bash +bin/lint +``` + ## Javascript Javascript dependencies are managed via [yarn](https://yarnpkg.com/) and