2 # Image URL to use all building/pushing image targets
\r
3 IMG ?= controller:latest
\r
4 # ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
\r
5 ENVTEST_K8S_VERSION = 1.27.1
\r
7 # Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
\r
8 ifeq (,$(shell go env GOBIN))
\r
9 GOBIN=$(shell go env GOPATH)/bin
\r
11 GOBIN=$(shell go env GOBIN)
\r
14 # CONTAINER_TOOL defines the container tool to be used for building images.
\r
15 # Be aware that the target commands are only tested with Docker which is
\r
16 # scaffolded by default. However, you might want to replace it to use other
\r
17 # tools. (i.e. podman)
\r
18 CONTAINER_TOOL ?= docker
\r
20 # Setting SHELL to bash allows bash commands to be executed by recipes.
\r
21 # Options are set to exit when a recipe line exits non-zero or a piped command fails.
\r
22 SHELL = /usr/bin/env bash -o pipefail
\r
30 # The help target prints out all targets with their descriptions organized
\r
31 # beneath their categories. The categories are represented by '##@' and the
\r
32 # target descriptions by '##'. The awk commands is responsible for reading the
\r
33 # entire set of makefiles included in this invocation, looking for lines of the
\r
34 # file as xyz: ## something, and then pretty-format the target and help. Then,
\r
35 # if there's a line with ##@ something, that gets pretty-printed as a category.
\r
36 # More info on the usage of ANSI control characters for terminal formatting:
\r
37 # https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
\r
38 # More info on the awk command:
\r
39 # http://linuxcommand.org/lc3_adv_awk.php
\r
42 help: ## Display this help.
\r
43 @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)
\r
48 manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
\r
49 $(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
\r
52 generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
\r
53 $(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
\r
56 fmt: ## Run go fmt against code.
\r
60 vet: ## Run go vet against code.
\r
64 test: manifests generate fmt vet envtest ## Run tests.
\r
65 KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out
\r
70 build: manifests generate fmt vet ## Build manager binary.
\r
71 go build -o bin/manager cmd/main.go
\r
74 run: manifests generate fmt vet ## Run a controller from your host.
\r
75 go run ./cmd/main.go
\r
77 # If you wish built the manager image targeting other platforms you can use the --platform flag.
\r
78 # (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it.
\r
79 # More info: https://docs.docker.com/develop/develop-images/build_enhancements/
\r
80 .PHONY: docker-build
\r
81 docker-build: test ## Build docker image with the manager.
\r
82 $(CONTAINER_TOOL) build -t ${IMG} .
\r
85 docker-push: ## Push docker image with the manager.
\r
86 $(CONTAINER_TOOL) push ${IMG}
\r
88 # PLATFORMS defines the target platforms for the manager image be build to provide support to multiple
\r
89 # architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
\r
90 # - able to use docker buildx . More info: https://docs.docker.com/build/buildx/
\r
91 # - have enable BuildKit, More info: https://docs.docker.com/develop/develop-images/build_enhancements/
\r
92 # - be able to push the image for your registry (i.e. if you do not inform a valid value via IMG=<myregistry/image:<tag>> then the export will fail)
\r
93 # To properly provided solutions that supports more than one platform you should use this option.
\r
94 PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
\r
95 .PHONY: docker-buildx
\r
96 docker-buildx: test ## Build and push docker image for the manager for cross-platform support
\r
97 # copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
\r
98 sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
\r
99 - $(CONTAINER_TOOL) buildx create --name project-v3-builder
\r
100 $(CONTAINER_TOOL) buildx use project-v3-builder
\r
101 - $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
\r
102 - $(CONTAINER_TOOL) buildx rm project-v3-builder
\r
103 rm Dockerfile.cross
\r
107 ifndef ignore-not-found
\r
108 ignore-not-found = false
\r
112 install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
\r
113 $(KUSTOMIZE) build config/crd | $(KUBECTL) apply -f -
\r
116 uninstall: 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.
\r
117 $(KUSTOMIZE) build config/crd | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
\r
120 deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
\r
121 cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
\r
122 $(KUSTOMIZE) build config/default | $(KUBECTL) apply -f -
\r
125 undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
\r
126 $(KUSTOMIZE) build config/default | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
\r
128 ##@ Build Dependencies
\r
130 ## Location to install dependencies to
\r
131 LOCALBIN ?= $(shell pwd)/bin
\r
133 mkdir -p $(LOCALBIN)
\r
137 KUSTOMIZE ?= $(LOCALBIN)/kustomize
\r
138 CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
\r
139 ENVTEST ?= $(LOCALBIN)/setup-envtest
\r
142 KUSTOMIZE_VERSION ?= v5.0.1
\r
143 CONTROLLER_TOOLS_VERSION ?= v0.12.0
\r
146 kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading.
\r
147 $(KUSTOMIZE): $(LOCALBIN)
\r
148 @if test -x $(LOCALBIN)/kustomize && ! $(LOCALBIN)/kustomize version | grep -q $(KUSTOMIZE_VERSION); then \
\r
149 echo "$(LOCALBIN)/kustomize version is not expected $(KUSTOMIZE_VERSION). Removing it before installing."; \
\r
150 rm -rf $(LOCALBIN)/kustomize; \
\r
152 test -s $(LOCALBIN)/kustomize || GOBIN=$(LOCALBIN) GO111MODULE=on go install sigs.k8s.io/kustomize/kustomize/v5@$(KUSTOMIZE_VERSION)
\r
154 .PHONY: controller-gen
\r
155 controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten.
\r
156 $(CONTROLLER_GEN): $(LOCALBIN)
\r
157 test -s $(LOCALBIN)/controller-gen && $(LOCALBIN)/controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION) || \
\r
158 GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
\r
161 envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
\r
162 $(ENVTEST): $(LOCALBIN)
\r
163 test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
\r