blob: 67e56f29108883e5ac7e8090b3a98c156cfeda15 [file] [log] [blame]
gio2446de02025-04-11 11:20:39 +04001docker_flags=--provenance=false --sbom=false
Giorgi Lekveishvili7366dbb2023-06-16 12:31:03 +04002
3# Image URL to use all building/pushing image targets
Giorgi Lekveishvili44f9d592023-06-21 14:58:19 +04004IMG ?= giolekva/headscale-controller:latest
Giorgi Lekveishvili7366dbb2023-06-16 12:31:03 +04005# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
6ENVTEST_K8S_VERSION = 1.24.2
7
8# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
9ifeq (,$(shell go env GOBIN))
10GOBIN=$(shell go env GOPATH)/bin
11else
12GOBIN=$(shell go env GOBIN)
13endif
14
15# Setting SHELL to bash allows bash commands to be executed by recipes.
16# Options are set to exit when a recipe line exits non-zero or a piped command fails.
17SHELL = /usr/bin/env bash -o pipefail
18.SHELLFLAGS = -ec
19
20.PHONY: all
21all: build
22
23##@ General
24
25# The help target prints out all targets with their descriptions organized
26# beneath their categories. The categories are represented by '##@' and the
27# target descriptions by '##'. The awk commands is responsible for reading the
28# entire set of makefiles included in this invocation, looking for lines of the
29# file as xyz: ## something, and then pretty-format the target and help. Then,
30# if there's a line with ##@ something, that gets pretty-printed as a category.
31# More info on the usage of ANSI control characters for terminal formatting:
32# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
33# More info on the awk command:
34# http://linuxcommand.org/lc3_adv_awk.php
35
36.PHONY: help
37help: ## Display this help.
38 @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)
39
40##@ Development
41
42.PHONY: manifests
43manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
44 $(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
45
46.PHONY: generate
47generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
48 $(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
49
50.PHONY: fmt
51fmt: ## Run go fmt against code.
52 go fmt ./...
53
54.PHONY: vet
55vet: ## Run go vet against code.
56 go vet ./...
57
58.PHONY: test
59test: manifests generate fmt vet envtest ## Run tests.
60 KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out
61
62##@ Build
63
64.PHONY: build
65build: generate fmt vet ## Build manager binary.
66 go build -o bin/manager main.go
67
68.PHONY: run
69run: manifests generate fmt vet ## Run a controller from your host.
70 go run ./main.go --headscale-api=localhost:8081
71
Giorgi Lekveishvili2d843c32023-07-20 10:10:24 +040072clean:
73 rm -rf manager_arm64 manager_amd64
74
75build_arm64: export CGO_ENABLED=0
76build_arm64: export GO111MODULE=on
77build_arm64: export GOOS=linux
78build_arm64: export GOARCH=arm64
79build_arm64:
80 go build -a -o manager_arm64 main.go
81
82build_amd64: export CGO_ENABLED=0
83build_amd64: export GO111MODULE=on
84build_amd64: export GOOS=linux
85build_amd64: export GOARCH=amd64
86build_amd64:
87 go build -a -o manager_amd64 main.go
88
Giorgi Lekveishvili7366dbb2023-06-16 12:31:03 +040089.PHONY: docker-build
Giorgi Lekveishvili2d843c32023-07-20 10:10:24 +040090docker-build: test clean build_arm64 build_amd64 ## Build docker image with the manager.
gio2446de02025-04-11 11:20:39 +040091 docker build --platform linux/arm64 --tag ${IMG}-arm64 $(docker_flags) .
92 docker build --platform linux/amd64 --tag ${IMG}-amd64 $(docker_flags) .
Giorgi Lekveishvili7366dbb2023-06-16 12:31:03 +040093
94.PHONY: docker-push
gio2446de02025-04-11 11:20:39 +040095docker-push: docker-build
96 docker push ${IMG}-arm64
97 docker push ${IMG}-amd64
98 docker manifest create ${IMG} ${IMG}-arm64 ${IMG}-amd64
99 docker manifest push --purge ${IMG}
Giorgi Lekveishvili7366dbb2023-06-16 12:31:03 +0400100
101##@ Deployment
102
103ifndef ignore-not-found
104 ignore-not-found = false
105endif
106
107.PHONY: install
108install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
109 $(KUSTOMIZE) build config/crd | kubectl apply -f -
110
111.PHONY: uninstall
112uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
113 $(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
114
115.PHONY: deploy
116deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
117 cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
118 $(KUSTOMIZE) build config/default | kubectl apply -f -
119
120.PHONY: undeploy
121undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
122 $(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
123
124##@ Build Dependencies
125
126## Location to install dependencies to
127LOCALBIN ?= $(shell pwd)/bin
128$(LOCALBIN):
129 mkdir -p $(LOCALBIN)
130
131## Tool Binaries
132KUSTOMIZE ?= $(LOCALBIN)/kustomize
133CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
134ENVTEST ?= $(LOCALBIN)/setup-envtest
135
136## Tool Versions
137KUSTOMIZE_VERSION ?= v3.8.7
138CONTROLLER_TOOLS_VERSION ?= v0.9.2
139
140KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
141.PHONY: kustomize
142kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
143$(KUSTOMIZE): $(LOCALBIN)
144 test -s $(LOCALBIN)/kustomize || { curl -s $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN); }
145
146.PHONY: controller-gen
147controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
148$(CONTROLLER_GEN): $(LOCALBIN)
149 test -s $(LOCALBIN)/controller-gen || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
150
151.PHONY: envtest
152envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
153$(ENVTEST): $(LOCALBIN)
154 test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
Giorgi Lekveishvili44f9d592023-06-21 14:58:19 +0400155
156generate-helm-chart: manifests kustomize
157 cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
158 $(KUSTOMIZE) build config/default | sed 's/: controller-system/: {{ .Release.Namespace }}/g' > ../../../charts/headscale-controller/templates/install.yaml