forked from kubernetes-sigs/cluster-api-provider-aws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
284 lines (231 loc) · 10.1 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# Copyright 2018 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# If you update this file, please follow
# https://suva.sh/posts/well-documented-makefiles
.DEFAULT_GOAL:=help
# A release should define this with gcr.io/cluster-api-provider-aws
REGISTRY ?= gcr.io/$(shell gcloud config get-value project)
# A release should define this with IfNotPresent
PULL_POLICY ?= Always
# A release does not need to define this
MANAGER_IMAGE_NAME ?= cluster-api-aws-controller
# A release should define this with the next version after 0.0.4
MANAGER_IMAGE_TAG ?= dev
## Image URL to use all building/pushing image targets
DEPCACHEAGE ?= 24h # Enables caching for Dep
BAZEL_ARGS ?=
BAZEL_BUILD_ARGS := --define=REGISTRY=$(REGISTRY)\
--define=PULL_POLICY=$(PULL_POLICY)\
--define=MANAGER_IMAGE_NAME=$(MANAGER_IMAGE_NAME)\
--define=MANAGER_IMAGE_TAG=$(MANAGER_IMAGE_TAG)\
--host_force_python=PY2\
$(BAZEL_ARGS)
# Bazel variables
BAZEL_VERSION := $(shell command -v bazel 2> /dev/null)
DEP ?= bazel run dep
# Determine the OS
HOSTOS := $(shell go env GOHOSTOS)
HOSTARCH := $(shell go env GOARCH)
BINARYPATHPATTERN :=${HOSTOS}_${HOSTARCH}_*
ifndef BAZEL_VERSION
$(error "Bazel is not available. \
Installation instructions can be found at \
https://docs.bazel.build/versions/master/install.html")
endif
.PHONY: all
all: check-install test binaries
help: ## Display this help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
## --------------------------------------
## Testing
## --------------------------------------
.PHONY: test
test: generate verify ## Run tests
bazel test --nosandbox_debug //pkg/... //cmd/... $(BAZEL_ARGS)
.PHONY: integration
integration: generate verify ## Run integraion tests
bazel test --define='gotags=integration' --test_output all //test/integration/...
JANITOR_ENABLED ?= 0
.PHONY: e2e
e2e: generate verify ## Run e2e tests
JANITOR_ENABLED=$(JANITOR_ENABLED) ./hack/e2e.sh $(BAZEL_BUILD_ARGS)
.PHONY: e2e-janitor
e2e-janitor:
./hack/e2e-aws-janitor.sh
## --------------------------------------
## Docker
## --------------------------------------
.PHONY: docker-build
docker-build: generate ## Build the production docker image
bazel run //cmd/manager:manager-image $(BAZEL_BUILD_ARGS)
.PHONY: docker-push
docker-push: ## Push production docker image
bazel run //cmd/manager:manager-push $(BAZEL_BUILD_ARGS)
## --------------------------------------
## Cleanup / Verification
## --------------------------------------
.PHONY: clean
clean: ## Remove all generated files
rm -rf cmd/clusterctl/examples/aws/out/
rm -f kubeconfig
rm -f minikube.kubeconfig
rm -f bazel-*
rm -rf out/
rm -f cmd/clusterctl/examples/aws/provider-components-base.yaml
.PHONY: check-install
check-install: ## Checks that you've installed this repository correctly
@./scripts/check-install.sh
.PHONY: verify
verify: ## Runs verification scripts to ensure correct execution
./hack/verify_boilerplate.py
## --------------------------------------
## Manifests
## --------------------------------------
.PHONY: manifests
manifests: clusterawsadm cmd/clusterctl/examples/aws/provider-components-base.yaml ## Build example set of manifests from the current source
./cmd/clusterctl/examples/aws/generate-yaml.sh
.PHONY: cmd/clusterctl/examples/aws/provider-components-base.yaml
cmd/clusterctl/examples/aws/provider-components-base.yaml:
bazel build //cmd/clusterctl/examples/aws:provider-components-base $(BAZEL_BUILD_ARGS)
install bazel-genfiles/cmd/clusterctl/examples/aws/provider-components-base.yaml cmd/clusterctl/examples/aws
## --------------------------------------
## Generate
## --------------------------------------
.PHONY: dep-ensure
dep-ensure: check-install ## Ensure dependencies are up to date
@${DEP} ensure
$(MAKE) remove-vendor-symlinks
$(MAKE) gazelle
.PHONY: remove-vendor-symlinks
remove-vendor-symlinks: ## Remove broken symlinks created by dep
find vendor -type l ! -exec test -e {} \; -print0 | xargs -0 rm -v
.PHONY: gazelle
gazelle: ## Run Bazel Gazelle
bazel run //:gazelle $(BAZEL_ARGS)
.PHONY: generate
generate: ## Generate mocks, CRDs and runs `go generate` through Bazel
GOPATH=$(shell go env GOPATH) bazel run //:generate $(BAZEL_ARGS)
$(MAKE) dep-ensure
bazel build $(BAZEL_ARGS) //pkg/cloud/aws/services/mocks:mocks \
//pkg/cloud/aws/services/ec2/mock_ec2iface:mocks \
//pkg/cloud/aws/services/elb/mock_elbiface:mocks
./hack/copy-bazel-mocks.sh
$(MAKE) generate-crds
.PHONY: generate-crds
generate-crds:
bazel build //config
cp -R bazel-genfiles/config/crds/* config/crds/
cp -R bazel-genfiles/config/rbac/* config/rbac/
## --------------------------------------
## Linting
## --------------------------------------
.PHONY: lint
lint: dep-ensure ## Lint codebase
bazel run //:lint $(BAZEL_ARGS)
lint-full: dep-ensure ## Run slower linters to detect possible issues
bazel run //:lint-full $(BAZEL_ARGS)
## --------------------------------------
## Binaries
## --------------------------------------
.PHONY: binaries
binaries: generate manager clusterawsadm clusterctl ## Builds and installs all binaries
.PHONY: manager
manager: ## Build manager binary.
bazel build //cmd/manager $(BAZEL_ARGS)
install bazel-bin/cmd/manager/${BINARYPATHPATTERN}/manager $(shell go env GOPATH)/bin/aws-manager
.PHONY: clusterctl
clusterctl: ## Build clusterctl binary.
bazel build --workspace_status_command=./hack/print-workspace-status.sh //cmd/clusterctl $(BAZEL_ARGS)
install bazel-bin/cmd/clusterctl/${BINARYPATHPATTERN}/clusterctl $(shell go env GOPATH)/bin/clusterctl
.PHONY: clusterawsadm
clusterawsadm: ## Build clusterawsadm binary.
bazel build --workspace_status_command=./hack/print-workspace-status.sh //cmd/clusterawsadm $(BAZEL_ARGS)
install bazel-bin/cmd/clusterawsadm/${BINARYPATHPATTERN}/clusterawsadm $(shell go env GOPATH)/bin/clusterawsadm
## --------------------------------------
## Release
## --------------------------------------
.PHONY: release-artifacts
release-artifacts: ## Build release artifacts
bazel build --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 //cmd/clusterctl //cmd/clusterawsadm
bazel build --platforms=@io_bazel_rules_go//go/toolchain:darwin_amd64 //cmd/clusterctl //cmd/clusterawsadm
bazel build //cmd/clusterctl/examples/aws $(BAZEL_BUILD_ARGS)
mkdir -p out
install bazel-bin/cmd/clusterawsadm/darwin_amd64_pure_stripped/clusterawsadm out/clusterawsadm-darwin-amd64
install bazel-bin/cmd/clusterawsadm/linux_amd64_pure_stripped/clusterawsadm out/clusterawsadm-linux-amd64
install bazel-bin/cmd/clusterctl/darwin_amd64_pure_stripped/clusterctl out/clusterctl-darwin-amd64
install bazel-bin/cmd/clusterctl/linux_amd64_pure_stripped/clusterctl out/clusterctl-linux-amd64
install bazel-bin/cmd/clusterctl/examples/aws/aws.tar out/cluster-api-provider-aws-examples.tar
## --------------------------------------
## Define local development targets here
## --------------------------------------
.PHONY: binaries-dev
binaries-dev: generate manager clusterawsadm clusterctl
.PHONY: create-cluster
create-cluster: binaries-dev ## Create a development Kubernetes cluster on AWS using examples
clusterctl create cluster -v 4 \
--provider aws \
--bootstrap-type kind \
-m ./cmd/clusterctl/examples/aws/out/machines.yaml \
-c ./cmd/clusterctl/examples/aws/out/cluster.yaml \
-p ./cmd/clusterctl/examples/aws/out/provider-components.yaml \
-a ./cmd/clusterctl/examples/aws/out/addons.yaml
.PHONY: create-cluster-ha
create-cluster-ha: binaries-dev ## Create a development Kubernetes cluster on AWS using HA examples
clusterctl create cluster -v 4 \
--provider aws \
--bootstrap-type kind \
-m ./cmd/clusterctl/examples/aws/out/machines-ha.yaml \
-c ./cmd/clusterctl/examples/aws/out/cluster.yaml \
-p ./cmd/clusterctl/examples/aws/out/provider-components.yaml \
-a ./cmd/clusterctl/examples/aws/out/addons.yaml
.PHONY: create-cluster-management
create-cluster-management: ## Create a development Kubernetes cluster on AWS in a KIND management cluster.
kind create cluster --name=clusterapi
# Apply provider-components.
kubectl \
--kubeconfig=$$(kind get kubeconfig-path --name="clusterapi") \
create -f cmd/clusterctl/examples/aws/out/provider-components.yaml
# Create Cluster.
kubectl \
--kubeconfig=$$(kind get kubeconfig-path --name="clusterapi") \
create -f cmd/clusterctl/examples/aws/out/cluster.yaml
# Create control plane machine.
kubectl \
--kubeconfig=$$(kind get kubeconfig-path --name="clusterapi") \
create -f cmd/clusterctl/examples/aws/out/controlplane-machine.yaml
# Get KubeConfig using clusterctl.
clusterctl alpha phases get-kubeconfig -v=3 \
--kubeconfig=$$(kind get kubeconfig-path --name="clusterapi") \
--provider=aws \
--cluster-name=test1
# Apply addons on the target cluster, waiting for the control-plane to become available.
clusterctl alpha phases apply-addons -v=3 \
--kubeconfig=./kubeconfig \
-a cmd/clusterctl/examples/aws/out/addons.yaml
# Create a worker node with MachineDeployment.
kubectl \
--kubeconfig=$$(kind get kubeconfig-path --name="clusterapi") \
create -f cmd/clusterctl/examples/aws/out/machine-deployment.yaml
.PHONY: delete-cluster
delete-cluster: binaries-dev ## Deletes the development Kubernetes Cluster "test1"
clusterctl delete cluster -v 4 \
--bootstrap-type kind \
--cluster test1 \
--kubeconfig ./kubeconfig \
-p ./cmd/clusterctl/examples/aws/out/provider-components.yaml \
kind-reset: ## Destroys the "clusterapi" kind cluster.
kind delete cluster --name=clusterapi || true
.PHONY: reset-bazel
reset-bazel: ## Deep cleaning for bazel
bazel clean --expunge