Skip to content

Add nilaway linter #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ cleanup-test-e2e: ## Tear down the Kind cluster used for e2e tests
.PHONY: lint
lint: golangci-lint ## Run golangci-lint linter
$(GOLANGCI_LINT) run
$(NILAWAY) -include-pkgs=github.com/scaleway/cluster-api-provider-scaleway ./...

.PHONY: lint-fix
lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
Expand Down Expand Up @@ -189,6 +190,7 @@ KUSTOMIZE ?= $(LOCALBIN)/kustomize
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
ENVTEST ?= $(LOCALBIN)/setup-envtest
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
NILAWAY = $(LOCALBIN)/nilaway

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

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

.PHONY: nilaway
nilaway: $(NILAWAY) ## Download nilaway locally if necessary.
$(NILAWAY): $(LOCALBIN)
$(call go-install-tool,$(NILAWAY),go.uber.org/nilaway/cmd/nilaway,$(NILAWAY_VERSION))

# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
# $1 - target path with name of binary
# $2 - package url which can be installed
Expand Down
6 changes: 5 additions & 1 deletion internal/service/scaleway/client/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ var (
// IsForbiddenError returns true if err is an HTTP 403 error.
func IsForbiddenError(err error) bool {
var respError *scw.ResponseError
return errors.As(err, &respError) && respError.StatusCode == http.StatusForbidden
if !errors.As(err, &respError) {
return false
}

return respError.StatusCode == http.StatusForbidden
}

// IsNotFoundError returns true if err is an HTTP 404 error or ErrNoItemFound.
Expand Down
3 changes: 3 additions & 0 deletions internal/service/scaleway/lb/lb.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,9 @@ func (s *Service) ensureACLs(
}

mainLBFrontend := frontendByLB[mainLB.ID]
if mainLBFrontend == nil {
panic("did not expect mainLBFrontend to be nil")
}

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