Skip to content

Commit 82ff4ec

Browse files
authored
Enable additional linters (#2318)
* Enable additional linter and formatter
1 parent 65c59f7 commit 82ff4ec

File tree

226 files changed

+19696
-6336
lines changed

Some content is hidden

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

226 files changed

+19696
-6336
lines changed

Makefile

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ GOLANGCI_LINT_PKG=github.com/golangci/golangci-lint/v2/cmd/[email protected]
3737
GOLANGCI_LINT=$(GOBIN)/golangci-lint
3838
GORELEASER_PKG=github.com/goreleaser/goreleaser/[email protected]
3939
GORELEASER=$(GOBIN)/goreleaser
40-
GO_LINES_PKG=github.com/segmentio/golines@v0.11.0
40+
GO_LINES_PKG=github.com/segmentio/golines@v0.12.2
4141
GO_LINES=$(GOBIN)/golines
42-
GO_IMPORTS_PKG=golang.org/x/tools/cmd/goimports@v0.20.0
42+
GO_IMPORTS_PKG=golang.org/x/tools/cmd/goimports@v0.34.0
4343
GO_IMPORTS=$(GOBIN)/goimports
4444

4545
BUILD_DEPS?=
@@ -93,7 +93,7 @@ clean:
9393
find . -name "cover.out" -delete
9494

9595
clean-deps:
96-
@rm $(CONTROLLER_GEN) $(KUSTOMIZE) $(GOLANGCI_LINT) $(GORELEASER)
96+
@rm $(CONTROLLER_GEN) $(KUSTOMIZE) $(GOLANGCI_LINT) $(GORELEASER) $(GO_LINES) $(GO_IMPORTS)
9797

9898
test_if_changed: cover.out
9999

@@ -121,35 +121,34 @@ bin/kubectl-fdb: ${GO_SRC} $(GORELEASER)
121121
$(GORELEASER) build --single-target --skip validate --clean
122122
@mkdir -p bin
123123
@touch $@
124-
# TODO test here that the tag is set properly
125124

126125
# Run against the configured Kubernetes cluster in ~/.kube/config
127126
run: generate manifests
128127
go run ./main.go
129128

130129
# Install CRDs into a cluster
131-
install: manifests
132-
kustomize build config/crd | kubectl $(KUBECTL_ARGS) apply -f -
130+
install: $(KUSTOMIZE) manifests
131+
$(KUSTOMIZE) build config/crd | kubectl $(KUBECTL_ARGS) apply -f -
133132

134133
# Uninstall CRDs from a cluster
135-
uninstall: manifests
136-
kustomize build config/crd | kubectl $(KUBECTL_ARGS) delete -f -
134+
uninstall: $(KUSTOMIZE) manifests
135+
$(KUSTOMIZE) build config/crd | kubectl $(KUBECTL_ARGS) delete -f -
137136

138137
# Apply config to the local development environment based on environment
139138
# variables.
140-
config/development/kustomization.yaml: config/development/kustomization.yaml.sample
139+
config/development/kustomization.yaml: $(KUSTOMIZE) config/development/kustomization.yaml.sample
141140
cp config/development/kustomization.yaml.sample config/development/kustomization.yaml
142-
cd config/development && kustomize edit set image foundationdb/fdb-kubernetes-operator=${IMG}
141+
cd config/development && $(KUSTOMIZE) edit set image foundationdb/fdb-kubernetes-operator=${IMG}
143142
ifneq "$(SIDECAR_IMG)" ""
144-
cd config/development && kustomize edit set image foundationdb/foundationdb-kubernetes-sidecar=${SIDECAR_IMG}
143+
cd config/development && $(KUSTOMIZE) edit set image foundationdb/foundationdb-kubernetes-sidecar=${SIDECAR_IMG}
145144
endif
146145
ifeq "$(REMOTE_BUILD)" "1"
147-
cd config/development && kustomize edit add patch --path=remote_build.yaml
146+
cd config/development && $(KUSTOMIZE) edit add patch --path=remote_build.yaml
148147
endif
149148

150149
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
151-
deploy: install manifests config/development/kustomization.yaml
152-
kustomize build config/development | kubectl $(KUBECTL_ARGS) apply -f -
150+
deploy: $(KUSTOMIZE) install manifests config/development/kustomization.yaml
151+
$(KUSTOMIZE) build config/development | kubectl $(KUBECTL_ARGS) apply -f -
153152

154153
# Generate manifests e.g. CRD, RBAC etc.
155154
manifests: ${MANIFESTS}
@@ -158,22 +157,21 @@ ${MANIFESTS}: ${CONTROLLER_GEN} ${GO_SRC}
158157
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./api/..." paths="./controllers/..." output:crd:artifacts:config=config/crd/bases
159158

160159
# Run go fmt against code
161-
fmt: bin/fmt_check
160+
fmt: deps bin/fmt_check
162161

163-
# TODO johscheuer: enable those new command in a new PR.
164162
bin/fmt_check: ${GO_ALL}
165-
# $(GO_LINES) -w .
166-
@go fmt $$(go list ./...)
167-
#$(GO_IMPORTS) -w $(GO_SRC)
168-
#$(GOLANGCI_LINT) run --fix
163+
# We make use of gofmt with golines because of: https://github.com/segmentio/golines/issues/155
164+
@$(GO_LINES) -w --base-formatter=gofmt --ignored-dirs=./e2e/chaos-mesh --ignore-generated $(GO_SRC)
165+
@$(GO_IMPORTS) -w $(GO_SRC)
166+
@$(GOLANGCI_LINT) run --fix
169167
@mkdir -p bin
170168
@touch $@
171169

172170
# Run go vet against code
173171
vet: bin/vet_check
174172

175173
bin/vet_check: ${GO_ALL}
176-
go vet ./...
174+
@go vet ./...
177175
@mkdir -p bin
178176
@touch $@
179177

@@ -203,22 +201,22 @@ rebuild-operator: container-build container-push-if-remote deploy bounce
203201
bounce:
204202
kubectl $(KUBECTL_ARGS) delete pod -l app=fdb-kubernetes-operator-controller-manager
205203

206-
samples: kustomize ${SAMPLES}
204+
samples: $(KUSTOMIZE) ${SAMPLES}
207205

208-
config/samples/deployment.yaml: config/deployment/*.yaml
209-
kustomize build ./config/deployment > $@
206+
config/samples/deployment.yaml: $(KUSTOMIZE) config/deployment/*.yaml
207+
$(KUSTOMIZE) build ./config/deployment > $@
210208

211-
config/samples/cluster.yaml: config/tests/base/*.yaml
212-
kustomize build ./config/tests/base/ > $@
209+
config/samples/cluster.yaml: $(KUSTOMIZE) config/tests/base/*.yaml
210+
$(KUSTOMIZE) build ./config/tests/base/ > $@
213211

214-
config/samples/backup.yaml: config/tests/backup/base/*.yaml
215-
kustomize build ./config/tests/backup/base > $@
212+
config/samples/backup.yaml: $(KUSTOMIZE) config/tests/backup/base/*.yaml
213+
$(KUSTOMIZE) build ./config/tests/backup/base > $@
216214

217-
config/samples/restore.yaml: config/tests/backup/base/*.yaml
218-
kustomize build ./config/tests/backup/restore > $@
215+
config/samples/restore.yaml: $(KUSTOMIZE) config/tests/backup/base/*.yaml
216+
$(KUSTOMIZE) build ./config/tests/backup/restore > $@
219217

220-
config/samples/client.yaml: config/tests/client/*.yaml
221-
kustomize build ./config/tests/client > $@
218+
config/samples/client.yaml: $(KUSTOMIZE) config/tests/client/*.yaml
219+
$(KUSTOMIZE) build ./config/tests/client > $@
222220

223221
bin/po-docgen: cmd/po-docgen/*.go
224222
go build -o bin/po-docgen cmd/po-docgen/main.go cmd/po-docgen/api.go

api/v1beta2/foundationdb_custom_parameter.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,31 @@ func (customParameters FoundationDBCustomParameters) ValidateCustomParameters()
8282
}
8383

8484
if _, ok := protectedParameters[parameterName]; ok {
85-
violations = append(violations, fmt.Sprintf("found protected customParameter: %s, please remove this parameter from the customParameters list", parameterName))
85+
violations = append(
86+
violations,
87+
fmt.Sprintf(
88+
"found protected customParameter: %s, please remove this parameter from the customParameters list",
89+
parameterName,
90+
),
91+
)
8692
}
8793

8894
if _, ok := fdbMonitorGeneralParameters[parameterName]; ok {
89-
violations = append(violations, fmt.Sprintf("found general or fdbmonitor customParameter: %s, please remove this parameter from the customParameters list as they are not supported", parameterName))
95+
violations = append(
96+
violations,
97+
fmt.Sprintf(
98+
"found general or fdbmonitor customParameter: %s, please remove this parameter from the customParameters list as they are not supported",
99+
parameterName,
100+
),
101+
)
90102
}
91103
}
92104

93105
if len(violations) > 0 {
94-
return fmt.Errorf("found the following customParameters violations:\n%s", strings.Join(violations, "\n"))
106+
return fmt.Errorf(
107+
"found the following customParameters violations:\n%s",
108+
strings.Join(violations, "\n"),
109+
)
95110
}
96111

97112
return nil

api/v1beta2/foundationdb_custom_parameter_test.go

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,32 +67,44 @@ var _ = Describe("FoundationDBCustomParameters", func() {
6767
"test=test",
6868
},
6969
nil),
70-
Entry("custom parameters that sets protected knob",
70+
Entry(
71+
"custom parameters that sets protected knob",
7172
FoundationDBCustomParameters{
7273
"datadir=test",
7374
},
74-
errors.New("found the following customParameters violations:\nfound protected customParameter: datadir, please remove this parameter from the customParameters list"),
75+
errors.New(
76+
"found the following customParameters violations:\nfound protected customParameter: datadir, please remove this parameter from the customParameters list",
77+
),
7578
),
76-
Entry("duplicate custom parameters",
79+
Entry(
80+
"duplicate custom parameters",
7781
FoundationDBCustomParameters{
7882
"test=test",
7983
"test=test",
8084
},
81-
errors.New("found the following customParameters violations:\nfound duplicated customParameter: test"),
85+
errors.New(
86+
"found the following customParameters violations:\nfound duplicated customParameter: test",
87+
),
8288
),
83-
Entry("duplicate custom parameters",
89+
Entry(
90+
"duplicate custom parameters",
8491
FoundationDBCustomParameters{
8592
"test=test",
8693
"datadir=test",
8794
"test=test",
8895
},
89-
errors.New("found the following customParameters violations:\nfound protected customParameter: datadir, please remove this parameter from the customParameters list\nfound duplicated customParameter: test"),
96+
errors.New(
97+
"found the following customParameters violations:\nfound protected customParameter: datadir, please remove this parameter from the customParameters list\nfound duplicated customParameter: test",
98+
),
9099
),
91-
Entry("custom parameters that sets general knob",
100+
Entry(
101+
"custom parameters that sets general knob",
92102
FoundationDBCustomParameters{
93103
"restart-delay",
94104
},
95-
errors.New("found the following customParameters violations:\nfound general or fdbmonitor customParameter: restart-delay, please remove this parameter from the customParameters list as they are not supported"),
105+
errors.New(
106+
"found the following customParameters violations:\nfound general or fdbmonitor customParameter: restart-delay, please remove this parameter from the customParameters list as they are not supported",
107+
),
96108
),
97109
)
98110
})

api/v1beta2/foundationdb_database_configuration.go

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,9 @@ func (configuration *DatabaseConfiguration) FailOver() DatabaseConfiguration {
188188
//
189189
// This will fill in defaults of -1 for some fields that have a default of 0,
190190
// and will ensure that the region configuration is ordered consistently.
191-
func (configuration DatabaseConfiguration) NormalizeConfiguration(cluster *FoundationDBCluster) DatabaseConfiguration {
191+
func (configuration DatabaseConfiguration) NormalizeConfiguration(
192+
cluster *FoundationDBCluster,
193+
) DatabaseConfiguration {
192194
result := configuration.DeepCopy()
193195

194196
if result.RemoteLogs == 0 {
@@ -273,7 +275,10 @@ func (configuration DatabaseConfiguration) getRegion(id string, priority int) Re
273275
}
274276

275277
if len(matchingRegion.DataCenters) == 0 {
276-
matchingRegion.DataCenters = append(matchingRegion.DataCenters, DataCenter{ID: id, Priority: priority})
278+
matchingRegion.DataCenters = append(
279+
matchingRegion.DataCenters,
280+
DataCenter{ID: id, Priority: priority},
281+
)
277282
}
278283

279284
return matchingRegion
@@ -298,7 +303,9 @@ func (configuration DatabaseConfiguration) getRegion(id string, priority int) Re
298303
// The default LogRouters value will be equal to 3 times the Logs value when
299304
// the UsableRegions is greater than 1. It will be equal to -1 when the
300305
// UsableRegions is less than or equal to 1.
301-
func (configuration *DatabaseConfiguration) GetRoleCountsWithDefaults(faultTolerance int) RoleCounts {
306+
func (configuration *DatabaseConfiguration) GetRoleCountsWithDefaults(
307+
faultTolerance int,
308+
) RoleCounts {
302309
counts := configuration.RoleCounts.DeepCopy()
303310
if counts.Storage == 0 {
304311
counts.Storage = 2*faultTolerance + 1
@@ -356,7 +363,9 @@ func (configuration *DatabaseConfiguration) GetRoleCountsWithDefaults(faultToler
356363
// converge on the final configuration.
357364
//
358365
// See: https://apple.github.io/foundationdb/configuration.html#migrating-a-database-to-use-a-region-configuration
359-
func (configuration DatabaseConfiguration) GetNextConfigurationChange(finalConfiguration DatabaseConfiguration) DatabaseConfiguration {
366+
func (configuration DatabaseConfiguration) GetNextConfigurationChange(
367+
finalConfiguration DatabaseConfiguration,
368+
) DatabaseConfiguration {
360369
if !reflect.DeepEqual(configuration.Regions, finalConfiguration.Regions) {
361370
result := configuration.DeepCopy()
362371
currentPriorities := configuration.getRegionPriorities()
@@ -368,7 +377,10 @@ func (configuration DatabaseConfiguration) GetNextConfigurationChange(finalConfi
368377
for regionIndex, region := range result.Regions {
369378
for _, dataCenter := range region.DataCenters {
370379
if dataCenter.Satellite == 0 {
371-
result.Regions[regionIndex] = finalConfiguration.getRegion(dataCenter.ID, dataCenter.Priority)
380+
result.Regions[regionIndex] = finalConfiguration.getRegion(
381+
dataCenter.ID,
382+
dataCenter.Priority,
383+
)
372384
break
373385
}
374386
}
@@ -397,7 +409,10 @@ func (configuration DatabaseConfiguration) GetNextConfigurationChange(finalConfi
397409
if len(result.Regions) == 0 {
398410
priority = 1
399411
}
400-
result.Regions = append(result.Regions, finalConfiguration.getRegion(regionToAdd, priority))
412+
result.Regions = append(
413+
result.Regions,
414+
finalConfiguration.getRegion(regionToAdd, priority),
415+
)
401416
currentPriorities[regionToAdd] = priority
402417
}
403418
}
@@ -653,9 +668,15 @@ func (configuration DatabaseConfiguration) AreSeparatedProxiesConfigured() bool
653668
// string "commit_proxies=%d grv_proxies=%d", otherwise just
654669
// "proxies=%d" using the correct counts of the configuration object.
655670
func (configuration DatabaseConfiguration) GetProxiesString() string {
656-
counts := configuration.GetRoleCountsWithDefaults(DesiredFaultTolerance(configuration.RedundancyMode))
671+
counts := configuration.GetRoleCountsWithDefaults(
672+
DesiredFaultTolerance(configuration.RedundancyMode),
673+
)
657674
if configuration.AreSeparatedProxiesConfigured() {
658-
return fmt.Sprintf(" commit_proxies=%d grv_proxies=%d", counts.CommitProxies, counts.GrvProxies)
675+
return fmt.Sprintf(
676+
" commit_proxies=%d grv_proxies=%d",
677+
counts.CommitProxies,
678+
counts.GrvProxies,
679+
)
659680
}
660681

661682
return fmt.Sprintf(" proxies=%d", counts.Proxies)
@@ -757,7 +778,9 @@ func (configuration DatabaseConfiguration) GetConfigurationString() (string, err
757778
//
758779
// Deprecated: Use ClearMissingVersionFlags instead on the live configuration
759780
// instead.
760-
func (configuration *DatabaseConfiguration) FillInDefaultVersionFlags(liveConfiguration DatabaseConfiguration) {
781+
func (configuration *DatabaseConfiguration) FillInDefaultVersionFlags(
782+
liveConfiguration DatabaseConfiguration,
783+
) {
761784
if configuration.LogSpill == 0 {
762785
configuration.LogSpill = liveConfiguration.LogSpill
763786
}

0 commit comments

Comments
 (0)