Skip to content

Commit bdf2fb0

Browse files
committed
Add nilaway linter
1 parent 3e09b01 commit bdf2fb0

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ cleanup-test-e2e: ## Tear down the Kind cluster used for e2e tests
8787
.PHONY: lint
8888
lint: golangci-lint ## Run golangci-lint linter
8989
$(GOLANGCI_LINT) run
90+
$(NILAWAY) -include-pkgs=github.com/scaleway/cluster-api-provider-scaleway ./...
9091

9192
.PHONY: lint-fix
9293
lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
@@ -189,6 +190,7 @@ KUSTOMIZE ?= $(LOCALBIN)/kustomize
189190
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
190191
ENVTEST ?= $(LOCALBIN)/setup-envtest
191192
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
193+
NILAWAY = $(LOCALBIN)/nilaway
192194

193195
## Tool Versions
194196
KUSTOMIZE_VERSION ?= v5.6.0
@@ -198,6 +200,7 @@ ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller
198200
#ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31)
199201
ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}')
200202
GOLANGCI_LINT_VERSION ?= v2.1.0
203+
NILAWAY_VERSION ?= latest
201204

202205
.PHONY: kustomize
203206
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
@@ -227,6 +230,11 @@ golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
227230
$(GOLANGCI_LINT): $(LOCALBIN)
228231
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
229232

233+
.PHONY: nilaway
234+
nilaway: $(NILAWAY) ## Download nilaway locally if necessary.
235+
$(NILAWAY): $(LOCALBIN)
236+
$(call go-install-tool,$(NILAWAY),go.uber.org/nilaway/cmd/nilaway,$(NILAWAY_VERSION))
237+
230238
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
231239
# $1 - target path with name of binary
232240
# $2 - package url which can be installed

internal/service/scaleway/client/errors.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ var (
1818
// IsForbiddenError returns true if err is an HTTP 403 error.
1919
func IsForbiddenError(err error) bool {
2020
var respError *scw.ResponseError
21-
return errors.As(err, &respError) && respError.StatusCode == http.StatusForbidden
21+
if !errors.As(err, &respError) {
22+
return false
23+
}
24+
25+
return respError.StatusCode == http.StatusForbidden
2226
}
2327

2428
// IsNotFoundError returns true if err is an HTTP 404 error or ErrNoItemFound.

internal/service/scaleway/lb/lb.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,9 @@ func (s *Service) ensureACLs(
502502
}
503503

504504
mainLBFrontend := frontendByLB[mainLB.ID]
505+
if mainLBFrontend == nil {
506+
panic("did not expect mainLBFrontend to be nil")
507+
}
505508

506509
// Set the Allowed Ranges ACL.
507510
if err := s.ensureACL(ctx, mainLBFrontend, allowedRangesACLName, allowedRanges, false, aclIndex); err != nil {

0 commit comments

Comments
 (0)