Skip to content

Commit

Permalink
fix static checks
Browse files Browse the repository at this point in the history
  • Loading branch information
maciaszczykm committed Sep 21, 2023
1 parent c68b20b commit fe72157
Show file tree
Hide file tree
Showing 26 changed files with 1,455 additions and 131 deletions.
41 changes: 24 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
MODULES_DIRECTORY := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
ROOT_DIRECTORY := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
API_DIRECTORY = $(MODULES_DIRECTORY)/api
COMMON_DIRECTORY = $(MODULES_DIRECTORY)/common
OPERATOR_DIRECTORY = $(MODULES_DIRECTORY)/operator
PROVIDER_DIRECTORY = $(MODULES_DIRECTORY)/providers
ARGOCD_PROVIDER_DIRECTORY = $(PROVIDER_DIRECTORY)/argocd
FAKE_PROVIDER_DIRECTORY = $(PROVIDER_DIRECTORY)/fake
PROVISIONER_DIRECTORY = $(MODULES_DIRECTORY)/provisioner
TOOLS_DIRECTORY = $(MODULES_DIRECTORY)/tools
MODULES := $(API_DIRECTORY) $(COMMON_DIRECTORY) $(OPERATOR_DIRECTORY) $(ARGOCD_PROVIDER_DIRECTORY) $(FAKE_PROVIDER_DIRECTORY) $(PROVISIONER_DIRECTORY)

MAKEFLAGS += -j2

# List of targets that should be executed before other targets
PRE = --ensure-tools

.PHONY: --ensure-tools
--ensure-tools:
@$(MAKE) --no-print-directory -C $(TOOLS_DIRECTORY) ensure

.PHONY: --run $(MODULES)
--run: $(MODULES)

Expand All @@ -24,25 +32,24 @@ help: ## show help

##@ Build

# TODO: build target is not defined for all modules at the moment.
.PHONY: build
build: ## build all modules
@$(MAKE) --no-print-directory -C $(MODULES_DIRECTORY) TARGET=build
build: build-api ## build all modules

##@ Code quality
.PHONY: build-api
build-api: ## build API module
@$(MAKE) -C $(API_DIRECTORY) build

.PHONY: check
check: fmt vet lint ## run all code quality checks
##@ Tests and checks

.PHONY: fmt
fmt: ## format code
@$(MAKE) --no-print-directory -C $(MODULES_DIRECTORY) TARGET=fmt
# TODO: test target is not defined for all modules at the moment.
.PHONY: test
test: ## test all modules
@$(MAKE) --no-print-directory -C $(MODULES_DIRECTORY) TARGET=test

.PHONY: vet
vet: ## examine code to find potential errors and suspicious constructs
@$(MAKE) --no-print-directory -C $(MODULES_DIRECTORY) TARGET=vet

# TODO: It doesn't seem to work when running with make. Should we remove vet since it already includes it?
.PHONY: lint
lint: ## lint code
docker run -t --rm -v $$(pwd):/app -v ~/.cache/golangci-lint/v1.54.2:/root/.cache -w /app golangci/golangci-lint:v1.54.2 golangci-lint run -v --fix
lint: $(PRE) ## lint all code
go work edit -json | jq -r '.Use[].DiskPath' | xargs -I{} golangci-lint run {}/...

.PHONY: fix
fix: $(PRE) ## fix all code
go work edit -json | jq -r '.Use[].DiskPath' | xargs -I{} golangci-lint run --fix {}/...
19 changes: 11 additions & 8 deletions api/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
CRD_OPTIONS ?= "crd"

ifeq (,$(shell go env GOBIN))
Expand All @@ -8,31 +9,33 @@ endif

##@ General

.PHONY: help
help: ## show help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

##@ Build

CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
.PHONY: help
get-controller-gen: ## install controller-gen
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected])

.PHONY: manifests
manifests: get-controller-gen ## generate manifests
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases

.PHONY: generate
generate: get-controller-gen ## generate code
go generate ./pkg/...
$(CONTROLLER_GEN) object:headerFile="../boilerplate.go.txt" paths="./..."

build: manifests generate ## generate manifests and code

##@ Code quality
.PHONY: build
build: manifests generate ## build module

fmt: ## format code
go fmt ./...
##@ Tests

vet: ## examine code to find potential errors and suspicious constructs
go vet ./...
.PHONY: test
test: ## test module
go test ./...

# go-get-tool will 'go get' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
Expand Down
1 change: 1 addition & 0 deletions api/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ require (
github.com/stretchr/testify v1.8.4 // indirect
golang.org/x/net v0.15.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/tools v0.12.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
k8s.io/api v0.28.1 // indirect
Expand Down
3 changes: 1 addition & 2 deletions api/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.9.3 h1:Gn1I8+64MsuTb/HpH+LmQtNas23LhUVr3rYZ0eKuaMM=
golang.org/x/tools v0.9.3/go.mod h1:owI94Op576fPu3cIGQeHs3joujW/2Oc6MtlxbF5dfNc=
golang.org/x/tools v0.12.0 h1:YW6HUoUmYBpwSgyaGaZq1fHjrBjX1rlpZ54T6mu2kss=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
6 changes: 5 additions & 1 deletion common/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
help: ## show help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

##@ Code quality
##@ Build

build: ## build module

##@ Tests and static checks

fmt: ## format code
go fmt ./...
Expand Down
1 change: 1 addition & 0 deletions common/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ require (
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/net v0.15.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/tools v0.12.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
2 changes: 1 addition & 1 deletion common/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.9.3 h1:Gn1I8+64MsuTb/HpH+LmQtNas23LhUVr3rYZ0eKuaMM=
golang.org/x/tools v0.12.0 h1:YW6HUoUmYBpwSgyaGaZq1fHjrBjX1rlpZ54T6mu2kss=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
2 changes: 1 addition & 1 deletion common/log/zap.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func init() {
}

var (
Logger *zap.SugaredLogger
Logger *zap.SugaredLogger
DefaultOptions Options
)

Expand Down
5 changes: 3 additions & 2 deletions go.work
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ go 1.21

use (
./api
./providers/argocd
./common
./operator
./provisioner
./providers/argocd
./providers/fake
./provisioner
./tools
)
Loading

0 comments on commit fe72157

Please sign in to comment.