Adding Makefile 21/12121/2
authornaman.gupta <naman.gupta@samsung.com>
Mon, 27 Nov 2023 04:51:28 +0000 (10:21 +0530)
committerThoralf Czichy <thoralf.czichy@nokia.com>
Thu, 7 Dec 2023 09:17:54 +0000 (09:17 +0000)
Adding Makefile.

Change-Id: Id725f4af67934bea301580dec4e5232a8ddb55c5
Signed-off-by: naman.gupta <naman.gupta@samsung.com>
depRicKubernetesOperator/Makefile

index e69de29..75ac164 100644 (file)
@@ -0,0 +1,163 @@
+\r
+# Image URL to use all building/pushing image targets\r
+IMG ?= controller:latest\r
+# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.\r
+ENVTEST_K8S_VERSION = 1.27.1\r
+\r
+# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)\r
+ifeq (,$(shell go env GOBIN))\r
+GOBIN=$(shell go env GOPATH)/bin\r
+else\r
+GOBIN=$(shell go env GOBIN)\r
+endif\r
+\r
+# CONTAINER_TOOL defines the container tool to be used for building images.\r
+# Be aware that the target commands are only tested with Docker which is\r
+# scaffolded by default. However, you might want to replace it to use other\r
+# tools. (i.e. podman)\r
+CONTAINER_TOOL ?= docker\r
+\r
+# Setting SHELL to bash allows bash commands to be executed by recipes.\r
+# Options are set to exit when a recipe line exits non-zero or a piped command fails.\r
+SHELL = /usr/bin/env bash -o pipefail\r
+.SHELLFLAGS = -ec\r
+\r
+.PHONY: all\r
+all: build\r
+\r
+##@ General\r
+\r
+# The help target prints out all targets with their descriptions organized\r
+# beneath their categories. The categories are represented by '##@' and the\r
+# target descriptions by '##'. The awk commands is responsible for reading the\r
+# entire set of makefiles included in this invocation, looking for lines of the\r
+# file as xyz: ## something, and then pretty-format the target and help. Then,\r
+# if there's a line with ##@ something, that gets pretty-printed as a category.\r
+# More info on the usage of ANSI control characters for terminal formatting:\r
+# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters\r
+# More info on the awk command:\r
+# http://linuxcommand.org/lc3_adv_awk.php\r
+\r
+.PHONY: help\r
+help: ## Display this help.\r
+       @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
+\r
+##@ Development\r
+\r
+.PHONY: manifests\r
+manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.\r
+       $(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases\r
+\r
+.PHONY: generate\r
+generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.\r
+       $(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."\r
+\r
+.PHONY: fmt\r
+fmt: ## Run go fmt against code.\r
+       go fmt ./...\r
+\r
+.PHONY: vet\r
+vet: ## Run go vet against code.\r
+       go vet ./...\r
+\r
+.PHONY: test\r
+test: manifests generate fmt vet envtest ## Run tests.\r
+       KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out\r
+\r
+##@ Build\r
+\r
+.PHONY: build\r
+build: manifests generate fmt vet ## Build manager binary.\r
+       go build -o bin/manager cmd/main.go\r
+\r
+.PHONY: run\r
+run: manifests generate fmt vet ## Run a controller from your host.\r
+       go run ./cmd/main.go\r
+\r
+# If you wish built the manager image targeting other platforms you can use the --platform flag.\r
+# (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it.\r
+# More info: https://docs.docker.com/develop/develop-images/build_enhancements/\r
+.PHONY: docker-build\r
+docker-build: test ## Build docker image with the manager.\r
+       $(CONTAINER_TOOL) build -t ${IMG} .\r
+\r
+.PHONY: docker-push\r
+docker-push: ## Push docker image with the manager.\r
+       $(CONTAINER_TOOL) push ${IMG}\r
+\r
+# PLATFORMS defines the target platforms for  the manager image be build to provide support to multiple\r
+# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:\r
+# - able to use docker buildx . More info: https://docs.docker.com/build/buildx/\r
+# - have enable BuildKit, More info: https://docs.docker.com/develop/develop-images/build_enhancements/\r
+# - 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
+# To properly provided solutions that supports more than one platform you should use this option.\r
+PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le\r
+.PHONY: docker-buildx\r
+docker-buildx: test ## Build and push docker image for the manager for cross-platform support\r
+       # copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile\r
+       sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross\r
+       - $(CONTAINER_TOOL) buildx create --name project-v3-builder\r
+       $(CONTAINER_TOOL) buildx use project-v3-builder\r
+       - $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .\r
+       - $(CONTAINER_TOOL) buildx rm project-v3-builder\r
+       rm Dockerfile.cross\r
+\r
+##@ Deployment\r
+\r
+ifndef ignore-not-found\r
+  ignore-not-found = false\r
+endif\r
+\r
+.PHONY: install\r
+install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.\r
+       $(KUSTOMIZE) build config/crd | $(KUBECTL) apply -f -\r
+\r
+.PHONY: uninstall\r
+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
+       $(KUSTOMIZE) build config/crd | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -\r
+\r
+.PHONY: deploy\r
+deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.\r
+       cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}\r
+       $(KUSTOMIZE) build config/default | $(KUBECTL) apply -f -\r
+\r
+.PHONY: undeploy\r
+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
+       $(KUSTOMIZE) build config/default | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -\r
+\r
+##@ Build Dependencies\r
+\r
+## Location to install dependencies to\r
+LOCALBIN ?= $(shell pwd)/bin\r
+$(LOCALBIN):\r
+       mkdir -p $(LOCALBIN)\r
+\r
+## Tool Binaries\r
+KUBECTL ?= kubectl\r
+KUSTOMIZE ?= $(LOCALBIN)/kustomize\r
+CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen\r
+ENVTEST ?= $(LOCALBIN)/setup-envtest\r
+\r
+## Tool Versions\r
+KUSTOMIZE_VERSION ?= v5.0.1\r
+CONTROLLER_TOOLS_VERSION ?= v0.12.0\r
+\r
+.PHONY: kustomize\r
+kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading.\r
+$(KUSTOMIZE): $(LOCALBIN)\r
+       @if test -x $(LOCALBIN)/kustomize && ! $(LOCALBIN)/kustomize version | grep -q $(KUSTOMIZE_VERSION); then \\r
+               echo "$(LOCALBIN)/kustomize version is not expected $(KUSTOMIZE_VERSION). Removing it before installing."; \\r
+               rm -rf $(LOCALBIN)/kustomize; \\r
+       fi\r
+       test -s $(LOCALBIN)/kustomize || GOBIN=$(LOCALBIN) GO111MODULE=on go install sigs.k8s.io/kustomize/kustomize/v5@$(KUSTOMIZE_VERSION)\r
+\r
+.PHONY: controller-gen\r
+controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten.\r
+$(CONTROLLER_GEN): $(LOCALBIN)\r
+       test -s $(LOCALBIN)/controller-gen && $(LOCALBIN)/controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION) || \\r
+       GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)\r
+\r
+.PHONY: envtest\r
+envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.\r
+$(ENVTEST): $(LOCALBIN)\r
+       test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest\r