1
- # Directory, where all required tools are located (absolute path required)
2
- BUILD_PATH ?= $(shell pwd)
3
- TOOLS_DIR ?= $(shell cd tools 2>/dev/null && pwd)
4
-
5
- YQ ?= yq
6
-
7
- VERSION ?= 0.0.1-local
8
- KUBE_NAMESPACE ?= vault-operator
9
- LATEST_REV = $(shell git rev-list --tags --max-count=1)
10
- LATEST_TAG = $(shell git describe --tags $(LATEST_REV ) )
11
-
12
- # Prerequisite tools
13
- GO ?= go
14
- GOOS ?= $(go env GOOS )
15
- GOARCH ?= $(go env GOARCH )
16
- DOCKER ?= docker
17
- KUBECTL ?= kubectl
18
-
19
- KIND ?= $(TOOLS_DIR ) /kind
20
- VAULT ?= $(TOOLS_DIR ) /vault
21
- CONTROLLER_GEN ?= $(TOOLS_DIR ) /controller-gen
22
- KUSTOMIZE ?= $(TOOLS_DIR ) /kustomize
23
- KUBEBUILDER ?= $(TOOLS_DIR ) /kubebuilder
24
- KUBEBUILDER_ASSETS ?= $(TOOLS_DIR )
25
-
26
- # Variables
27
- MANAGER_BIN ?= bin/manager
1
+
2
+ # Image URL to use all building/pushing image targets
3
+ IMG ?= controller:latest
4
+ # ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
5
+ ENVTEST_K8S_VERSION = 1.24.1
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-envtest.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
28
22
29
23
# #@ General
30
24
@@ -39,52 +33,143 @@ MANAGER_BIN ?= bin/manager
39
33
# More info on the awk command:
40
34
# http://linuxcommand.org/lc3_adv_awk.php
41
35
36
+ .PHONY : help
42
37
help : # # Display this help.
43
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 )
44
39
45
- export
46
-
47
- .PHONY : all go-test install uninstall deploy manifests
48
-
49
- all : $(MANAGER_BIN )
50
-
51
- $(MANAGER_BIN ) : generate fmt vet
52
- $(GO ) build -o $(MANAGER_BIN ) ./main.go
53
-
54
- add-license : # # Adds the license to every file
55
- @docker run --rm -v " $( PWD) :/src" -u $(shell id -u) ghcr.io/google/addlicense --ignore ** /* .yaml --ignore ** /* .yml -c " VaultOperator Authors" -l " apache" -v .
40
+ # #@ Development
56
41
57
- check-license : # # Checks that the license is set on every file
58
- @docker run --rm -v " $( PWD) :/src" -u $(shell id -u) ghcr.io/google/addlicense --ignore ** /* .yaml --ignore ** /* .yml -c " VaultOperator Authors" -l " apache" -v -check .
59
-
60
- manifests : $(CONTROLLER_GEN ) $(KUSTOMIZE ) # # Generate manifests e.g. CRD, RBAC etc.
61
- $(CONTROLLER_GEN ) crd:trivialVersions=false rbac:roleName=manager-role webhook paths=" ./..." output:crd:artifacts:config=config/crd/bases
62
- echo " # Generated by 'make manifests'\n" > $(HELM_CHART_DIR ) /templates/crds.yaml
42
+ .PHONY : manifests
43
+ manifests : controller-gen kustomize # # Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
44
+ $(CONTROLLER_GEN ) rbac:roleName=manager-role crd webhook paths=" ./..." output:crd:artifacts:config=config/crd/bases
45
+ echo " # Generated by 'make manifests'" > $(HELM_CHART_DIR ) /templates/crds.yaml
63
46
$(KUSTOMIZE ) build config/crd-templates >> $(HELM_CHART_DIR ) /templates/crds.yaml
64
- echo " # Generated by 'make manifests'\n " > $(HELM_CHART_DIR ) /templates/webhook.yaml
47
+ echo " # Generated by 'make manifests'" > $(HELM_CHART_DIR ) /templates/webhook.yaml
65
48
$(KUSTOMIZE ) build config/webhook-templates >> $(HELM_CHART_DIR ) /templates/webhook.yaml
66
49
67
- generate : $(CONTROLLER_GEN ) # # Generate code using controller-gen
68
-
69
- tools : $(TOOLS_DIR ) /kind $(TOOLS_DIR ) /ginkgo $(TOOLS_DIR ) /controller-gen $(TOOLS_DIR ) /kustomize $(TOOLS_DIR ) /golangci-lint $(TOOLS_DIR ) /kubebuilder # # Phony target to install all required tools into ${TOOLS_DIR}
70
-
71
- $(TOOLS_DIR ) /kind :
72
- @echo " Installing $@ "
73
- @GOBIN=$(TOOLS_DIR ) go install sigs.k8s.io/kind@v0.7.0
74
-
75
- $(TOOLS_DIR ) /controller-gen :
76
- @echo " Installing $@ "
77
- @GOBIN=$(TOOLS_DIR ) go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.2.5
78
-
79
- $(TOOLS_DIR ) /kustomize :
80
- @echo " Installing $@ "
81
- @$(TOOLS_DIR ) /install_kustomize.sh $(TOOLS_DIR )
82
-
83
- $(TOOLS_DIR ) /vault :
84
- @$(TOOLS_DIR ) /vault-install
85
-
86
- $(TOOLS_DIR ) /kubebuilder $(TOOLS_DIR ) /kubectl $(TOOLS_DIR ) /kube-apiserver $(TOOLS_DIR ) /etcd :
87
- @$(TOOLS_DIR ) /kubebuilder-install
50
+ .PHONY : generate
51
+ generate : controller-gen # # Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
52
+ $(CONTROLLER_GEN ) object:headerFile=" hack/boilerplate.go.txt" paths=" ./..."
53
+
54
+ .PHONY : fmt
55
+ fmt : # # Run go fmt against code.
56
+ go fmt ./...
57
+
58
+ .PHONY : vet
59
+ vet : # # Run go vet against code.
60
+ go vet ./...
61
+
62
+ .PHONY : lint
63
+ lint : golangcilint # # Run linter against code.
64
+ $(GOLANGCILINT ) run -v -E goconst -E misspell
65
+
66
+ coverage : # # print coverage from coverprofiles
67
+ go tool cover -func .coverprofile
68
+
69
+ .PHONY : test
70
+ test : ginkgo manifests generate fmt vet envtest vault # # Run tests.
71
+ KUBEBUILDER_ASSETS=" $( shell $( ENVTEST) use $( ENVTEST_K8S_VERSION) -p path) " PATH=" $( PATH) :$( LOCALBIN) " $(GINKGO ) -r -v -cover --failFast -requireSuite -covermode count -outputdir=. -coverprofile=.coverprofile
72
+
73
+ # #@ Build
74
+
75
+ .PHONY : build
76
+ build : generate fmt vet # # Build manager binary.
77
+ go build -o bin/manager main.go
78
+
79
+ .PHONY : run
80
+ run : manifests generate fmt vet # # Run a controller from your host.
81
+ go run ./main.go
82
+
83
+ .PHONY : docker-build
84
+ docker-build : test # # Build docker image with the manager.
85
+ docker build -t ${IMG} .
86
+
87
+ .PHONY : docker-push
88
+ docker-push : # # Push docker image with the manager.
89
+ docker push ${IMG}
90
+
91
+ # #@ Deployment
92
+
93
+ ifndef ignore-not-found
94
+ ignore-not-found = false
95
+ endif
96
+
97
+ .PHONY : install
98
+ install : manifests kustomize # # Install CRDs into the K8s cluster specified in ~/.kube/config.
99
+ $(KUSTOMIZE ) build config/crd | kubectl apply -f -
100
+
101
+ .PHONY : uninstall
102
+ 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.
103
+ $(KUSTOMIZE ) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found ) -f -
104
+
105
+ .PHONY : deploy
106
+ deploy : manifests kustomize # # Deploy controller to the K8s cluster specified in ~/.kube/config.
107
+ cd config/manager && $(KUSTOMIZE ) edit set image controller=${IMG}
108
+ $(KUSTOMIZE ) build config/default | kubectl apply -f -
109
+
110
+ .PHONY : undeploy
111
+ 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.
112
+ $(KUSTOMIZE ) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found ) -f -
113
+
114
+ # #@ Build Dependencies
115
+
116
+ # # Location to install dependencies to
117
+ LOCALBIN ?= $(shell pwd) /bin
118
+ $(LOCALBIN ) :
119
+ mkdir -p $(LOCALBIN )
120
+
121
+ .PHONY :
122
+ clean :
123
+ rm -R $(LOCALBIN )
124
+
125
+ # # Tool Binaries
126
+ KUSTOMIZE ?= $(LOCALBIN ) /kustomize
127
+ CONTROLLER_GEN ?= $(LOCALBIN ) /controller-gen
128
+ ENVTEST ?= $(LOCALBIN ) /setup-envtest
129
+ GINKGO ?= $(LOCALBIN ) /ginkgo
130
+ GOLANGCILINT ?= $(LOCALBIN ) /golangci-lint
131
+ VAULT ?= $(LOCALBIN ) /vault
132
+
133
+ # # Tool Versions
134
+ KUSTOMIZE_VERSION ?= v4.5.5
135
+ CONTROLLER_TOOLS_VERSION ?= v0.8.0
136
+ GINKGO_VERSION ?= v1.16.5
137
+ GOLANGCILINT_VERSION ?= v1.46.1
138
+ VAULT_VERSION ?= 1.9.3
139
+ GO_OS ?= $(shell go env GOOS)
140
+ GO_ARCH ?= $(shell go env GOARCH)
141
+
142
+ KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
143
+ .PHONY : kustomize
144
+ kustomize : $(KUSTOMIZE ) # # Download kustomize locally if necessary.
145
+ $(KUSTOMIZE ) : $(LOCALBIN )
146
+ curl -s $(KUSTOMIZE_INSTALL_SCRIPT ) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION ) ) $(LOCALBIN )
147
+
148
+ .PHONY : controller-gen
149
+ controller-gen : $(CONTROLLER_GEN ) # # Download controller-gen locally if necessary.
150
+ $(CONTROLLER_GEN ) : $(LOCALBIN )
151
+ GOBIN=$(LOCALBIN ) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION )
152
+
153
+ .PHONY : envtest
154
+ envtest : $(ENVTEST ) # # Download envtest-setup locally if necessary.
155
+ $(ENVTEST ) : $(LOCALBIN )
156
+ GOBIN=$(LOCALBIN ) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
157
+
158
+ .PHONY : ginkgo
159
+ ginkgo : $(GINKGO ) # # Download ginkgo locally if necessary.
160
+ $(GINKGO ) : $(LOCALBIN )
161
+ GOBIN=$(LOCALBIN ) go install github.com/onsi/ginkgo/ginkgo@$(GINKGO_VERSION )
162
+
163
+ .PHONY : golangcilint
164
+ golangcilint : $(GOLANGCILINT ) # # Download golangci-lint locally if necessary.
165
+ $(GOLANGCILINT ) : $(LOCALBIN )
166
+ GOBIN=$(LOCALBIN ) go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCILINT_VERSION )
167
+
168
+ .PHONY : vault
169
+ vault : $(VAULT ) # # Download vault locally if necessary.
170
+ $(VAULT ) : $(LOCALBIN )
171
+ wget https://releases.hashicorp.com/vault/$(VAULT_VERSION ) /vault_$(VAULT_VERSION ) _$(GO_OS ) _$(GO_ARCH ) .zip -O $(LOCALBIN ) /vault.zip
172
+ unzip -o $(LOCALBIN ) /vault.zip -d $(LOCALBIN )
173
+ rm $(LOCALBIN ) /vault.zip
88
174
89
- include go.mk
90
175
include helm.mk
0 commit comments