|
| 1 | + |
| 2 | +# Image URL to use all building/pushing image targets |
| 3 | +IMG ?= database-interface:latest |
| 4 | + |
| 5 | +CRD_OPTIONS ?= "crd" |
| 6 | + |
| 7 | +# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) |
| 8 | +ifeq (,$(shell go env GOBIN)) |
| 9 | +GOBIN=$(shell go env GOPATH)/bin |
| 10 | +else |
| 11 | +GOBIN=$(shell go env GOBIN) |
| 12 | +endif |
| 13 | + |
| 14 | +all: build |
| 15 | + |
| 16 | +##@ General |
| 17 | + |
| 18 | +# The help target prints out all targets with their descriptions organized |
| 19 | +# beneath their categories. The categories are represented by '##@' and the |
| 20 | +# target descriptions by '##'. The awk commands is responsible for reading the |
| 21 | +# entire set of makefiles included in this invocation, looking for lines of the |
| 22 | +# file as xyz: ## something, and then pretty-format the target and help. Then, |
| 23 | +# if there's a line with ##@ something, that gets pretty-printed as a category. |
| 24 | +# More info on the usage of ANSI control characters for terminal formatting: |
| 25 | +# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters |
| 26 | +# More info on the awk command: |
| 27 | +# http://linuxcommand.org/lc3_adv_awk.php |
| 28 | + |
| 29 | +help: ## Display this help. |
| 30 | + @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) |
| 31 | + |
| 32 | +##@ Development |
| 33 | + |
| 34 | +manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects. |
| 35 | + $(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases |
| 36 | + |
| 37 | +generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations. |
| 38 | + $(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..." |
| 39 | + |
| 40 | +fmt: ## Run go fmt against code. |
| 41 | + go fmt ./... |
| 42 | + |
| 43 | +vet: ## Run go vet against code. |
| 44 | + go vet ./... |
| 45 | + |
| 46 | +ENVTEST_ASSETS_DIR=$(shell pwd)/testbin |
| 47 | +test: manifests generate fmt vet ## Run tests. |
| 48 | + mkdir -p ${ENVTEST_ASSETS_DIR} |
| 49 | + test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.7.2/hack/setup-envtest.sh |
| 50 | + source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out |
| 51 | + |
| 52 | +unit-test: |
| 53 | + go test -tags=unit -v -race ./controllers/... |
| 54 | + |
| 55 | +##@ Build |
| 56 | + |
| 57 | +build: generate fmt vet ## Build manager binary. |
| 58 | + go build -o bin/manager main.go |
| 59 | + |
| 60 | +run: manifests generate fmt vet ## Run a controller from your host. |
| 61 | + ENABLE_WEBHOOKS=false go run ./main.go -zap-log-level 2 |
| 62 | + |
| 63 | +docker-build: build ## Build docker image with the manager. |
| 64 | + docker build -t ${IMG} . |
| 65 | + |
| 66 | +docker-push: ## Push docker image with the manager. |
| 67 | + docker push ${IMG} |
| 68 | + |
| 69 | +##@ Deployment |
| 70 | + |
| 71 | +install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config. |
| 72 | + $(KUSTOMIZE) build config/crd | kubectl apply -f - |
| 73 | + |
| 74 | +uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. |
| 75 | + $(KUSTOMIZE) build config/crd | kubectl delete -f - |
| 76 | + |
| 77 | +deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config. |
| 78 | + cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG} |
| 79 | + $(KUSTOMIZE) build config/default | kubectl apply -f - |
| 80 | + |
| 81 | +undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. |
| 82 | + $(KUSTOMIZE) build config/default | kubectl delete -f - |
| 83 | + |
| 84 | + |
| 85 | +CONTROLLER_GEN = $(shell pwd)/bin/controller-gen |
| 86 | +controller-gen: ## Download controller-gen locally if necessary. |
| 87 | + $(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected]) |
| 88 | + |
| 89 | +KUSTOMIZE = $(shell pwd)/bin/kustomize |
| 90 | +kustomize: ## Download kustomize locally if necessary. |
| 91 | + $(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected]) |
| 92 | + |
| 93 | +client-gen: |
| 94 | + ./hack/update-codegen.sh |
| 95 | + mv github.com/pluralsh/plural-operator/generated generated |
| 96 | + rm -rf github.com |
| 97 | + |
| 98 | +# go-get-tool will 'go get' any package $2 and install it to $1. |
| 99 | +PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST)))) |
| 100 | +define go-get-tool |
| 101 | +@[ -f $(1) ] || { \ |
| 102 | +set -e ;\ |
| 103 | +TMP_DIR=$$(mktemp -d) ;\ |
| 104 | +cd $$TMP_DIR ;\ |
| 105 | +go mod init tmp ;\ |
| 106 | +echo "Downloading $(2)" ;\ |
| 107 | +GOBIN=$(PROJECT_DIR)/bin go install $(2) ;\ |
| 108 | +rm -rf $$TMP_DIR ;\ |
| 109 | +} |
| 110 | +endef |
0 commit comments