This repository has been archived by the owner on Nov 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
100 lines (65 loc) · 3.15 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
NAME := manager
IMG_TAG ?= latest
IMG ?= docker.io/criticalstack/stackapps:$(IMG_TAG)
KUBEBUILDER_VERSION ?= 2.3.1
BIN_DIR := bin
TOOLS_DIR := $(shell pwd)/hack/tools
TOOLS_BIN_DIR := $(TOOLS_DIR)/bin
CONTROLLER_GEN := $(TOOLS_BIN_DIR)/controller-gen
export GO111MODULE := on
export CGO_ENABLED := 0
API_DIR := api
API_SRC := $(shell find $(API_DIR) -type f \( -name '*.go' -not -name 'zz_generated.*' \))
API_DEEPCOPY := $(addsuffix /zz_generated.deepcopy.go,$(shell find $(API_DIR) -type d -not -name $(API_DIR)))
OBJECT_HEADER := hack/boilerplate.go.txt
CONTROLLER_GEN_CRD_OPTIONS ?= crd:trivialVersions=true
CONTROLLER_GEN_OBJECT_OPTIONS ?= object:headerFile=$(OBJECT_HEADER)
export KUBEBUILDER_ASSETS := $(TOOLS_BIN_DIR)
KUBEBUILDER_ASSETS_BIN := $(addprefix $(TOOLS_BIN_DIR)/,kubebuilder kube-apiserver etcd kubectl)
##@ Build
.PHONY: build run test fmt vet image
build: $(BIN_DIR)/$(NAME) ## Build controller-manager binary
$(BIN_DIR)/$(NAME): deepcopy-gen fmt
go build -o $@ main.go
run: deepcopy-gen fmt ## Run against the configured Kubernetes cluster in ~/.kube/config
go run ./main.go
test: $(KUBEBUILDER_ASSETS_BIN) deepcopy-gen vet ## Run go tests
go test ./... -coverprofile cover.out
vtest: $(KUBEBUILDER_ASSETS_BIN) deepcopy-gen vet ## Run go tests (verbose)
go test -v ./... -coverprofile cover.out
fmt: ## Run go fmt against code
go fmt ./...
vet: ## Run go vet against code
go vet ./...
image: ## Build manager container image
docker build . -t ${IMG}
##@ Codegen
.PHONY: deepcopy-gen crds
deepcopy-gen: $(API_DEEPCOPY) ## Generate k8s object deepcopy methods
$(API_DEEPCOPY): $(CONTROLLER_GEN) $(OBJECT_HEADER) $(API_SRC)
$(CONTROLLER_GEN) $(CONTROLLER_GEN_OBJECT_OPTIONS) paths="./..."
crds: manifests/crds ## Generate CRD manifests
chart/crds: $(CONTROLLER_GEN) $(API_SRC)
$(CONTROLLER_GEN) $(CONTROLLER_GEN_CRD_OPTIONS) paths="./..." output:crd:artifacts:config=$@
@touch $@ # touch the directory to update the timestamp in case no new files were created
##@ Deploy
.PHONY: deploy install uninstall
deploy: crds ## Deploy helm cahrt in the configured Kubernetes cluster in ~/.kube/configs
helm template cs-stackapps ./chart | kubectl apply -f -
install: crds ## Install CRDs into a cluster
kubectl apply -f chart/crds
uninstall: crds ## Uninstall CRDs from a cluster
kubectl delete -f chart/crds
##@ Helpers
.PHONY: clean help
$(KUBEBUILDER_ASSETS_BIN):
mkdir -p $(KUBEBUILDER_ASSETS)
curl -L https://go.kubebuilder.io/dl/$(KUBEBUILDER_VERSION)/$(shell go env GOOS)/$(shell go env GOARCH) | tar -xz -C /tmp/
mv /tmp/kubebuilder_$(KUBEBUILDER_VERSION)_$(shell go env GOOS)_$(shell go env GOARCH)/bin/* $(KUBEBUILDER_ASSETS)/
$(CONTROLLER_GEN): $(TOOLS_DIR)/go.mod # Build controller-gen from tools folder.
cd $(TOOLS_DIR); go build -o bin/controller-gen sigs.k8s.io/controller-tools/cmd/controller-gen
clean: ## Cleanup build folders
rm -f $(BIN_DIR)/*
rm -f $(TOOLS_BIN_DIR)/*
help: ## Display this help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z0-9_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)