@@ -39,8 +39,12 @@ BIN_DIR := bin
39
39
KUSTOMIZE := $(TOOLS_BIN_DIR ) /kustomize
40
40
CLUSTERCTL := $(BIN_DIR ) /clusterctl
41
41
CONTROLLER_GEN := $(TOOLS_BIN_DIR ) /controller-gen
42
+ ENVSUBST := $(TOOLS_BIN_DIR ) /envsubst
42
43
GOLANGCI_LINT := $(TOOLS_BIN_DIR ) /golangci-lint
43
44
MOCKGEN := $(TOOLS_BIN_DIR ) /mockgen
45
+ CONVERSION_GEN := $(TOOLS_BIN_DIR ) /conversion-gen
46
+ RELEASE_NOTES_BIN := bin/release-notes
47
+ RELEASE_NOTES := $(TOOLS_DIR ) /$(RELEASE_NOTES_BIN )
44
48
45
49
# Define Docker related variables. Releases should modify and double check these vars.
46
50
REGISTRY ?= gcr.io/$(shell gcloud config get-value project)
@@ -58,9 +62,21 @@ CRD_ROOT ?= $(MANIFEST_ROOT)/crd/bases
58
62
WEBHOOK_ROOT ?= $(MANIFEST_ROOT ) /webhook
59
63
RBAC_ROOT ?= $(MANIFEST_ROOT ) /rbac
60
64
65
+ # Allow overriding the imagePullPolicy
66
+ PULL_POLICY ?= Always
67
+
68
+ # Hosts running SELinux need :z added to volume mounts
69
+ SELINUX_ENABLED := $(shell cat /sys/fs/selinux/enforce 2> /dev/null || echo 0)
70
+
71
+ ifeq ($(SELINUX_ENABLED ) ,1)
72
+ DOCKER_VOL_OPTS? =:z
73
+ endif
74
+
75
+ # Set build time variables including version details
76
+ LDFLAGS := $(shell source ./hack/version.sh; version::ldflags)
77
+
61
78
# Check if binaries exist
62
79
HAS_YQ := $(shell command -v yq;)
63
- HAS_ENVSUBST := $(shell command -v envsubst;)
64
80
65
81
# # --------------------------------------
66
82
# # Help
@@ -97,14 +113,10 @@ test-go: ## Run golang tests
97
113
# See:
98
114
# * https://github.com/mikefarah/yq/issues/291
99
115
# * https://github.com/mikefarah/yq/issues/289
100
- test-generate-examples : $(KUSTOMIZE )
116
+ test-generate-examples : $(KUSTOMIZE ) $( ENVSUBST )
101
117
ifndef HAS_YQ
102
118
echo "installing yq"
103
- GO111MODULE=on go get -u github.com/mikefarah/yq@d05391e
104
- endif
105
- ifndef HAS_ENVSUBST
106
- echo "installing envsubst"
107
- go get github.com/a8m/envsubst/cmd/envsubst
119
+ GO111MODULE=on go get github.com/mikefarah/yq/v2
108
120
endif
109
121
# Create a dummy file for test only
110
122
mkdir -p tmp/dummy-make-auto-test
@@ -137,12 +149,21 @@ $(CLUSTERCTL): go.mod ## Build clusterctl binary.
137
149
$(CONTROLLER_GEN ) : $(TOOLS_DIR ) /go.mod # Build controller-gen from tools folder.
138
150
cd $(TOOLS_DIR ) ; go build -tags=tools -o $(BIN_DIR ) /controller-gen sigs.k8s.io/controller-tools/cmd/controller-gen
139
151
152
+ $(ENVSUBST ) : $(TOOLS_DIR ) /go.mod # Build envsubst from tools folder.
153
+ cd $(TOOLS_DIR ) ; go build -tags=tools -o $(BIN_DIR ) /envsubst github.com/a8m/envsubst/cmd/envsubst
154
+
140
155
$(GOLANGCI_LINT ) : $(TOOLS_DIR ) /go.mod # Build golangci-lint from tools folder.
141
156
cd $(TOOLS_DIR ) ; go build -tags=tools -o $(BIN_DIR ) /golangci-lint github.com/golangci/golangci-lint/cmd/golangci-lint
142
157
143
158
$(MOCKGEN ) : $(TOOLS_DIR ) /go.mod # Build mockgen from tools folder.
144
159
cd $(TOOLS_DIR ) ; go build -tags=tools -o $(BIN_DIR ) /mockgen github.com/golang/mock/mockgen
145
160
161
+ $(CONVERSION_GEN ) : $(TOOLS_DIR ) /go.mod
162
+ cd $(TOOLS_DIR ) ; go build -tags=tools -o $(BIN_DIR ) /conversion-gen k8s.io/code-generator/cmd/conversion-gen
163
+
164
+ $(RELEASE_NOTES ) : $(TOOLS_DIR ) /go.mod
165
+ cd $(TOOLS_DIR ) && go build -tags tools -o $(BIN_DIR ) /release-notes sigs.k8s.io/cluster-api/hack/tools/release
166
+
146
167
# # --------------------------------------
147
168
# # Linting
148
169
# # --------------------------------------
@@ -169,17 +190,22 @@ generate: ## Generate code
169
190
$(MAKE ) generate-manifests
170
191
171
192
.PHONY : generate-go
172
- generate-go : $(CONTROLLER_GEN ) $(MOCKGEN ) # # Runs Go related generate targets
173
- go generate ./...
193
+ generate-go : $(CONTROLLER_GEN ) $(CONVERSION_GEN ) $(MOCKGEN ) # # Runs Go related generate targets
174
194
$(CONTROLLER_GEN ) \
175
195
paths=./api/... \
176
- object:headerFile=./hack/boilerplate.go.txt
196
+ object:headerFile=./hack/boilerplate/boilerplate.generatego.txt
197
+
198
+ $(CONVERSION_GEN) \
199
+ --input-dirs=./api/v1alpha2 \
200
+ --output-file-base=zz_generated.conversion \
201
+ --go-header-file=./hack/boilerplate/boilerplate.generatego.txt
202
+ go generate ./...
177
203
178
204
.PHONY : generate-manifests
179
205
generate-manifests : $(CONTROLLER_GEN ) # # Generate manifests e.g. CRD, RBAC etc.
180
206
$(CONTROLLER_GEN ) \
181
207
paths=./api/... \
182
- crd \
208
+ crd:crdVersions=v1 \
183
209
output:crd:dir=$(CRD_ROOT ) \
184
210
output:webhook:dir=$(WEBHOOK_ROOT ) \
185
211
webhook
@@ -190,15 +216,21 @@ generate-manifests: $(CONTROLLER_GEN) ## Generate manifests e.g. CRD, RBAC etc.
190
216
191
217
.PHONY : generate-examples
192
218
generate-examples : clean-examples # # Generate examples configurations to run a cluster.
193
- ./examples/generate.sh
219
+ ifndef HAS_YQ
220
+ echo "installing yq"
221
+ GO111MODULE=on go get github.com/mikefarah/yq/v2
222
+ endif
223
+ ./examples/generate.sh -f ${OPENSTACK_CONFIG_FILE} ${CLUSTER_NAME} ./examples/_out single-node
194
224
195
225
# # --------------------------------------
196
226
# # Docker
197
227
# # --------------------------------------
198
228
199
229
.PHONY : docker-build
200
230
docker-build : # # Build the docker image for controller-manager
201
- docker build --pull --build-arg ARCH=$(ARCH ) . -t $(CONTROLLER_IMG ) -$(ARCH ) :$(TAG )
231
+ docker build --pull --build-arg ARCH=$(ARCH ) --build-arg LDFLAGS=" $( LDFLAGS) " . -t $(CONTROLLER_IMG ) -$(ARCH ) :$(TAG )
232
+ MANIFEST_IMG=$(CONTROLLER_IMG ) -$(ARCH ) MANIFEST_TAG=$(TAG ) $(MAKE ) set-manifest-image
233
+ $(MAKE ) set-manifest-pull-policy
202
234
203
235
.PHONY : docker-push
204
236
docker-push : # # Push the docker image
@@ -226,18 +258,20 @@ docker-push-manifest: ## Push the fat manifest docker image.
226
258
# # Minimum docker version 18.06.0 is required for creating and pushing manifest images.
227
259
docker manifest create --amend $(CONTROLLER_IMG ) :$(TAG ) $(shell echo $(ALL_ARCH ) | sed -e "s~[^ ]* ~$(CONTROLLER_IMG ) \-&:$(TAG ) ~g")
228
260
@for arch in $(ALL_ARCH ) ; do docker manifest annotate --arch $$ {arch} ${CONTROLLER_IMG} :${TAG} ${CONTROLLER_IMG} -$$ {arch}:${TAG} ; done
229
- docker manifest push --purge $(CONTROLLER_IMG ) :$(TAG )
261
+ docker manifest push --purge ${CONTROLLER_IMG} :${TAG}
262
+ MANIFEST_IMG=$(CONTROLLER_IMG ) MANIFEST_TAG=$(TAG ) $(MAKE ) set-manifest-image
263
+ $(MAKE ) set-manifest-pull-policy
230
264
231
265
.PHONY : set-manifest-image
232
266
set-manifest-image :
233
267
$(info Updating kustomize image patch file for manager resource)
234
- sed -i' ' -e ' s@image: .*@image: ' " ${MANIFEST_IMG} :$( MANIFEST_TAG) " ' @' ./config/default /manager_image_patch.yaml
268
+ sed -i' ' -e ' s@image: .*@image: ' " ${MANIFEST_IMG} :$( MANIFEST_TAG) " ' @' ./config/manager /manager_image_patch.yaml
235
269
236
270
237
271
.PHONY : set-manifest-pull-policy
238
272
set-manifest-pull-policy :
239
273
$(info Updating kustomize pull policy file for manager resource)
240
- sed -i' ' -e ' s@imagePullPolicy: .*@imagePullPolicy: ' " $( PULL_POLICY) " ' @' ./config/default /manager_pull_policy.yaml
274
+ sed -i' ' -e ' s@imagePullPolicy: .*@imagePullPolicy: ' " $( PULL_POLICY) " ' @' ./config/manager /manager_pull_policy.yaml
241
275
242
276
# # --------------------------------------
243
277
# # Release
@@ -250,87 +284,105 @@ $(RELEASE_DIR):
250
284
mkdir -p $(RELEASE_DIR ) /
251
285
252
286
.PHONY : release
253
- release : clean-release # # Builds and push container images using the latest git tag for the commit.
287
+ release : clean-release # # Builds and push container images using the latest git tag for the commit.
254
288
@if [ -z " ${RELEASE_TAG} " ]; then echo " RELEASE_TAG is not set" ; exit 1; fi
255
- # Push the release image to the staging bucket first.
256
- REGISTRY=$(STAGING_REGISTRY ) TAG=$(RELEASE_TAG ) \
257
- $(MAKE ) docker-build-all docker-push-all
289
+ @if ! [ -z " $$ (git status --porcelain)" ]; then echo " Your local git repository contains uncommitted changes, use git clean before proceeding." ; exit 1; fi
290
+ git checkout " ${RELEASE_TAG} "
258
291
# Set the manifest image to the production bucket.
292
+ $(MAKE ) set-manifest-image MANIFEST_IMG=$(PROD_REGISTRY ) /$(IMAGE_NAME ) MANIFEST_TAG=$(RELEASE_TAG )
293
+ $(MAKE ) set-manifest-pull-policy PULL_POLICY=IfNotPresent
259
294
$(MAKE ) release-manifests
260
295
261
296
.PHONY : release-manifests
262
297
release-manifests : $(RELEASE_DIR ) # # Builds the manifests to publish with a release
263
- MANIFEST_IMG=$(PROD_REGISTRY ) /$(IMAGE_NAME ) MANIFEST_TAG=$(RELEASE_TAG ) \
264
- $(MAKE ) set-manifest-image
265
- PULL_POLICY=IfNotPresent $(MAKE ) set-manifest-pull-policy
266
- $(KUSTOMIZE ) build config/default > $(RELEASE_DIR ) /infrastructure-components.yaml
298
+ kustomize build config > $(RELEASE_DIR ) /infrastructure-components.yaml
299
+
300
+ .PHONY : release-binary
301
+ release-binary : $(RELEASE_DIR )
302
+ docker run \
303
+ --rm \
304
+ -e CGO_ENABLED=0 \
305
+ -e GOOS=$(GOOS ) \
306
+ -e GOARCH=$(GOARCH ) \
307
+ -v " $$ (pwd):/workspace$( DOCKER_VOL_OPTS) " \
308
+ -w /workspace \
309
+ golang:1.13.8 \
310
+ go build -a -ldflags ' $(LDFLAGS) -extldflags "-static"' \
311
+ -o $(RELEASE_DIR ) /$(notdir $(RELEASE_BINARY ) ) -$(GOOS ) -$(GOARCH ) $(RELEASE_BINARY )
267
312
268
313
.PHONY : release-staging
269
314
release-staging : # # Builds and push container images to the staging bucket.
270
315
REGISTRY=$(STAGING_REGISTRY ) $(MAKE ) docker-build-all docker-push-all release-alias-tag
271
316
272
- RELEASE_ALIAS_TAG =$(shell if [ " $( PULL_BASE_REF ) " = "master" ]; then echo "latest"; else echo " $( PULL_BASE_REF ) "; fi )
317
+ RELEASE_ALIAS_TAG =$(PULL_BASE_REF )
273
318
274
319
.PHONY : release-alias-tag
275
320
release-alias-tag : # Adds the tag to the last build tag.
276
321
gcloud container images add-tag $(CONTROLLER_IMG ) :$(TAG ) $(CONTROLLER_IMG ) :$(RELEASE_ALIAS_TAG )
277
322
323
+ .PHONY : release-notes
324
+ release-notes : $(RELEASE_NOTES )
325
+ $(RELEASE_NOTES ) $(ARGS )
326
+
278
327
# # --------------------------------------
279
328
# # Development
280
329
# # --------------------------------------
281
330
331
+ # This is used in the get-kubeconfig call below in the create-cluster target. It may be overridden by the
332
+ # e2e-conformance.sh script, which is why we need it as a variable here.
333
+ CLUSTER_NAME ?= test1
334
+
335
+ # NOTE: do not add 'generate-exmaples' as a prerequisite of this target. It will break e2e conformance testing.
282
336
.PHONY : create-cluster
283
- create-cluster : $(CLUSTERCTL ) # # Create a development Kubernetes cluster on OpenStack using examples
284
- $(CLUSTERCTL ) \
285
- create cluster -v 4 \
286
- --bootstrap-flags=" name=clusterapi" \
287
- --bootstrap-type kind \
288
- -m ./examples/_out/controlplane.yaml \
289
- -c ./examples/_out/cluster.yaml \
290
- -p ./examples/_out/provider-components.yaml \
291
- -a ./examples/addons.yaml
292
-
293
-
294
- .PHONY : create-cluster-management
295
- create-cluster-management : $(CLUSTERCTL ) # # Create a development Kubernetes cluster on OpenStack in a KIND management cluster.
296
- kind create cluster --name=clusterapi
337
+ create-cluster : $(CLUSTERCTL ) $(ENVSUBST ) # # Create a development Kubernetes cluster on OpenStack in a KIND management cluster.
338
+ @if [ -z ` kind get clusters | grep clusterapi` ]; then \
339
+ kind create cluster --name=clusterapi; \
340
+ fi
341
+ @if [ ! -z " ${LOAD_IMAGE} " ]; then \
342
+ echo " loading ${LOAD_IMAGE} into kind cluster ..." && \
343
+ kind --name=" clusterapi" load docker-image " ${LOAD_IMAGE} " ; \
344
+ fi
345
+ # Install cert manager and wait for availability
346
+ kubectl apply -f https://github.com/jetstack/cert-manager/releases/download/v0.11.1/cert-manager.yaml
347
+ kubectl wait --for=condition=Available --timeout=5m apiservice v1beta1.webhook.cert-manager.io
348
+
349
+ # Deploy CAPI
350
+ kubectl apply -f https://github.com/kubernetes-sigs/cluster-api/releases/download/v0.3.0-rc.3/cluster-api-components.yaml
351
+
352
+ # Deploy CAPO
353
+ kustomize build config | $(ENVSUBST) | kubectl apply -f -
354
+
355
+ # Wait for CAPI pods
356
+ kubectl wait --for=condition=Ready --timeout=5m -n capi-system pod -l cluster.x-k8s.io/provider=cluster-api
357
+ kubectl wait --for=condition=Ready --timeout=5m -n capi-kubeadm-bootstrap-system pod -l cluster.x-k8s.io/provider=bootstrap-kubeadm
358
+ kubectl wait --for=condition=Ready --timeout=5m -n capi-kubeadm-control-plane-system pod -l cluster.x-k8s.io/provider=control-plane-kubeadm
359
+
360
+ # Wait for CAPO pods
361
+ kubectl wait --for=condition=Ready --timeout=5m -n capo-system pod -l cluster.x-k8s.io/provider=infrastructure-openstack
362
+
363
+ # FIXME:
364
+ # Create Cluster.
365
+ # sleep 10
366
+ # kustomize build templates | $(ENVSUBST) | kubectl apply -f -
367
+
297
368
# Apply provider-components.
298
- kubectl \
299
- --kubeconfig=$$(kind get kubeconfig-path --name="clusterapi" ) \
300
- create -f examples/_out/provider-components.yaml
369
+ kubectl apply -f examples/_out/provider-components.yaml
301
370
# Create Cluster.
302
- kubectl \
303
- --kubeconfig=$$(kind get kubeconfig-path --name="clusterapi" ) \
304
- create -f examples/_out/cluster.yaml
371
+ kubectl apply -f examples/_out/cluster.yaml
305
372
# Create control plane machine.
306
- kubectl \
307
- --kubeconfig=$$(kind get kubeconfig-path --name="clusterapi" ) \
308
- create -f examples/_out/controlplane.yaml
309
- # Get KubeConfig using clusterctl.
310
- $(CLUSTERCTL ) \
311
- alpha phases get-kubeconfig -v=3 \
312
- --kubeconfig=$$(kind get kubeconfig-path --name="clusterapi" ) \
313
- --namespace=default \
314
- --cluster-name=test1
315
- # Apply addons on the target cluster, waiting for the control-plane to become available.
316
- $(CLUSTERCTL ) \
317
- alpha phases apply-addons -v=3 \
318
- --kubeconfig=./kubeconfig \
319
- -a examples/addons.yaml
373
+ kubectl apply -f examples/_out/controlplane.yaml
374
+
375
+ # Wait for the kubeconfig to become available.
376
+ timeout 300 bash -c "while ! kubectl -n $(CLUSTER_NAME) get secrets | grep $(CLUSTER_NAME)-kubeconfig; do sleep 1; done"
377
+ # Get kubeconfig and store it locally.
378
+ kubectl -n $(CLUSTER_NAME) get secrets $(CLUSTER_NAME)-kubeconfig -o json | jq -r .data.value | base64 --decode > ./kubeconfig
379
+ timeout 300 bash -c "while ! kubectl --kubeconfig=./kubeconfig get nodes | grep master; do sleep 1; done"
380
+
381
+ # Deploy calico
382
+ kubectl --kubeconfig=./kubeconfig apply -f https://docs.projectcalico.org/manifests/calico.yaml
383
+ # FIXME:
320
384
# Create a worker node with MachineDeployment.
321
- kubectl \
322
- --kubeconfig=$$(kind get kubeconfig-path --name="clusterapi" ) \
323
- create -f examples/_out/machinedeployment.yaml
324
-
325
- .PHONY : delete-cluster
326
- delete-cluster : $(CLUSTERCTL ) # # Deletes the development Kubernetes Cluster "test1"
327
- $(CLUSTERCTL ) \
328
- delete cluster -v 4 \
329
- --bootstrap-type kind \
330
- --bootstrap-flags=" name=clusterapi" \
331
- --cluster test1 \
332
- --kubeconfig ./kubeconfig \
333
- -p ./examples/_out/provider-components.yaml \
385
+ kubectl apply -f examples/_out/machinedeployment.yaml
334
386
335
387
.PHONY : kind-reset
336
388
kind-reset : # # Destroys the "clusterapi" kind cluster.
@@ -359,11 +411,28 @@ clean-temporary: ## Remove all temporary files and folders
359
411
clean-release : # # Remove the release folder
360
412
rm -rf $(RELEASE_DIR )
361
413
414
+ # FIXME:
362
415
.PHONY : clean-examples
363
416
clean-examples : # # Remove all the temporary files generated in the examples folder
364
417
rm -rf examples/_out/
365
418
rm -f examples/provider-components/provider-components-* .yaml
366
419
367
- .PHONY : verify-install
368
- verify-install : # # Checks that you've installed this repository correctly
369
- ./hack/verify-install.sh
420
+ .PHONY : verify
421
+ verify : verify-boilerplate verify-modules verify-gen
422
+
423
+ .PHONY : verify-boilerplate
424
+ verify-boilerplate :
425
+ ./hack/verify-boilerplate.sh
426
+
427
+ .PHONY : verify-modules
428
+ verify-modules : modules
429
+ @if ! (git diff --quiet HEAD -- go.sum go.mod hack/tools/go.mod hack/tools/go.sum); then \
430
+ git diff; \
431
+ echo " go module files are out of date" ; exit 1; \
432
+ fi
433
+
434
+ verify-gen : generate
435
+ @if ! (git diff --quiet HEAD); then \
436
+ git diff; \
437
+ echo " generated files are out of date, run make generate" ; exit 1; \
438
+ fi
0 commit comments