github.com/kotalco/kotal@v0.3.0/Makefile (about)

     1  
     2  # Image URL to use all building/pushing image targets
     3  IMG ?= kotalco/kotal:v0.2.0
     4  # ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
     5  ENVTEST_K8S_VERSION = 1.23
     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  # Setting SHELL to bash allows bash commands to be executed by recipes.
    15  # This is a requirement for 'setup-?.sh' in the test target.
    16  # Options are set to exit when a recipe line exits non-zero or a piped command fails.
    17  SHELL = /usr/bin/env bash -o pipefail
    18  .SHELLFLAGS = -ec
    19  
    20  .PHONY: all
    21  all: build
    22  
    23  ##@ General
    24  
    25  # The help target prints out all targets with their descriptions organized
    26  # beneath their categories. The categories are represented by '##@' and the
    27  # target descriptions by '##'. The awk commands is responsible for reading the
    28  # entire set of makefiles included in this invocation, looking for lines of the
    29  # file as xyz: ## something, and then pretty-format the target and help. Then,
    30  # if there's a line with ##@ something, that gets pretty-printed as a category.
    31  # More info on the usage of ANSI control characters for terminal formatting:
    32  # https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
    33  # More info on the awk command:
    34  # http://linuxcommand.org/lc3_adv_awk.php
    35  
    36  .PHONY: help
    37  help: ## Display this help.
    38  	@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)
    39  
    40  # test operator on multiple k8s cluster versions
    41  # KOTAL_VERSION is released kotal image tag
    42  # K8S_PROVIDER is k8s cluster provider: kind or minikube
    43  # KOTAL_VERSION=$IMG K8S_PROVIDER=minikube make test-multi
    44  # KOTAL_VERSION=$IMG K8S_PROVIDER=kind make test-multi
    45  # make test-multi
    46  .SILENT: test-multi
    47  test-multi:
    48  	chmod +x multi.sh
    49  	./multi.sh
    50  
    51  cover:
    52  	go tool cover -html=cover.out
    53  
    54  
    55  ##@ Build
    56  
    57  # Build manager binary
    58  .PHONY: build
    59  build: generate fmt vet
    60  	go build -o bin/manager main.go
    61  
    62  .PHONY: run
    63  run: generate fmt vet manifests ## Run a controller from your host.
    64  	ENABLE_WEBHOOKS=false go run ./main.go
    65  
    66  # Push the docker image
    67  .PHONY: docker-push
    68  docker-push:
    69  	docker push ${IMG}
    70  
    71  # Build the docker image
    72  .PHONY: docker-build
    73  docker-build: test
    74  	docker build . -t ${IMG}
    75  
    76  ##@ Deployment
    77  
    78  ifndef ignore-not-found
    79    ignore-not-found = false
    80  endif
    81  
    82  # Install CRDs into a cluster
    83  .PHONY: install
    84  install: manifests kustomize
    85  	$(KUSTOMIZE) build config/crd | kubectl apply -f -
    86  
    87  # Uninstall CRDs from a cluster
    88  .PHONY: uninstall kustomize
    89  uninstall: manifests
    90  	$(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
    91  
    92  # Deploy controller in the configured Kubernetes cluster in ~/.kube/config
    93  .PHONY: deploy
    94  deploy: manifests kustomize
    95  	cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
    96  	$(KUSTOMIZE) build config/default | kubectl apply -f -
    97  
    98  .PHONY: undeploy
    99  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.
   100  	$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
   101  
   102  ##@ Development
   103  
   104  # Generate manifests e.g. CRD, RBAC etc.
   105  .PHONY: manifests
   106  manifests: controller-gen
   107  	$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
   108  
   109  .PHONY: generate
   110  generate: controller-gen
   111  	$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
   112  
   113  # Run go fmt against code
   114  fmt:
   115  	go fmt ./...
   116  
   117  # Run go vet against code
   118  vet:
   119  	go vet ./...
   120  
   121  ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
   122  test: manifests generate fmt vet envtest
   123  	KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test -coverprofile cover.out.tmp ./...
   124  	cat cover.out.tmp | grep -v zz_generated > cover.out
   125  
   126  # output manifest files for the release
   127  release: manifests
   128  	cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
   129  	$(KUSTOMIZE) build config/default > kotal.yaml
   130  
   131  # load image into kind
   132  kind-load:
   133  	kind load docker-image ${IMG}
   134  
   135  # Build the docker image
   136  kind: kind-load deploy
   137  
   138  # load image into minikube registry
   139  minikube-load:
   140  	minikube image load ${IMG}
   141  	minikube cache reload
   142  
   143  # Build the docker image
   144  minikube: minikube-load deploy
   145  
   146  
   147  ##@ Build Dependencies
   148  
   149  ## Location to install dependencies to
   150  LOCALBIN ?= $(shell pwd)/bin
   151  $(LOCALBIN): ## Ensure that the directory exists
   152  	mkdir -p $(LOCALBIN)
   153  
   154  ## Tool Binaries
   155  KUSTOMIZE ?= $(LOCALBIN)/kustomize
   156  CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
   157  ENVTEST ?= $(LOCALBIN)/setup-envtest
   158  
   159  ## Tool Versions
   160  KUSTOMIZE_VERSION ?= v3.8.7
   161  CONTROLLER_TOOLS_VERSION ?= v0.8.0
   162  
   163  KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
   164  .PHONY: kustomize
   165  kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
   166  $(KUSTOMIZE):
   167  	curl -s $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN)
   168  
   169  .PHONY: controller-gen
   170  controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
   171  $(CONTROLLER_GEN):
   172  	GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
   173  
   174  .PHONY: envtest
   175  envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
   176  $(ENVTEST): $(LOCALBIN)
   177  	GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest