Skip to content

Commit 5ae6698

Browse files
committed
ci: enable golangci-lint
1 parent 3f4a6c5 commit 5ae6698

File tree

13 files changed

+665
-216
lines changed

13 files changed

+665
-216
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,6 @@ _output/
2828

2929
# e2e output
3030
tests/e2e/generated_manifests/*
31+
32+
# Go tools
33+
.tools/

.golangci.yml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
run:
2+
timeout: 5m
3+
skip-dirs:
4+
skip-files:
5+
6+
linters:
7+
disable-all: true
8+
enable:
9+
- deadcode
10+
- goconst
11+
- gocyclo
12+
- gofmt
13+
- goimports
14+
- golint
15+
- gosec
16+
- gosimple
17+
- govet
18+
- ineffassign
19+
- maligned
20+
- misspell
21+
- nakedret
22+
- prealloc
23+
- staticcheck
24+
- structcheck
25+
- unused
26+
- varcheck

.pipelines/unit-tests-template.yml

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ jobs:
1313
version: 1.15
1414
- script: make build
1515
displayName: Build
16+
- script: make lint
17+
displayName: Run lint
1618
- script: make unit-test
1719
displayName: Run unit tests
1820
- script: |

Makefile

+12
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ BUILD_DATE := $$(date +%Y-%m-%d-%H:%M)
1717
GIT_VAR := $(REPO_PATH)/pkg/version.GitCommit
1818
GIT_HASH := $$(git rev-parse --short HEAD)
1919

20+
GO_FILES=$(shell go list ./... | grep -v /test/e2e)
21+
TOOLS_MOD_DIR := ./tools
22+
TOOLS_DIR := $(abspath ./.tools)
23+
2024
# docker env var
2125
DOCKER_BUILDKIT = 1
2226
export DOCKER_BUILDKIT
@@ -28,6 +32,14 @@ BATS_VERSION ?= 1.2.1
2832

2933
GO_BUILD_OPTIONS := --tags "netgo osusergo" -ldflags "-s -X $(BUILD_VERSION_VAR)=$(IMAGE_VERSION) -X $(GIT_VAR)=$(GIT_HASH) -X $(BUILD_DATE_VAR)=$(BUILD_DATE) -extldflags '-static'"
3034

35+
$(TOOLS_DIR)/golangci-lint: $(TOOLS_MOD_DIR)/go.mod $(TOOLS_MOD_DIR)/go.sum $(TOOLS_MOD_DIR)/tools.go
36+
cd $(TOOLS_MOD_DIR) && \
37+
go build -o $(TOOLS_DIR)/golangci-lint github.com/golangci/golangci-lint/cmd/golangci-lint
38+
39+
.PHONY: lint
40+
lint: $(TOOLS_DIR)/golangci-lint
41+
$(TOOLS_DIR)/golangci-lint run --timeout=5m -v
42+
3143
.PHONY: build
3244
build:
3345
$Q GOOS=linux CGO_ENABLED=0 go build $(GO_BUILD_OPTIONS) -o _output/kubernetes-kms ./cmd/server/

go.mod

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ require (
88
github.com/Azure/go-autorest/autorest/adal v0.8.2
99
github.com/Azure/go-autorest/autorest/to v0.4.0 // indirect
1010
github.com/Azure/go-autorest/autorest/validation v0.3.0 // indirect
11-
github.com/golang/mock v1.3.1
12-
github.com/golang/protobuf v1.4.2
1311
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
1412
golang.org/x/net v0.0.0-20200707034311-ab3426394381
1513
google.golang.org/grpc v1.27.0

pkg/plugin/mock_keyvault/keyvault_mock.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// This source code is licensed under the MIT license found in the
44
// LICENSE file in the root directory of this source tree.
55

6-
package mock_keyvault
6+
package mockkeyvault
77

88
import (
99
"context"
@@ -36,13 +36,11 @@ func (kvc *KeyVaultClient) SetEncryptResponse(encryptOut []byte, err error) {
3636
defer kvc.mutex.Unlock()
3737
kvc.encryptOut = encryptOut
3838
kvc.encryptErr = err
39-
return
4039
}
4140

4241
func (kvc *KeyVaultClient) SetDecryptResponse(decryptOut []byte, err error) {
4342
kvc.mutex.Lock()
4443
defer kvc.mutex.Unlock()
4544
kvc.decryptOut = decryptOut
4645
kvc.decryptErr = err
47-
return
4846
}

pkg/plugin/server_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
k8spb "k8s.io/apiserver/pkg/storage/value/encrypt/envelope/v1beta1"
1414

15-
"github.com/Azure/kubernetes-kms/pkg/plugin/mock_keyvault"
15+
mockkeyvault "github.com/Azure/kubernetes-kms/pkg/plugin/mock_keyvault"
1616
"github.com/Azure/kubernetes-kms/pkg/version"
1717
)
1818

@@ -39,7 +39,7 @@ func TestEncrypt(t *testing.T) {
3939

4040
for _, test := range tests {
4141
t.Run(test.desc, func(t *testing.T) {
42-
kvClient := &mock_keyvault.KeyVaultClient{}
42+
kvClient := &mockkeyvault.KeyVaultClient{}
4343
kvClient.SetEncryptResponse(test.output, test.err)
4444

4545
kmsServer := KeyManagementServiceServer{
@@ -82,7 +82,7 @@ func TestDecrypt(t *testing.T) {
8282

8383
for _, test := range tests {
8484
t.Run(test.desc, func(t *testing.T) {
85-
kvClient := &mock_keyvault.KeyVaultClient{}
85+
kvClient := &mockkeyvault.KeyVaultClient{}
8686
kvClient.SetDecryptResponse(test.output, test.err)
8787

8888
kmsServer := KeyManagementServiceServer{

pkg/version/version.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ var (
1111
BuildDate string
1212
// GitCommit is the commit hash when the binary was built
1313
GitCommit string
14-
// BinaryVersion is the version of the KMS binary
14+
// BuildVersion is the version of the KMS binary
1515
BuildVersion string
1616
APIVersion = "v1beta1"
1717
Runtime = "Microsoft AzureKMS"

tests/grpc/mock_v1beta1/kmsc_mock.go

-91
This file was deleted.

tests/grpc/mock_v1beta1/kmsc_mock_test.go

-116
This file was deleted.

tools/go.mod

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module github.com/Azure/kubernetes-kms/tools
2+
3+
go 1.15
4+
5+
require github.com/golangci/golangci-lint v1.30.0

0 commit comments

Comments
 (0)