forked from syself/cluster-api-provider-hetzner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
731 lines (593 loc) · 34.4 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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
# Copyright 2022 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.
# Ensure Make is run with bash shell as some syntax below is bash-specific
# Setting SHELL to bash allows bash commands to be executed by recipes.
# This is a requirement for 'setup-envtest.sh' in the test target.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec
.DEFAULT_GOAL:=help
#
# Directories.
#
# Full directory of where the Makefile resides
ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
EXP_DIR := exp
BIN_DIR := bin
TEST_DIR := test
TOOLS_DIR := hack/tools
TOOLS_BIN_DIR := $(TOOLS_DIR)/$(BIN_DIR)
export PATH := $(abspath $(TOOLS_BIN_DIR)):$(PATH)
# Default path for Kubeconfig File.
CAPH_WORKER_CLUSTER_KUBECONFIG ?= "/tmp/workload-kubeconfig"
INTEGRATION_CONF_FILE ?= "$(abspath test/integration/integration-dev.yaml)"
E2E_TEMPLATE_DIR := "$(abspath test/e2e/data/infrastructure-hetzner/)"
ARTIFACTS_PATH := $(ROOT_DIR)/_artifacts
CI_KIND ?= true
#
# Binaries.
#
MINIMUM_CLUSTERCTL_VERSION=1.1.4 # https://github.com/kubernetes-sigs/cluster-api/releases
MINIMUM_CTLPTL_VERSION=0.8.3 # https://github.com/tilt-dev/ctlptl/releases
MINIMUM_GO_VERSION=go$(GO_VERSION) # Check current project go version
MINIMUM_HCLOUD_VERSION=1.29.4 # https://github.com/hetznercloud/cli/releases
MINIMUM_HELMFILE_VERSION=v0.144.0 # https://github.com/roboll/helmfile/releases
MINIMUM_KIND_VERSION=v0.14.0 # https://github.com/kubernetes-sigs/kind/releases
MINIMUM_KUBECTL_VERSION=v1.24.0 # https://github.com/kubernetes/kubernetes/releases
MINIMUM_PACKER_VERSION=1.8.1 # https://github.com/hashicorp/packer/releases
MINIMUM_TILT_VERSION=0.30.1 # https://github.com/tilt-dev/tilt/releases
KUSTOMIZE_VERSION=4.5.4 # https://github.com/kubernetes-sigs/kustomize/releases
#
# Tooling Binaries.
#
CONTROLLER_GEN := $(abspath $(TOOLS_BIN_DIR)/controller-gen)
KUSTOMIZE := $(abspath $(TOOLS_BIN_DIR)/kustomize)
GOLANGCI_LINT := $(abspath $(TOOLS_BIN_DIR)/golangci-lint)
CONVERSION_GEN := $(abspath $(TOOLS_BIN_DIR)/conversion-gen)
ENVSUBST_BIN := $(BIN_DIR)/envsubst
ENVSUBST := $(TOOLS_DIR)/$(ENVSUBST_BIN)
SETUP_ENVTEST := $(abspath $(TOOLS_BIN_DIR)/setup-envtest)
GINKGO := $(TOOLS_BIN_DIR)/ginkgo
GO_APIDIFF_BIN := $(BIN_DIR)/go-apidiff
GO_APIDIFF := $(TOOLS_DIR)/$(GO_APIDIFF_BIN)
TIMEOUT := $(shell command -v timeout || command -v gtimeout)
KIND := $(TOOLS_BIN_DIR)/kind
#
# HELM.
#
MINIMUM_HELM_VERSION=v3.8.0 # https://github.com/helm/helm/releases
HELM_GIT_VERSION=0.11.1 # https://github.com/aslafy-z/helm-git/releases
HELM_DIFF_VERSION=3.4.1 # https://github.com/databus23/helm-diff/releases
#
# Go.
#
GO_VERSION ?= 1.18.2
GO_CONTAINER_IMAGE ?= docker.io/library/golang:$(GO_VERSION)
# Use GOPROXY environment variable if set
GOPROXY := $(shell go env GOPROXY)
ifeq ($(GOPROXY),)
GOPROXY := https://proxy.golang.org
endif
export GOPROXY
# Active module mode, as we use go modules to manage dependencies
export GO111MODULE=on
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif
# Set --output-base for conversion-gen if we are not within GOPATH
ifneq ($(abspath $(ROOT_DIR)),$(shell go env GOPATH)/src/sigs.k8s.io/cluster-api)
CONVERSION_GEN_OUTPUT_BASE := --output-base=$(ROOT_DIR)
else
export GOPATH := $(shell go env GOPATH)
endif
#
# Kubebuilder.
#
export KUBEBUILDER_ENVTEST_KUBERNETES_VERSION ?= 1.23.3
export KUBEBUILDER_CONTROLPLANE_START_TIMEOUT ?= 60s
export KUBEBUILDER_CONTROLPLANE_STOP_TIMEOUT ?= 60s
#
# Container related variables. Releases should modify and double check these vars.
#
REGISTRY ?= quay.io/syself
PROD_REGISTRY := quay.io/syself
IMAGE_NAME ?= cluster-api-provider-hetzner
CONTROLLER_IMG ?= $(REGISTRY)/$(IMAGE_NAME)
TAG ?= dev
ARCH ?= amd64
# Modify these according to your needs
PLATFORMS = linux/amd64,linux/arm64
# Allow overriding the imagePullPolicy
PULL_POLICY ?= Always
# Build time versioning details.
LDFLAGS := $(shell hack/version.sh)
# This option is for running docker manifest command
export DOCKER_CLI_EXPERIMENTAL := enabled
all: help
##@ General
# The help target prints out all targets with their descriptions organized
# beneath their categories. The categories are represented by '##@' and the
# target descriptions by '##'. The awk commands is responsible for reading the
# entire set of makefiles included in this invocation, looking for lines of the
# file as xyz: ## something, and then pretty-format the target and help. Then,
# if there's a line with ##@ something, that gets pretty-printed as a category.
# More info on the usage of ANSI control characters for terminal formatting:
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php
help: ## Display this help.
@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)
##@ Binaries / Software
.PHONY: install-ctlptl
install-ctlptl: ## Installs CTLPTL (CLI for declaratively setting up local Kubernetes clusters)
MINIMUM_CTLPTL_VERSION=$(MINIMUM_CTLPTL_VERSION) ./hack/ensure-ctlptl.sh
.PHONY: install-helm
install-helm: ## Installs Helm (Kubernetes package manager)
MINIMUM_HELM_VERSION=$(MINIMUM_HELM_VERSION) ./hack/ensure-helm.sh
.PHONY: check-go
check-go: ## Checks go version
MINIMUM_GO_VERSION=$(MINIMUM_GO_VERSION) ./hack/ensure-go.sh
.PHONY: install-helmfile
install-helmfile: ## Installs Helmfile (Helmfile is like a helm for your helm)
MINIMUM_HELMFILE_VERSION=$(MINIMUM_HELMFILE_VERSION) ./hack/ensure-helmfile.sh
.PHONY: install-packer
install-packer: ## Installs Hashicorp Packer
MINIMUM_PACKER_VERSION=$(MINIMUM_PACKER_VERSION) ./hack/ensure-packer.sh
.PHONY: install-hcloud
install-hcloud: ## Installs hcloud (CLI for Hetzner)
MINIMUM_HCLOUD_VERSION=$(MINIMUM_HCLOUD_VERSION) ./hack/ensure-hcloud.sh
.PHONY: install-helm-plugins
install-helm-plugins: ## Installs Helm Plugins (helm-git)
HELM_GIT_VERSION=$(HELM_GIT_VERSION) HELM_DIFF_VERSION=$(HELM_DIFF_VERSION) ./hack/ensure-helm-plugins.sh
install-kind: ## Installs Kind (Kubernetes-in-Docker)
MINIMUM_KIND_VERSION=$(MINIMUM_KIND_VERSION) ./hack/ensure-kind.sh
.PHONY: install-kubectl
install-kubectl: ## Installs Kubectl (CLI for kubernetes)
MINIMUM_KUBECTL_VERSION=$(MINIMUM_KUBECTL_VERSION) ./hack/ensure-kubectl.sh
.PHONY: install-tilt
install-tilt: ## Installs Tilt (watches files, builds containers, ships to k8s)
MINIMUM_TILT_VERSION=$(MINIMUM_TILT_VERSION) ./hack/ensure-tilt.sh
.PHONY: install-clusterctl
install-clusterctl: ## Installs clusterctl
MINIMUM_CLUSTERCTL_VERSION=$(MINIMUM_CLUSTERCTL_VERSION) ./hack/ensure-clusterctl.sh
install-dev-prerequisites: ## Installs ctlptl, helm, helmfile, helm-plugins, kind, kubectl, tilt, clusterctl, packer, hcloud and checks installed go version
@echo "Start checking dependencies"
$(MAKE) install-ctlptl
$(MAKE) install-helm
$(MAKE) check-go
$(MAKE) install-helmfile
$(MAKE) install-helm-plugins
$(MAKE) install-kind
$(MAKE) install-kubectl
$(MAKE) install-tilt
$(MAKE) install-clusterctl
$(MAKE) install-packer
$(MAKE) install-hcloud
@echo "Finished: All dependencies up to date"
controller-gen: $(CONTROLLER_GEN) ## Build a local copy of controller-gen
$(CONTROLLER_GEN): $(TOOLS_DIR)/go.mod # Build controller-gen from tools folder.
cd $(TOOLS_DIR); go build -tags=tools -o $(BIN_DIR)/controller-gen sigs.k8s.io/controller-tools/cmd/controller-gen
conversion-gen: $(CONVERSION_GEN) ## Build a local copy of conversion-gen
$(CONVERSION_GEN): $(TOOLS_DIR)/go.mod # Build conversion-gen from tools folder.
cd $(TOOLS_DIR); go build -tags=tools -o $(BIN_DIR)/conversion-gen k8s.io/code-generator/cmd/conversion-gen
conversion-verifier: $(CONVERSION_VERIFIER) ## Build a local copy of conversion-verifier
$(CONVERSION_VERIFIER): $(TOOLS_DIR)/go.mod # Build conversion-verifier from tools folder.
cd $(TOOLS_DIR); go build -tags=tools -o $(BIN_DIR)/conversion-verifier sigs.k8s.io/cluster-api/hack/tools/conversion-verifier
go-apidiff: $(GO_APIDIFF) ## Build a local copy of apidiff
$(GO_APIDIFF): $(TOOLS_DIR)/go.mod # Build go-apidiff from tools folder.
cd $(TOOLS_DIR) && go build -tags=tools -o $(GO_APIDIFF_BIN) github.com/joelanford/go-apidiff
envsubst: $(ENVSUBST) ## Build a local copy of envsubst
$(ENVSUBST): $(TOOLS_DIR)/go.mod # Build envsubst from tools folder.
cd $(TOOLS_DIR) && go build -tags=tools -o $(ENVSUBST_BIN) github.com/drone/envsubst/v2/cmd/envsubst
kustomize: $(KUSTOMIZE) ## Build a local copy of kustomize
$(KUSTOMIZE): # Download kustomize using hack script into tools folder.
KUSTOMIZE_VERSION=$(KUSTOMIZE_VERSION) hack/ensure-kustomize.sh
golangci-lint: $(GOLANGCI_LINT) ## Build a local copy of golangci-lint
$(GOLANGCI_LINT): .github/workflows/pr-golangci-lint.yml # Download golanci-lint using hack script into tools folder.
hack/ensure-golangci-lint.sh \
-b $(TOOLS_DIR)/$(BIN_DIR) \
$(shell cat .github/workflows/pr-golangci-lint.yml | grep version | sed 's/.*version: //')
setup-envtest: $(SETUP_ENVTEST) ## Build a local copy of setup-envtest
$(SETUP_ENVTEST): $(TOOLS_DIR)/go.mod # Build setup-envtest from tools folder.
cd $(TOOLS_DIR); go build -tags=tools -o $(BIN_DIR)/setup-envtest sigs.k8s.io/controller-runtime/tools/setup-envtest
##@ Generate / Manifests
.PHONY: generate
generate: ## Run all generate-manifests, generate-go-deepcopyand generate-go-conversions targets
$(MAKE) generate-manifests generate-go-deepcopy
generate-manifests: $(CONTROLLER_GEN) ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) \
paths=./api/... \
paths=./controllers/... \
crd:crdVersions=v1 \
rbac:roleName=manager-role \
output:crd:dir=./config/crd/bases \
output:webhook:dir=./config/webhook \
webhook
generate-go-deepcopy: $(CONTROLLER_GEN) ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) \
object:headerFile="./hack/boilerplate/boilerplate.generatego.txt" \
paths="./api/..."
dry-run: generate
cd config/manager && $(KUSTOMIZE) edit set image controller=${CONTROLLER_IMG}:${TAG}
mkdir -p dry-run
$(KUSTOMIZE) build config/default > dry-run/manifests.yaml
.PHONY: ensure-boilerplate
ensure-boilerplate: ## Ensures that a boilerplate exists in each file by adding missing boilerplates
./hack/ensure-boilerplate.sh
cluster-templates: $(KUSTOMIZE)
$(KUSTOMIZE) build templates/cluster-templates/hcloud --load-restrictor LoadRestrictionsNone > templates/cluster-templates/cluster-template.yaml
$(KUSTOMIZE) build templates/cluster-templates/hcloud --load-restrictor LoadRestrictionsNone > templates/cluster-templates/cluster-template-hcloud.yaml
$(KUSTOMIZE) build templates/cluster-templates/hcloud-packer --load-restrictor LoadRestrictionsNone > templates/cluster-templates/cluster-template-hcloud-packer.yaml
$(KUSTOMIZE) build templates/cluster-templates/hcloud-talos-packer --load-restrictor LoadRestrictionsNone > templates/cluster-templates/cluster-template-hcloud-talos-packer.yaml
$(KUSTOMIZE) build templates/cluster-templates/hcloud-network --load-restrictor LoadRestrictionsNone > templates/cluster-templates/cluster-template-hcloud-network.yaml
$(KUSTOMIZE) build templates/cluster-templates/hcloud-network-packer --load-restrictor LoadRestrictionsNone > templates/cluster-templates/cluster-template-hcloud-network-packer.yaml
$(KUSTOMIZE) build templates/cluster-templates/hetzner-hcloud-control-planes --load-restrictor LoadRestrictionsNone > templates/cluster-templates/cluster-template-hetzner-hcloud-control-planes.yaml
$(KUSTOMIZE) build templates/cluster-templates/hetzner-baremetal-control-planes --load-restrictor LoadRestrictionsNone > templates/cluster-templates/cluster-template-hetzner-baremetal-control-planes.yaml
$(KUSTOMIZE) build templates/cluster-templates/hetzner-baremetal-control-planes-remediation --load-restrictor LoadRestrictionsNone > templates/cluster-templates/cluster-template-hetzner-baremetal-control-planes-remediation.yaml
##@ Lint and Verify
.PHONY: modules
modules: ## Runs go mod to ensure modules are up to date.
go mod tidy
cd $(TOOLS_DIR); go mod tidy
.PHONY: lint
lint: $(GOLANGCI_LINT) ## Lint Golang codebase
$(GOLANGCI_LINT) run -v $(GOLANGCI_LINT_EXTRA_ARGS)
.PHONY: lint-fix
lint-fix: $(GOLANGCI_LINT) ## Lint the Go codebase and run auto-fixers if supported by the linter.
GOLANGCI_LINT_EXTRA_ARGS=--fix $(MAKE) lint
.PHONY: format-tiltfile
format-tiltfile: ## Format the Tiltfile
./hack/verify-starlark.sh fix
yamllint: ## Lints YAML Files
yamllint -c .github/linters/yaml-lint.yaml --strict .
ALL_VERIFY_CHECKS = boilerplate shellcheck tiltfile modules gen
.PHONY: verify
verify: lint $(addprefix verify-,$(ALL_VERIFY_CHECKS)) ## Run all verify-* targets
@echo "All verify checks passed, congrats!"
.PHONY: verify-modules
verify-modules: modules ## Verify go modules are up to date
@if !(git diff --quiet HEAD -- go.sum go.mod $(TOOLS_DIR)/go.mod $(TOOLS_DIR)/go.sum $(TEST_DIR)/go.mod $(TEST_DIR)/go.sum); then \
git diff; \
echo "go module files are out of date"; exit 1; \
fi
@if (find . -name 'go.mod' | xargs -n1 grep -q -i 'k8s.io/client-go.*+incompatible'); then \
find . -name "go.mod" -exec grep -i 'k8s.io/client-go.*+incompatible' {} \; -print; \
echo "go module contains an incompatible client-go version"; exit 1; \
fi
.PHONY: verify-gen
verify-gen: generate ## Verfiy go generated files are up to date
@if !(git diff --quiet HEAD); then \
git diff; \
echo "generated files are out of date, run make generate"; exit 1; \
fi
.PHONY: verify-boilerplate
verify-boilerplate: ## Verify boilerplate text exists in each file
./hack/verify-boilerplate.sh
.PHONY: verify-shellcheck
verify-shellcheck: ## Verify shell files
./hack/verify-shellcheck.sh
.PHONY: verify-tiltfile
verify-tiltfile: ## Verify Tiltfile format
./hack/verify-starlark.sh
##@ Clean
.PHONY: clean
clean: ## Remove all generated files
$(MAKE) clean-bin
.PHONY: clean-bin
clean-bin: ## Remove all generated helper binaries
rm -rf $(BIN_DIR)
rm -rf $(TOOLS_BIN_DIR)
.PHONY: clean-release
clean-release: ## Remove the release folder
rm -rf $(RELEASE_DIR)
.PHONY: clean-docker-all
clean-docker-all: ## Erases all container and images
./hack/erase-docker-all.sh
.PHONY: clean-release-git
clean-release-git: ## Restores the git files usually modified during a release
git restore ./*manager_image_patch.yaml ./*manager_pull_policy.yaml
##@ Release
## latest git tag for the commit, e.g., v0.3.10
RELEASE_TAG ?= $(shell git describe --abbrev=0 2>/dev/null)
# the previous release tag, e.g., v0.3.9, excluding pre-release tags
PREVIOUS_TAG ?= $(shell git tag -l | grep -E "^v[0-9]+\.[0-9]+\.[0-9]." | sort -V | grep -B1 $(RELEASE_TAG) | head -n 1 2>/dev/null)
RELEASE_DIR ?= out
RELEASE_NOTES_DIR := _releasenotes
$(RELEASE_DIR):
mkdir -p $(RELEASE_DIR)/
$(RELEASE_NOTES_DIR):
mkdir -p $(RELEASE_NOTES_DIR)/
.PHONY: test-release
test-release:
$(MAKE) set-manifest-image MANIFEST_IMG=$(REGISTRY)/$(IMAGE_NAME) MANIFEST_TAG=$(TAG)
$(MAKE) set-manifest-pull-policy PULL_POLICY=IfNotPresent
$(MAKE) release-manifests
.PHONY: release
release: clean-release ## Builds and push container images using the latest git tag for the commit.
@if [ -z "${RELEASE_TAG}" ]; then echo "RELEASE_TAG is not set"; exit 1; fi
@if ! [ -z "$$(git status --porcelain)" ]; then echo "Your local git repository contains uncommitted changes, use git clean before proceeding."; exit 1; fi
git checkout "${RELEASE_TAG}"
# Set the manifest image to the production bucket.
$(MAKE) set-manifest-image MANIFEST_IMG=$(PROD_REGISTRY)/$(IMAGE_NAME) MANIFEST_TAG=$(RELEASE_TAG)
$(MAKE) set-manifest-pull-policy PULL_POLICY=IfNotPresent
## Build the manifests
$(MAKE) release-manifests clean-release-git
.PHONY: release-manifests
release-manifests: generate $(KUSTOMIZE) $(RELEASE_DIR) cluster-templates ## Builds the manifests to publish with a release
$(KUSTOMIZE) build config/default > $(RELEASE_DIR)/infrastructure-components.yaml
## Build caph-components (aggregate of all of the above).
cp metadata.yaml $(RELEASE_DIR)/metadata.yaml
cp templates/cluster-templates/cluster-template* $(RELEASE_DIR)/
.PHONY: release-notes
release-notes: $(RELEASE_NOTES_DIR) $(RELEASE_NOTES)
go run ./hack/tools/release/notes.go --from=$(PREVIOUS_TAG) > $(RELEASE_NOTES_DIR)/$(RELEASE_TAG).md
.PHONY: release-nightly
release-nightly: ## Builds and push container images to the prod bucket.
$(MAKE) CONTROLLER_IMG=$(PROD_REGISTRY)/$(IMAGE_NAME) TAG=latest docker-multiarch
.PHONY: release-image
release-image: ## Builds and push container images to the prod bucket.
$(MAKE) CONTROLLER_IMG=$(PROD_REGISTRY)/$(IMAGE_NAME) TAG=$(RELEASE_TAG) docker-multiarch
##@ Test
ARTIFACTS ?= _artifacts
$(ARTIFACTS):
mkdir -p $(ARTIFACTS)/
KUBEBUILDER_ASSETS ?= $(shell $(SETUP_ENVTEST) use --use-env -p path $(KUBEBUILDER_ENVTEST_KUBERNETES_VERSION))
REPO_ROOT := $(shell git rev-parse --show-toplevel)
E2E_DIR ?= $(REPO_ROOT)/test/e2e
E2E_CONF_FILE_SOURCE ?= $(E2E_DIR)/config/hetzner.yaml
E2E_CONF_FILE ?= $(E2E_DIR)/config/hetzner-ci-envsubst.yaml
.PHONY: e2e-image
e2e-image: ## Build the e2e manager image
docker build --pull --build-arg ARCH=$(ARCH) --build-arg LDFLAGS="$(LDFLAGS)" . -t $(CONTROLLER_IMG):e2e
.PHONY: $(E2E_CONF_FILE)
e2e-conf-file: $(E2E_CONF_FILE)
$(E2E_CONF_FILE): $(ENVSUBST) $(E2E_CONF_FILE_SOURCE)
mkdir -p $(shell dirname $(E2E_CONF_FILE))
$(ENVSUBST) < $(E2E_CONF_FILE_SOURCE) > $(E2E_CONF_FILE)
.PHONY: test-e2e
test-e2e: $(E2E_CONF_FILE) $(if $(SKIP_IMAGE_BUILD),,e2e-image) $(ARTIFACTS)
GINKO_FOKUS="'\[Basic\]'" GINKO_NODES=2 ./hack/ci-e2e-capi.sh
.PHONY: test-e2e-feature
test-e2e-feature: $(E2E_CONF_FILE) $(if $(SKIP_IMAGE_BUILD),,e2e-image) $(ARTIFACTS)
GINKO_FOKUS="'\[Feature\]'" GINKO_NODES=3 ./hack/ci-e2e-capi.sh
.PHONY: test-e2e-feature-packer
test-e2e-feature-packer: $(if $(SKIP_IMAGE_BUILD),,e2e-image) $(ARTIFACTS)
GINKO_FOKUS="'\[Feature Packer\]'" GINKO_NODES=1 PACKER_IMAGE_NAME=templates/node-image/1.24.1-ubuntu-20-04-containerd ./hack/ci-e2e-capi.sh
.PHONY: test-e2e-feature-talos
test-e2e-feature-talos: $(if $(SKIP_IMAGE_BUILD),,e2e-image) $(ARTIFACTS)
GINKO_FOKUS="'\[Feature Talos\]'" GINKO_NODES=1 PACKER_TALOS=templates/node-image/talos-image ./hack/ci-e2e-capi.sh
.PHONY: test-e2e-lifecycle
test-e2e-lifecycle: $(E2E_CONF_FILE) $(if $(SKIP_IMAGE_BUILD),,e2e-image) $(ARTIFACTS)
GINKO_FOKUS="'\[Lifecycle\]'" GINKO_NODES=3 ./hack/ci-e2e-capi.sh
.PHONY: test-e2e-upgrade-caph
test-e2e-upgrade-caph: $(E2E_CONF_FILE) $(if $(SKIP_IMAGE_BUILD),,e2e-image) $(ARTIFACTS)
GINKO_FOKUS="'\[Upgrade CAPH\]'" GINKO_NODES=1 ./hack/ci-e2e-capi.sh
.PHONY: test-e2e-upgrade-kubernetes
test-e2e-upgrade-kubernetes: $(if $(SKIP_IMAGE_BUILD),,e2e-image) $(ARTIFACTS)
GINKO_FOKUS="'\[Upgrade Kubernetes\]'" GINKO_NODES=2 PACKER_KUBERNETES_UPGRADE_FROM=templates/node-image/1.23.6-ubuntu-20-04-containerd PACKER_KUBERNETES_UPGRADE_TO=templates/node-image/1.24.1-ubuntu-20-04-containerd ./hack/ci-e2e-capi.sh
.PHONY: test-e2e-conformance
test-e2e-conformance: $(E2E_CONF_FILE) $(if $(SKIP_IMAGE_BUILD),,e2e-image) $(ARTIFACTS)
GINKO_FOKUS="'\[Conformance\]'" GINKO_NODES=1 ./hack/ci-e2e-capi.sh
.PHONY: test
test: $(SETUP_ENVTEST) ## Run unit and integration tests
KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" go test ./controllers/... ./pkg/... $(TEST_ARGS)
.PHONY: test-verbose
test-verbose: ## Run tests with verbose settings
$(MAKE) test TEST_ARGS="$(TEST_ARGS) -v"
.PHONY: test-cover
test-cover: $(RELEASE_DIR) ## Run tests with code coverage and code generate reports
$(MAKE) test TEST_ARGS="$(TEST_ARGS) -coverprofile=out/coverage.out -covermode=atomic"
go tool cover -func=out/coverage.out -o $(RELEASE_DIR)/coverage.txt
go tool cover -html=out/coverage.out -o $(RELEASE_DIR)/coverage.html
.PHONY: test-junit
test-junit: $(SETUP_ENVTEST) $(GOTESTSUM) ## Run tests with verbose setting and generate a junit report
set +o errexit; (KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" go test -json ./... $(TEST_ARGS); echo $$? > $(ARTIFACTS)/junit.exitcode) | tee $(ARTIFACTS)/junit.stdout
$(GOTESTSUM) --junitfile $(ARTIFACTS)/junit.xml --raw-command cat $(ARTIFACTS)/junit.stdout
exit $$(cat $(ARTIFACTS)/junit.exitcode)
##@ Build
build: generate fmt vet ## Build manager binary.
go build -o bin/manager main.go
run: generate fmt vet ## Run a controller from your host.
go run ./main.go
## --------------------------------------
## Docker
## --------------------------------------
# Create multi-platform docker image. If you have native systems around, using
# them will be much more efficient at build time. See e.g.
BUILDXDETECT = ${HOME}/.docker/cli-plugins/docker-buildx
# Just one of the many files created
QEMUDETECT = /proc/sys/fs/binfmt_misc/qemu-m68k
docker-multiarch: qemu buildx docker-multiarch-builder
docker buildx build --builder docker-multiarch --pull --push \
--platform ${PLATFORMS} \
-t $(CONTROLLER_IMG):$(TAG) .
.PHONY: qemu buildx docker-multiarch-builder
qemu: ${QEMUDETECT}
${QEMUDETECT}:
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
buildx: ${BUILDXDETECT}
${BUILDXDETECT}:
@echo
# Output of `uname -m` is too different
@echo "*** 'docker buildx' missing. Install binary for this machine's architecture"
@echo "*** from https://github.com/docker/buildx/releases/latest"
@echo "*** to ~/.docker/cli-plugins/docker-buildx"
@echo
@exit 1
docker-multiarch-builder: qemu buildx
if ! docker buildx ls | grep -w docker-multiarch > /dev/null; then \
docker buildx create --name docker-multiarch && \
docker buildx inspect --builder docker-multiarch --bootstrap; \
fi
.PHONY: set-manifest-image
set-manifest-image:
$(info Updating kustomize image patch file for default resource)
sed -i'' -e 's@image: .*@image: '"${MANIFEST_IMG}:$(MANIFEST_TAG)"'@' ./config/default/manager_image_patch.yaml
.PHONY: set-manifest-pull-policy
set-manifest-pull-policy:
$(info Updating kustomize pull policy file for default resource)
sed -i'' -e 's@imagePullPolicy: .*@imagePullPolicy: '"$(PULL_POLICY)"'@' ./config/default/manager_pull_policy.yaml
##@ Development
fmt: ## Run go fmt against code.
go fmt ./...
vet: ## Run go vet against code.
go vet ./...
install-crds: generate-manifests $(KUSTOMIZE) ## Install CRDs into the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | kubectl apply -f -
uninstall-crds: generate-manifests $(KUSTOMIZE) ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | kubectl delete -f -
deploy-controller: generate-manifests $(KUSTOMIZE) ## Deploy controller to the K8s cluster specified in ~/.kube/config.
cd config/manager && $(KUSTOMIZE) edit set image controller=${CONTROLLER_IMG}:${TAG}
$(KUSTOMIZE) build config/default | kubectl apply -f -
undeploy-controller: ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/default | kubectl delete -f -
.PHONY: tilt-up
tilt-up: $(ENVSUBST) $(KUSTOMIZE) cluster ## Start a mgt-cluster & Tilt. Installs the CRDs and deploys the controllers
EXP_CLUSTER_RESOURCE_SET=true tilt up
install-essentials: ## This gets the secret and installs a CNI and the CCM. Usage: MAKE install-essentials NAME=<cluster-name>
export CAPH_WORKER_CLUSTER_KUBECONFIG=/tmp/workload-kubeconfig
$(MAKE) wait-and-get-secret CLUSTER_NAME=$(NAME)
$(MAKE) install-manifests-cilium
$(MAKE) install-manifests-ccm-hetzner
wait-and-get-secret:
# Wait for the kubeconfig to become available.
${TIMEOUT} 5m bash -c "while ! kubectl get secrets | grep $(CLUSTER_NAME)-kubeconfig; do sleep 1; done"
# Get kubeconfig and store it locally.
kubectl get secrets $(CLUSTER_NAME)-kubeconfig -o json | jq -r .data.value | base64 --decode > $(CAPH_WORKER_CLUSTER_KUBECONFIG)
${TIMEOUT} 15m bash -c "while ! kubectl --kubeconfig=$(CAPH_WORKER_CLUSTER_KUBECONFIG) get nodes | grep control-plane; do sleep 1; done"
install-manifests-cilium:
# Deploy cilium
helm repo add cilium https://helm.cilium.io/
helm repo update cilium
KUBECONFIG=$(CAPH_WORKER_CLUSTER_KUBECONFIG) helm upgrade --install cilium cilium/cilium --version 1.11.5 \
--namespace kube-system \
-f templates/cilium/cilium.yaml
install-manifests-ccm-hetzner:
# Deploy Hetzner Cloud Controller Manager
helm repo add syself https://charts.syself.com
helm repo update syself
KUBECONFIG=$(CAPH_WORKER_CLUSTER_KUBECONFIG) helm upgrade --install ccm syself/ccm-hetzner --version 1.1.2 \
--namespace kube-system \
--set image.tag=latest \
--set privateNetwork.enabled=$(PRIVATE_NETWORK)
@echo 'run "kubectl --kubeconfig=$(CAPH_WORKER_CLUSTER_KUBECONFIG) ..." to work with the new target cluster'
install-manifests-ccm-hcloud:
# Deploy Hcloud Cloud Controller Manager
helm repo add syself https://charts.syself.com
helm repo update syself
KUBECONFIG=$(CAPH_WORKER_CLUSTER_KUBECONFIG) helm upgrade --install ccm syself/ccm-hcloud --version 1.0.10 \
--namespace kube-system \
--set secret.name=hetzner \
--set secret.tokenKeyName=hcloud \
--set privateNetwork.enabled=$(PRIVATE_NETWORK)
@echo 'run "kubectl --kubeconfig=$(CAPH_WORKER_CLUSTER_KUBECONFIG) ..." to work with the new target cluster'
create-workload-cluster-hcloud: $(KUSTOMIZE) $(ENVSUBST) ## Creates a workload-cluster. ENV Variables need to be exported or defined in the tilt-settings.json
# Create workload Cluster.
kubectl create secret generic hetzner --from-literal=hcloud=$(HCLOUD_TOKEN) --save-config --dry-run=client -o yaml | kubectl apply -f -
$(KUSTOMIZE) build templates/cluster-templates/hcloud --load-restrictor LoadRestrictionsNone > templates/cluster-templates/cluster-template-hcloud.yaml
cat templates/cluster-templates/cluster-template-hcloud.yaml | $(ENVSUBST) - | kubectl apply -f -
$(MAKE) wait-and-get-secret
$(MAKE) install-manifests-cilium
$(MAKE) install-manifests-ccm-hcloud PRIVATE_NETWORK=false
create-workload-cluster-hcloud-packer: $(KUSTOMIZE) $(ENVSUBST) ## Creates a workload-cluster. ENV Variables need to be exported or defined in the tilt-settings.json
# Create workload Cluster.
kubectl create secret generic hetzner --from-literal=hcloud=$(HCLOUD_TOKEN) --save-config --dry-run=client -o yaml | kubectl apply -f -
$(KUSTOMIZE) build templates/cluster-templates/hcloud-packer --load-restrictor LoadRestrictionsNone > templates/cluster-templates/cluster-template-hcloud-packer.yaml
cat templates/cluster-templates/cluster-template-hcloud-packer.yaml | $(ENVSUBST) - | kubectl apply -f -
$(MAKE) wait-and-get-secret
$(MAKE) install-manifests-cilium
$(MAKE) install-manifests-ccm-hcloud PRIVATE_NETWORK=false
create-workload-cluster-hcloud-talos-packer: $(KUSTOMIZE) $(ENVSUBST) ## Creates a workload-cluster. ENV Variables need to be exported or defined in the tilt-settings.json
# Create workload Cluster.
kubectl create secret generic hetzner --from-literal=hcloud=$(HCLOUD_TOKEN) --save-config --dry-run=client -o yaml | kubectl apply -f -
$(KUSTOMIZE) build templates/cluster-templates/hcloud-talos-packer --load-restrictor LoadRestrictionsNone > templates/cluster-templates/cluster-template-hcloud-talos-packer.yaml
cat templates/cluster-templates/cluster-template-hcloud-talos-packer.yaml | $(ENVSUBST) - | kubectl apply -f -
$(MAKE) wait-and-get-secret
$(MAKE) install-manifests-cilium
$(MAKE) install-manifests-ccm-hcloud PRIVATE_NETWORK=false
create-workload-cluster-hcloud-network: $(KUSTOMIZE) $(ENVSUBST) ## Creates a workload-cluster. ENV Variables need to be exported or defined in the tilt-settings.json
# Create workload Cluster.
kubectl create secret generic hetzner --from-literal=hcloud=$(HCLOUD_TOKEN) --save-config --dry-run=client -o yaml | kubectl apply -f -
$(KUSTOMIZE) build templates/cluster-templates/hcloud-network --load-restrictor LoadRestrictionsNone > templates/cluster-templates/cluster-template-hcloud-network.yaml
cat templates/cluster-templates/cluster-template-hcloud-network.yaml | $(ENVSUBST) - | kubectl apply -f -
$(MAKE) wait-and-get-secret
$(MAKE) install-manifests-cilium
$(MAKE) install-manifests-ccm-hcloud PRIVATE_NETWORK=true
create-workload-cluster-hcloud-network-packer: $(KUSTOMIZE) $(ENVSUBST) ## Creates a workload-cluster. ENV Variables need to be exported or defined in the tilt-settings.json
# Create workload Cluster.
kubectl create secret generic hetzner --from-literal=hcloud=$(HCLOUD_TOKEN) --save-config --dry-run=client -o yaml | kubectl apply -f -
$(KUSTOMIZE) build templates/cluster-templates/hcloud-network-packer --load-restrictor LoadRestrictionsNone > templates/cluster-templates/cluster-template-hcloud-network-packer.yaml
cat templates/cluster-templates/cluster-template-hcloud-network-packer.yaml | $(ENVSUBST) - | kubectl apply -f -
$(MAKE) wait-and-get-secret
$(MAKE) install-manifests-cilium
$(MAKE) install-manifests-ccm-hcloud PRIVATE_NETWORK=true
create-workload-cluster-hetzner-hcloud-control-plane: $(KUSTOMIZE) $(ENVSUBST) ## Creates a workload-cluster. ENV Variables need to be exported or defined in the tilt-settings.json
# Create workload Cluster.
kubectl create secret generic hetzner --from-literal=hcloud=$(HCLOUD_TOKEN) --from-literal=robot-user=$(HETZNER_ROBOT_USER) --from-literal=robot-password=$(HETZNER_ROBOT_PASSWORD) --save-config --dry-run=client -o yaml | kubectl apply -f -
kubectl create secret generic robot-ssh --from-literal=sshkey-name=cluster --from-file=ssh-privatekey=${HETZNER_SSH_PRIV_PATH} --from-file=ssh-publickey=${HETZNER_SSH_PUB_PATH} --save-config --dry-run=client -o yaml | kubectl apply -f -
$(KUSTOMIZE) build templates/cluster-templates/hetzner-hcloud-control-planes --load-restrictor LoadRestrictionsNone > templates/cluster-templates/cluster-template-hetzner-hcloud-control-planes.yaml
cat templates/cluster-templates/cluster-template-hetzner-hcloud-control-planes.yaml | $(ENVSUBST) - | kubectl apply -f -
$(MAKE) wait-and-get-secret
$(MAKE) install-manifests-cilium
$(MAKE) install-manifests-ccm-hetzner PRIVATE_NETWORK=false
create-workload-cluster-hetzner-baremetal-control-plane: $(KUSTOMIZE) $(ENVSUBST) ## Creates a workload-cluster. ENV Variables need to be exported or defined in the tilt-settings.json
# Create workload Cluster.
kubectl create secret generic hetzner --from-literal=hcloud=$(HCLOUD_TOKEN) --from-literal=robot-user=$(HETZNER_ROBOT_USER) --from-literal=robot-password=$(HETZNER_ROBOT_PASSWORD) --save-config --dry-run=client -o yaml | kubectl apply -f -
kubectl create secret generic robot-ssh --from-literal=sshkey-name=cluster --from-file=ssh-privatekey=${HETZNER_SSH_PRIV_PATH} --from-file=ssh-publickey=${HETZNER_SSH_PUB_PATH} --save-config --dry-run=client -o yaml | kubectl apply -f -
$(KUSTOMIZE) build templates/cluster-templates/hetzner-baremetal-control-planes --load-restrictor LoadRestrictionsNone > templates/cluster-templates/cluster-template-hetzner-baremetal-control-planes.yaml
cat templates/cluster-templates/cluster-template-hetzner-baremetal-control-planes.yaml | $(ENVSUBST) - | kubectl apply -f -
$(MAKE) wait-and-get-secret
$(MAKE) install-manifests-cilium
$(MAKE) install-manifests-ccm-hetzner PRIVATE_NETWORK=false
create-workload-cluster-hetzner-baremetal-control-plane-remediation: $(KUSTOMIZE) $(ENVSUBST) ## Creates a workload-cluster. ENV Variables need to be exported or defined in the tilt-settings.json
# Create workload Cluster.
kubectl create secret generic hetzner --from-literal=hcloud=$(HCLOUD_TOKEN) --from-literal=robot-user=$(HETZNER_ROBOT_USER) --from-literal=robot-password=$(HETZNER_ROBOT_PASSWORD) --save-config --dry-run=client -o yaml | kubectl apply -f -
kubectl create secret generic robot-ssh --from-literal=sshkey-name=cluster --from-file=ssh-privatekey=${HETZNER_SSH_PRIV_PATH} --from-file=ssh-publickey=${HETZNER_SSH_PUB_PATH} --save-config --dry-run=client -o yaml | kubectl apply -f -
$(KUSTOMIZE) build templates/cluster-templates/hetzner-baremetal-control-planes-remediation --load-restrictor LoadRestrictionsNone > templates/cluster-templates/cluster-template-hetzner-baremetal-control-planes-remediation.yaml
cat templates/cluster-templates/cluster-template-hetzner-baremetal-control-planes-remediation.yaml | $(ENVSUBST) - | kubectl apply -f -
$(MAKE) wait-and-get-secret
$(MAKE) install-manifests-cilium
$(MAKE) install-manifests-ccm-hetzner PRIVATE_NETWORK=false
move-to-workload-cluster:
clusterctl init --kubeconfig=$(CAPH_WORKER_CLUSTER_KUBECONFIG) --core cluster-api --bootstrap kubeadm --control-plane kubeadm --infrastructure hetzner
kubectl --kubeconfig=$(CAPH_WORKER_CLUSTER_KUBECONFIG) -n cluster-api-provider-hetzner-system wait deploy/caph-controller-manager --for condition=available && sleep 15s
clusterctl move --to-kubeconfig=$(CAPH_WORKER_CLUSTER_KUBECONFIG)
.PHONY: delete-workload-cluster
delete-workload-cluster: ## Deletes the example workload Kubernetes cluster
@echo 'Your Hetzner resources will now be deleted, this can take up to 20 minutes'
kubectl patch cluster $(CLUSTER_NAME) --type=merge -p '{"spec":{"paused": "false"}}' || true
kubectl delete cluster $(CLUSTER_NAME)
${TIMEOUT} 15m bash -c "while kubectl get cluster | grep $(NAME); do sleep 1; done"
@echo 'Cluster deleted'
##@ Management Cluster
create-mgt-cluster: cluster ## Start a mgt-cluster with the latest version of all capi components and the hetzner provider. Usage: MAKE create-mgt-cluster HCLOUD=<hcloud-token>
clusterctl init --core cluster-api --bootstrap kubeadm --control-plane kubeadm --infrastructure hetzner
kubectl create secret generic hetzner --from-literal=hcloud=$(HCLOUD_TOKEN)
kubectl patch secret hetzner -p '{"metadata":{"labels":{"clusterctl.cluster.x-k8s.io/move":""}}}'
.PHONY: cluster
cluster: ## Creates kind-dev Cluster
./hack/kind-dev.sh
.PHONY: delete-cluster
delete-cluster: ## Deletes Kind-dev Cluster (default)
ctlptl delete cluster kind-caph
.PHONY: delete-registry
delete-registry: ## Deletes Kind-dev Cluster and the local registry
ctlptl delete registry caph-registry
.PHONY: delete-cluster-registry
delete-cluster-registry: ## Deletes Kind-dev Cluster and the local registry
ctlptl delete cluster kind-caph
ctlptl delete registry caph-registry