blob: 0ad7f5f7a876de168a7f92c1c293e7a78c46472b [file] [log] [blame]
Giorgi Lekveishvilie8b2f012023-11-30 19:05:03 +04001
2# Image URL to use all building/pushing image targets
3IMG ?= giolekva/dns-ns-controller:latest
4# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
5ENVTEST_K8S_VERSION = 1.24.2
6
7# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
8ifeq (,$(shell go env GOBIN))
9GOBIN=$(shell go env GOPATH)/bin
10else
11GOBIN=$(shell go env GOBIN)
12endif
13
14# Setting SHELL to bash allows bash commands to be executed by recipes.
15# Options are set to exit when a recipe line exits non-zero or a piped command fails.
16SHELL = /usr/bin/env bash -o pipefail
17.SHELLFLAGS = -ec
18
19.PHONY: all
20all: build
21
22##@ General
23
24# The help target prints out all targets with their descriptions organized
25# beneath their categories. The categories are represented by '##@' and the
26# target descriptions by '##'. The awk commands is responsible for reading the
27# entire set of makefiles included in this invocation, looking for lines of the
28# file as xyz: ## something, and then pretty-format the target and help. Then,
29# if there's a line with ##@ something, that gets pretty-printed as a category.
30# More info on the usage of ANSI control characters for terminal formatting:
31# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
32# More info on the awk command:
33# http://linuxcommand.org/lc3_adv_awk.php
34
35.PHONY: help
36help: ## Display this help.
37 @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)
38
39##@ Development
40
41.PHONY: manifests
42manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
43 $(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
44
45.PHONY: generate
46generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
47 $(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
48
49.PHONY: fmt
50fmt: ## Run go fmt against code.
51 go fmt ./...
52
53.PHONY: vet
54vet: ## Run go vet against code.
55 go vet ./...
56
57.PHONY: test
58test: manifests generate fmt vet envtest ## Run tests.
59 KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out
60
61##@ Build
62
63.PHONY: build
64build: generate fmt vet ## Build manager binary.
65 go build -o bin/manager main.go
66
67.PHONY: run
68run: manifests generate fmt vet ## Run a controller from your host.
69 go run ./main.go
70
71clean:
72 rm -rf manager_arm64 manager_amd64
73
74build_arm64: export CGO_ENABLED=0
75build_arm64: export GO111MODULE=on
76build_arm64: export GOOS=linux
77build_arm64: export GOARCH=arm64
78build_arm64:
79 go build -a -o manager_arm64 main.go
80
81build_amd64: export CGO_ENABLED=0
82build_amd64: export GO111MODULE=on
83build_amd64: export GOOS=linux
84build_amd64: export GOARCH=amd64
85build_amd64:
86 go build -a -o manager_amd64 main.go
87
88.PHONY: docker-build
89docker-build: clean build_arm64 build_amd64 ## Build docker image with the manager.
90 podman build --platform linux/arm64 --tag ${IMG}-arm64 .
91 podman build --platform linux/amd64 --tag ${IMG}-amd64 .
92
93.PHONY: docker-push
94docker-push: ## Push docker image with the manager.
95 podman push ${IMG}-arm64
96 podman push ${IMG}-amd64
97 podman manifest create ${IMG} ${IMG}-arm64 ${IMG}-amd64
98 podman manifest push ${IMG} docker://docker.io/${IMG}
99 podman manifest rm ${IMG}
100
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
155
156generate-helm-chart: manifests kustomize
157 $(KUSTOMIZE) build config/crd > ../../charts/dns-ns-controller/templates/crds.yaml
158 cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
159 $(KUSTOMIZE) build config/default | sed 's/: ns-controller-system/: {{ .Release.Namespace }}/g' > ../../charts/dns-ns-controller/templates/install.yaml