Skip to content

Commit c5cc68d

Browse files
authored
[Cleanup] Linter code cleaning (#718)
1 parent e559f21 commit c5cc68d

File tree

88 files changed

+371
-764
lines changed

Some content is hidden

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

88 files changed

+371
-764
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ install:
1313
- make init
1414

1515
script:
16-
- make license-verify fmt-verify
16+
- make license-verify fmt-verify linter
1717
- make run-unit-tests
1818
- make bin

Makefile

+10-11
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ ifdef VERBOSE
138138
TESTVERBOSEOPTIONS := -v
139139
endif
140140

141+
EXCLUDE_DIRS := tests vendor .gobuild deps tools
141142
SOURCES_QUERY := find $(SRCDIR) -name '*.go' -type f -not -path '$(SRCDIR)/tests/*' -not -path '$(SRCDIR)/vendor/*' -not -path '$(SRCDIR)/.gobuild/*' -not -path '$(SRCDIR)/deps/*' -not -path '$(SRCDIR)/tools/*'
142143
SOURCES := $(shell $(SOURCES_QUERY))
143-
SOURCES_PACKAGES := $(shell $(SOURCES_QUERY) -exec dirname {} \; | sort | uniq)
144144
DASHBOARDSOURCES := $(shell find $(DASHBOARDDIR)/src -name '*.js' -not -path './test/*') $(DASHBOARDDIR)/package.json
145145

146146
ifndef ARANGOSYNCSRCDIR
@@ -174,10 +174,8 @@ allall: all
174174
# Tip: Run `eval $(minikube docker-env)` before calling make if you're developing on minikube.
175175
#
176176

177-
GOLANGCI_ENABLED=deadcode gocyclo golint varcheck structcheck maligned errcheck \
178-
ineffassign interfacer unconvert goconst \
179-
megacheck
180-
177+
GOLANGCI_ENABLED=deadcode govet ineffassign staticcheck structcheck typecheck unconvert unparam unused varcheck
178+
#GOLANGCI_ENABLED=gocyclo goconst golint maligned errcheck interfacer megacheck
181179
#GOLANGCI_ENABLED+=dupl - disable dupl check
182180

183181
.PHONY: license-verify
@@ -201,11 +199,10 @@ fmt-verify: license-verify
201199
@if [ X"$$(go run golang.org/x/tools/cmd/goimports -l $(SOURCES) | wc -l)" != X"0" ]; then echo ">> Style errors"; go run golang.org/x/tools/cmd/goimports -l $(SOURCES); exit 1; fi
202200

203201
.PHONY: linter
204-
linter: fmt
205-
@golangci-lint run --no-config --issues-exit-code=1 --deadline=30m --disable-all \
206-
$(foreach MODE,$(GOLANGCI_ENABLED),--enable $(MODE) ) \
207-
--exclude-use-default=false \
208-
$(SOURCES_PACKAGES)
202+
linter:
203+
$(GOPATH)/bin/golangci-lint run --no-config --issues-exit-code=1 --deadline=30m --exclude-use-default=false \
204+
--disable-all $(foreach EXCLUDE_DIR,$(EXCLUDE_DIRS),--skip-dirs $(EXCLUDE_DIR)) \
205+
$(foreach MODE,$(GOLANGCI_ENABLED),--enable $(MODE)) ./...
209206

210207
.PHONY: build
211208
build: docker manifests
@@ -599,6 +596,8 @@ init: tools update-generated $(GHRELEASE) $(RELEASE) $(TESTBIN) $(BIN) vendor
599596

600597
.PHONY: tools
601598
tools: update-vendor
599+
@echo ">> Fetching golangci-lint linter"
600+
@go install github.com/golangci/golangci-lint/cmd/golangci-lint
602601
@echo ">> Fetching goimports"
603602
@go get -u golang.org/x/tools/cmd/goimports
604603
@echo ">> Fetching license check"
@@ -653,4 +652,4 @@ synchronize-v2alpha1-with-v1:
653652
@for file in $$(find "$(ROOT)/pkg/apis/deployment/v1/" -type f -exec realpath --relative-to "$(ROOT)/pkg/apis/deployment/v1/" {} \;); do cat "$(ROOT)/pkg/apis/deployment/v1/$${file}" | sed "s#package v1#package v2alpha1#g" | sed 's#ArangoDeploymentVersion = "v1"#ArangoDeploymentVersion = "v2alpha1"#g' > "$(ROOT)/pkg/apis/deployment/v2alpha1/$${file}"; done
654653
@make update-generated
655654
@make set-deployment-api-version-v2alpha1 bin
656-
@make set-deployment-api-version-v1 bin
655+
@make set-deployment-api-version-v1 bin

pkg/apis/deployment/v1/timeouts.go

-4
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ import (
2828
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
2929
)
3030

31-
const (
32-
addMemberTimeout = time.Minute * 5
33-
)
34-
3531
type Timeouts struct {
3632
AddMember *Timeout `json:"addMember,omitempty"`
3733
}

pkg/apis/deployment/v2alpha1/timeouts.go

-4
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ import (
2828
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
2929
)
3030

31-
const (
32-
addMemberTimeout = time.Minute * 5
33-
)
34-
3531
type Timeouts struct {
3632
AddMember *Timeout `json:"addMember,omitempty"`
3733
}

pkg/backup/handlers/arango/backup/backup_suite_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,6 @@ func wrapperProgressMissing(t *testing.T, state state.State) {
264264
newObj := refreshArangoBackup(t, handler, obj)
265265
require.Equal(t, newObj.Status.State, backupApi.ArangoBackupStateFailed)
266266

267-
require.Equal(t, newObj.Status.Message, createStateMessage(state, backupApi.ArangoBackupStateFailed, fmt.Sprintf("missing field .status.backup")))
268-
267+
require.Equal(t, newObj.Status.Message, createStateMessage(state, backupApi.ArangoBackupStateFailed, "missing field .status.backup"))
269268
})
270269
}

pkg/backup/handlers/arango/backup/finalizer.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,15 @@ func hasFinalizers(backup *backupApi.ArangoBackup) bool {
175175
}
176176

177177
for _, finalizer := range backupApi.FinalizersArangoBackup {
178-
if !hasFinalizer(backup, finalizer) {
178+
if !hasFinalizer(finalizer) {
179179
return false
180180
}
181181
}
182182

183183
return true
184184
}
185185

186-
func hasFinalizer(backup *backupApi.ArangoBackup, finalizer string) bool {
186+
func hasFinalizer(finalizer string) bool {
187187
if backupApi.FinalizersArangoBackup == nil {
188188
return false
189189
}
@@ -209,7 +209,7 @@ func appendFinalizers(backup *backupApi.ArangoBackup) []string {
209209
old := backup.Finalizers
210210

211211
for _, finalizer := range backupApi.FinalizersArangoBackup {
212-
if !hasFinalizer(backup, finalizer) {
212+
if !hasFinalizer(finalizer) {
213213
old = append(old, finalizer)
214214
}
215215
}

pkg/backup/handlers/arango/backup/status.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func setFailedState(backup *backupApi.ArangoBackup, err error) (*backupApi.Arang
118118
updateStatusAvailable(false))
119119
}
120120

121-
func createStateMessage(from, to state.State, message string) string {
121+
func createStateMessage(from, to state.State, message string) string { // nolint:unparam
122122
return fmt.Sprintf("Transiting from %s to %s: %s", from, to, message)
123123
}
124124

pkg/backup/handlers/arango/policy/handler.go

+10-14
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,7 @@ func (h *handler) Handle(item operation.Item) error {
7474
return err
7575
}
7676

77-
status, err := h.processBackupPolicy(policy.DeepCopy())
78-
if err != nil {
79-
return err
80-
}
81-
77+
status := h.processBackupPolicy(policy.DeepCopy())
8278
// Nothing to update, objects are equal
8379
if reflect.DeepEqual(policy.Status, status) {
8480
return nil
@@ -94,13 +90,13 @@ func (h *handler) Handle(item operation.Item) error {
9490
return nil
9591
}
9692

97-
func (h *handler) processBackupPolicy(policy *backupApi.ArangoBackupPolicy) (backupApi.ArangoBackupPolicyStatus, error) {
93+
func (h *handler) processBackupPolicy(policy *backupApi.ArangoBackupPolicy) backupApi.ArangoBackupPolicyStatus {
9894
if err := policy.Validate(); err != nil {
9995
h.eventRecorder.Warning(policy, policyError, "Policy Error: %s", err.Error())
10096

10197
return backupApi.ArangoBackupPolicyStatus{
10298
Message: fmt.Sprintf("Validation error: %s", err.Error()),
103-
}, nil
99+
}
104100
}
105101

106102
now := time.Now()
@@ -111,7 +107,7 @@ func (h *handler) processBackupPolicy(policy *backupApi.ArangoBackupPolicy) (bac
111107

112108
return backupApi.ArangoBackupPolicyStatus{
113109
Message: fmt.Sprintf("error while parsing expr: %s", err.Error()),
114-
}, nil
110+
}
115111
}
116112

117113
if policy.Status.Scheduled.IsZero() {
@@ -121,7 +117,7 @@ func (h *handler) processBackupPolicy(policy *backupApi.ArangoBackupPolicy) (bac
121117
Scheduled: meta.Time{
122118
Time: next,
123119
},
124-
}, nil
120+
}
125121
}
126122

127123
// Check if schedule is required
@@ -135,10 +131,10 @@ func (h *handler) processBackupPolicy(policy *backupApi.ArangoBackupPolicy) (bac
135131
Scheduled: meta.Time{
136132
Time: next,
137133
},
138-
}, nil
134+
}
139135
}
140136

141-
return policy.Status, nil
137+
return policy.Status
142138
}
143139

144140
// Schedule new deployments
@@ -159,7 +155,7 @@ func (h *handler) processBackupPolicy(policy *backupApi.ArangoBackupPolicy) (bac
159155
return backupApi.ArangoBackupPolicyStatus{
160156
Scheduled: policy.Status.Scheduled,
161157
Message: fmt.Sprintf("deployments listing failed: %s", err.Error()),
162-
}, nil
158+
}
163159
}
164160

165161
for _, deployment := range deployments.Items {
@@ -171,7 +167,7 @@ func (h *handler) processBackupPolicy(policy *backupApi.ArangoBackupPolicy) (bac
171167
return backupApi.ArangoBackupPolicyStatus{
172168
Scheduled: policy.Status.Scheduled,
173169
Message: fmt.Sprintf("backup creation failed: %s", err.Error()),
174-
}, nil
170+
}
175171
}
176172

177173
h.eventRecorder.Normal(policy, backupCreated, "Created ArangoBackup: %s/%s", b.Namespace, b.Name)
@@ -185,7 +181,7 @@ func (h *handler) processBackupPolicy(policy *backupApi.ArangoBackupPolicy) (bac
185181
Scheduled: meta.Time{
186182
Time: next,
187183
},
188-
}, nil
184+
}
189185
}
190186

191187
func (*handler) CanBeHandled(item operation.Item) bool {

pkg/backup/handlers/arango/policy/handler_suite_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func newItem(o operation.Operation, namespace, name string) operation.Item {
6969
}
7070
}
7171

72-
func newItemFromBackupPolicy(operation operation.Operation, policy *backupApi.ArangoBackupPolicy) operation.Item {
72+
func newItemFromBackupPolicy(operation operation.Operation, policy *backupApi.ArangoBackupPolicy) operation.Item { // nolint:unparam
7373
return newItem(operation, policy.Namespace, policy.Name)
7474
}
7575

pkg/backup/operator/operator_suite_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ func mockSimpleObject(name string, canBeHandled bool) (Handler, chan operation.I
102102
})
103103
}
104104

105-
func waitForItems(t *testing.T, i <-chan operation.Item, expectedSize int, timeout time.Duration) []operation.Item {
106-
tmout := time.NewTimer(timeout)
105+
func waitForItems(t *testing.T, i <-chan operation.Item, expectedSize int) []operation.Item {
106+
tmout := time.NewTimer(time.Second)
107107
defer tmout.Stop()
108108
received := make([]operation.Item, 0, expectedSize)
109109
for {

pkg/backup/operator/operator_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func Test_Operator_InformerProcessing(t *testing.T) {
7979
}
8080

8181
// Assert
82-
res := waitForItems(t, i, size, time.Second)
82+
res := waitForItems(t, i, size)
8383
assert.Len(t, res, size)
8484

8585
time.Sleep(50 * time.Millisecond)
@@ -140,7 +140,7 @@ func Test_Operator_MultipleInformers(t *testing.T) {
140140
}
141141

142142
// Assert
143-
res := waitForItems(t, i, size*2, time.Second)
143+
res := waitForItems(t, i, size*2)
144144
assert.Len(t, res, size*2)
145145

146146
time.Sleep(50 * time.Millisecond)
@@ -200,7 +200,7 @@ func Test_Operator_MultipleInformers_IgnoredTypes(t *testing.T) {
200200
}
201201

202202
// Assert
203-
res := waitForItems(t, i, size, time.Second)
203+
res := waitForItems(t, i, size)
204204
assert.Len(t, res, size)
205205

206206
time.Sleep(50 * time.Millisecond)
@@ -300,10 +300,10 @@ func Test_Operator_MultipleInformers_MultipleHandlers(t *testing.T) {
300300
}
301301

302302
// Assert
303-
assert.Len(t, waitForItems(t, ip, size, time.Second), size)
304-
assert.Len(t, waitForItems(t, in, size, time.Second), size)
305-
assert.Len(t, waitForItems(t, is, size, time.Second), size)
306-
assert.Len(t, waitForItems(t, id, size, time.Second), size)
303+
assert.Len(t, waitForItems(t, ip, size), size)
304+
assert.Len(t, waitForItems(t, in, size), size)
305+
assert.Len(t, waitForItems(t, is, size), size)
306+
assert.Len(t, waitForItems(t, id, size), size)
307307

308308
time.Sleep(50 * time.Millisecond)
309309
assert.Len(t, ip, 0)
@@ -358,7 +358,7 @@ func Test_Operator_InformerProcessing_Namespaced(t *testing.T) {
358358
}
359359

360360
// Assert
361-
res := waitForItems(t, i, 1, time.Second)
361+
res := waitForItems(t, i, 1)
362362
assert.Len(t, res, 1)
363363

364364
time.Sleep(50 * time.Millisecond)

pkg/deployment/client/client_cache.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func (cc *cache) extendHost(host string) string {
6969
return scheme + "://" + net.JoinHostPort(host, strconv.Itoa(k8sutil.ArangoPort))
7070
}
7171

72-
func (cc *cache) getClient(ctx context.Context, group api.ServerGroup, id string) (driver.Client, error) {
72+
func (cc *cache) getClient(group api.ServerGroup, id string) (driver.Client, error) {
7373
m, _, _ := cc.apiObjectGetter().Status.Members.ElementByID(id)
7474

7575
c, err := cc.factory.Client(cc.extendHost(m.GetEndpoint(k8sutil.CreatePodDNSName(cc.apiObjectGetter(), group.AsRole(), id))))
@@ -80,15 +80,15 @@ func (cc *cache) getClient(ctx context.Context, group api.ServerGroup, id string
8080
}
8181

8282
func (cc *cache) get(ctx context.Context, group api.ServerGroup, id string) (driver.Client, error) {
83-
client, err := cc.getClient(ctx, group, id)
83+
client, err := cc.getClient(group, id)
8484
if err != nil {
8585
return nil, errors.WithStack(err)
8686
}
8787

8888
if _, err := client.Version(ctx); err == nil {
8989
return client, nil
9090
} else if driver.IsUnauthorized(err) {
91-
return cc.getClient(ctx, group, id)
91+
return cc.getClient(group, id)
9292
} else {
9393
return client, nil
9494
}
@@ -103,7 +103,7 @@ func (cc *cache) Get(ctx context.Context, group api.ServerGroup, id string) (dri
103103
return cc.get(ctx, group, id)
104104
}
105105

106-
func (cc cache) GetAuth() conn.Auth {
106+
func (cc *cache) GetAuth() conn.Auth {
107107
return cc.factory.GetAuth()
108108
}
109109

0 commit comments

Comments
 (0)