blob: 5b9dda49c51a38ccee980e20175a0bf68fe2daed [file] [log] [blame]
Giorgi Lekveishvilib591eae2023-06-16 12:31:49 +04001
2# Image URL to use all building/pushing image targets
Giorgi Lekveishvili71761892023-06-21 15:03:14 +04003IMG ?= giolekva/resource-renderer-controller:latest
Giorgi Lekveishvilib591eae2023-06-16 12:31:49 +04004# 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
Giorgi Lekveishvili2d843c32023-07-20 10:10:24 +040071clean:
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
Giorgi Lekveishvilib591eae2023-06-16 12:31:49 +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.
91 podman build --platform linux/arm64 --tag ${IMG}-arm64 .
92 podman build --platform linux/amd64 --tag ${IMG}-amd64 .
Giorgi Lekveishvilib591eae2023-06-16 12:31:49 +040093
94.PHONY: docker-push
95docker-push: ## Push docker image with the manager.
Giorgi Lekveishvili2d843c32023-07-20 10:10:24 +040096 podman push ${IMG}-arm64
97 podman push ${IMG}-amd64
98 podman manifest create ${IMG} ${IMG}-arm64 ${IMG}-amd64
99 podman manifest push ${IMG} docker://docker.io/${IMG}
100 podman manifest rm ${IMG}
Giorgi Lekveishvilib591eae2023-06-16 12:31:49 +0400101
102##@ Deployment
103
104ifndef ignore-not-found
105 ignore-not-found = false
106endif
107
108.PHONY: install
109install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
Giorgi Lekveishvili71761892023-06-21 15:03:14 +0400110 $(KUSTOMIZE) build config/crd # | kubectl apply -f -
Giorgi Lekveishvilib591eae2023-06-16 12:31:49 +0400111
112.PHONY: uninstall
113uninstall: 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.
114 $(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
115
116.PHONY: deploy
117deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
118 cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
Giorgi Lekveishvili71761892023-06-21 15:03:14 +0400119 $(KUSTOMIZE) build config/default # | kubectl apply -f -
Giorgi Lekveishvilib591eae2023-06-16 12:31:49 +0400120
121.PHONY: undeploy
122undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
123 $(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
124
125##@ Build Dependencies
126
127## Location to install dependencies to
128LOCALBIN ?= $(shell pwd)/bin
129$(LOCALBIN):
130 mkdir -p $(LOCALBIN)
131
132## Tool Binaries
133KUSTOMIZE ?= $(LOCALBIN)/kustomize
134CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
135ENVTEST ?= $(LOCALBIN)/setup-envtest
136
137## Tool Versions
138KUSTOMIZE_VERSION ?= v3.8.7
139CONTROLLER_TOOLS_VERSION ?= v0.9.2
140
141KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
142.PHONY: kustomize
143kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
144$(KUSTOMIZE): $(LOCALBIN)
145 test -s $(LOCALBIN)/kustomize || { curl -s $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN); }
146
147.PHONY: controller-gen
148controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
149$(CONTROLLER_GEN): $(LOCALBIN)
150 test -s $(LOCALBIN)/controller-gen || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
151
152.PHONY: envtest
153envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
154$(ENVTEST): $(LOCALBIN)
155 test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
Giorgi Lekveishvili71761892023-06-21 15:03:14 +0400156
157generate-helm-chart: manifests kustomize
158 $(KUSTOMIZE) build config/crd > ../../charts/resource-renderer-controller/templates/crds.yaml
159 cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
160 $(KUSTOMIZE) build config/default | sed 's/: resource-renderer-system/: {{ .Release.Namespace }}/g' > ../../charts/resource-renderer-controller/templates/install.yaml