Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
130 lines (100 loc) · 4.26 KB
/
Copy pathMakefile
File metadata and controls
130 lines (100 loc) · 4.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# Copyright 2026 Matheus Pimenta.
# SPDX-License-Identifier: AGPL-3.0
ENVTEST_K8S_VERSION = 1.35.0
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec
# Allows for defining additional Go test args, e.g. '-tags integration'.
GO_TEST_ARGS ?=
# Docker image name for local builds.
IMG ?= cloudflare-gateway-controller:dev
.PHONY: all
all: tidy manifests lint test build ## Run basic validation targets.
##@ Development
.PHONY: manifests
manifests: controller-gen ## Generate RBAC and CRD manifests and wire them into the Helm chart.
$(CONTROLLER_GEN) rbac:roleName=manager-role crd object paths="./..." output:rbac:artifacts:config=config/rbac output:crd:artifacts:config=config/crd/bases
./hack/gen-chart-rbac.sh
./hack/gen-chart-crd.sh
.PHONY: fmt
fmt: ## Run go fmt against code.
go fmt ./...
.PHONY: vet
vet: ## Run go vet against code.
go vet ./...
.PHONY: tidy
tidy: fmt ## Run go mod tidy and go fmt.
go mod tidy
.PHONY: test
test: envtest ## Run all unit tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" \
go test $(shell go list ./... | grep -v '/cmd/') $(GO_TEST_ARGS) -coverprofile cover.out
.PHONY: lint
lint: vet golangci-lint ## Run go vet, golangci and helm linters.
$(GOLANGCI_LINT) run
helm lint charts/cloudflare-gateway-controller
.PHONY: lint-fix
lint-fix: golangci-lint ## Run golangci linters and perform fixes.
$(GOLANGCI_LINT) run --fix
##@ Build
.PHONY: build
build: ## Build the binary.
CGO_ENABLED=0 go build -o ./bin/cfgwctl ./cmd/cfgwctl
.PHONY: docker-build
docker-build: ## Build the controller Docker image locally.
docker buildx build -t $(IMG) --load .
.PHONY: test-e2e
test-e2e: build ## Run e2e tests against a kind cluster.
hack/e2e-test.sh 2>&1 | stdbuf -oL tee test-e2e.log
.PHONY: run
run: ## Run the controller locally against the current kubeconfig cluster.
go run ./cmd/cfgwctl controller --cluster-name=dev --enable-leader-election=false 2>&1 | stdbuf -oL tee run.log
.PHONY: run-debug
run-debug: ## Run the controller locally with debug logging (verbosity level 1).
go run ./cmd/cfgwctl controller --cluster-name=dev--enable-leader-election=false --log-level=debug 2>&1 | stdbuf -oL tee run.log
##@ Dependencies
## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
## Tool Binaries
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen-$(CONTROLLER_GEN_VERSION)
ENVTEST ?= $(LOCALBIN)/setup-envtest-$(ENVTEST_VERSION)
GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint-$(GOLANGCI_LINT_VERSION)
## Tool Versions
CONTROLLER_GEN_VERSION ?= v0.21.0
ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-%d.%d", $$2, $$3}')
GOLANGCI_LINT_VERSION ?= v2.9.0
.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
$(CONTROLLER_GEN): $(LOCALBIN)
$(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen,$(CONTROLLER_GEN_VERSION))
.PHONY: envtest
envtest: $(ENVTEST) ## Download setup-envtest locally if necessary.
$(ENVTEST): $(LOCALBIN)
$(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest,$(ENVTEST_VERSION))
.PHONY: golangci-lint
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))
# 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 (ideally with version)
# $2 - package url which can be installed
# $3 - specific version of package
define go-install-tool
@[ -f $(1) ] || { \
set -e; \
package=$(2)@$(3) ;\
echo "Downloading $${package}" ;\
GOBIN=$(LOCALBIN) go install $${package} ;\
mv "$$(echo "$(1)" | sed "s/-$(3)$$//")" $(1) ;\
}
endef
##@ General
.PHONY: help
help: ## Display this 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)