From bdf2fb003a58f0820ac23394c433c2f3b72b3e67 Mon Sep 17 00:00:00 2001 From: Tomy Guichard Date: Mon, 30 Jun 2025 11:22:27 +0200 Subject: [PATCH] Add nilaway linter --- Makefile | 8 ++++++++ internal/service/scaleway/client/errors.go | 6 +++++- internal/service/scaleway/lb/lb.go | 3 +++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 8dbdb7d..26b9c28 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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 @@ -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. @@ -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 diff --git a/internal/service/scaleway/client/errors.go b/internal/service/scaleway/client/errors.go index 3975e26..839f547 100644 --- a/internal/service/scaleway/client/errors.go +++ b/internal/service/scaleway/client/errors.go @@ -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. diff --git a/internal/service/scaleway/lb/lb.go b/internal/service/scaleway/lb/lb.go index 80dc409..4b985d9 100644 --- a/internal/service/scaleway/lb/lb.go +++ b/internal/service/scaleway/lb/lb.go @@ -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 {