-
Notifications
You must be signed in to change notification settings - Fork 28
/
Makefile
163 lines (133 loc) · 5.45 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
REGISTRY ?= ghcr.io
USERNAME ?= siderolabs
SHA ?= $(shell git describe --match=none --always --abbrev=8 --dirty)
TAG ?= $(shell git describe --tag --always --dirty)
BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
REGISTRY_AND_USERNAME := $(REGISTRY)/$(USERNAME)
NAME := cluster-api-talos-controller
ARTIFACTS := _out
TEST_RUN ?= ./...
TOOLS ?= ghcr.io/siderolabs/tools:v1.8.0-1-ga0c06c6
PKGS ?= v1.8.0
TALOS_VERSION ?= v1.8.0
K8S_VERSION ?= 1.30.1
CONTROLLER_GEN_VERSION ?= v0.16.2
CONVERSION_GEN_VERSION ?= v0.31.0
BUILD := docker buildx build
PLATFORM ?= linux/amd64
PROGRESS ?= auto
PUSH ?= false
COMMON_ARGS := --file=Dockerfile
COMMON_ARGS += --progress=$(PROGRESS)
COMMON_ARGS += --platform=$(PLATFORM)
COMMON_ARGS += --build-arg=REGISTRY_AND_USERNAME=$(REGISTRY_AND_USERNAME)
COMMON_ARGS += --build-arg=NAME=$(NAME)
COMMON_ARGS += --build-arg=TAG=$(TAG)
COMMON_ARGS += --build-arg=PKGS=$(PKGS)
COMMON_ARGS += --build-arg=TOOLS=$(TOOLS)
COMMON_ARGS += --build-arg=CONTROLLER_GEN_VERSION=$(CONTROLLER_GEN_VERSION)
COMMON_ARGS += --build-arg=CONVERSION_GEN_VERSION=$(CONVERSION_GEN_VERSION)
COMMON_ARGS += --build-arg=TALOS_VERSION=$(TALOS_VERSION)
COMMON_ARGS += --build-arg=ARTIFACTS=$(ARTIFACTS)
all: manifests container
.PHONY: help
help: ## This help menu.
@grep -E '^[a-zA-Z%_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
target-%: ## Builds the specified target defined in the Dockerfile. The build result will remain only in the build cache.
@$(BUILD) \
--target=$* \
$(COMMON_ARGS) \
$(TARGET_ARGS) .
local-%: ## Builds the specified target defined in the Dockerfile using the local output type. The build result will be output to the specified local destination.
@$(MAKE) target-$* TARGET_ARGS="--output=type=local,dest=$(DEST) $(TARGET_ARGS)"
docker-%: ## Builds the specified target defined in the Dockerfile using the docker output type. The build result will be loaded into docker.
@$(MAKE) target-$* TARGET_ARGS="--tag $(REGISTRY_AND_USERNAME)/$(NAME):$(TAG) $(TARGET_ARGS)"
define RELEASEYAML
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: $(NAMESPACE)
commonLabels:
app: $(NAME)
bases:
- crd
- rbac
- manager
endef
export RELEASEYAML
.PHONY: init
init: ## Initialize the project.
@mkdir tmp \
&& cd tmp \
&& kubebuilder init --repo $(REGISTRY_AND_USERNAME)/$(NAME) --domain $(DOMAIN) \
&& rm -rf Dockerfile Makefile .gitignore bin hack \
&& mv ./* ../ \
&& cd .. \
&& rm -rf tmp \
&& echo "$$RELEASEYAML" > ./config/kustomization.yaml
.PHONY: generate
generate: ## Generate source code.
@$(MAKE) local-$@ DEST=./ PLATFORM=linux/amd64
.PHONY: container
container: generate ## Build the container image.
@$(MAKE) docker-$@ TARGET_ARGS="--push=$(PUSH)"
.PHONY: manifests
manifests: ## Generate manifests (e.g. CRD, RBAC, etc.).
@$(MAKE) local-$@ DEST=./ PLATFORM=linux/amd64
.PHONY: release-notes
release-notes: ## Create the release notes.
@mkdir -p $(ARTIFACTS)
ARTIFACTS=$(ARTIFACTS) ./hack/release.sh $@ $(ARTIFACTS)/RELEASE_NOTES.md $(TAG)
.PHONY: release-manifests
release-manifests:
@$(MAKE) local-$@ DEST=./$(ARTIFACTS) PLATFORM=linux/amd64
.PHONY: release
release: manifests container release-notes release-manifests ## Create the release YAML. The build result will be ouput to the specified local destination.
.PHONY: deploy
deploy: manifests ## Deploy to a cluster. This is for testing purposes only.
kubectl apply -k config/default
.PHONY: destroy
destroy: ## Remove from a cluster. This is for testing purposes only.
kubectl delete -k config/default
.PHONY: install
install: manifests ## Install CRDs into a cluster.
kubectl apply -k config/crd
.PHONY: uninstall
uninstall: manifests ## Uninstall CRDs from a cluster.
kubectl delete -k config/crd
.PHONY: run
run: install ## Run the controller locally. This is for testing purposes only.
@$(MAKE) docker-container TARGET_ARGS="--load"
@docker run --rm -it --net host -v $(PWD):/src -v $(KUBECONFIG):/root/.kube/config -e KUBECONFIG=/root/.kube/config $(REGISTRY_AND_USERNAME)/$(NAME):$(TAG)
.PHONY: clean
clean:
@rm -rf $(ARTIFACTS)
check-dirty: ## Verifies that source tree is not dirty
@if test -n "`git status --porcelain`"; then echo "Source tree is dirty"; git status; exit 1 ; fi
conformance: ## Performs policy checks against the commit and source code.
docker run --rm -it -v $(PWD):/src -w /src ghcr.io/siderolabs/conform:latest enforce
# Make `make test` behave just like `go test` regarding relative paths.
test: ## Run tests.
@$(MAKE) local-integration-test DEST=./internal/integration PLATFORM=linux/amd64
cd internal/integration && KUBECONFIG=../../kubeconfig ./integration.test -test.v -test.coverprofile=../../coverage.txt -test.run $(TEST_RUN)
coverage: ## Upload coverage data to codecov.io.
/usr/local/bin/codecov -f coverage.txt -X fix
talosctl:
curl -Lo talosctl https://github.com/siderolabs/talos/releases/download/$(TALOS_VERSION)/talosctl-$(shell uname -s | tr "[:upper:]" "[:lower:]")-amd64
chmod +x ./talosctl
env-up: talosctl ## Start development environment.
./talosctl cluster create \
--talosconfig=talosconfig \
--name=cabpt-env \
--kubernetes-version=$(K8S_VERSION) \
--mtu=1450 \
--skip-kubeconfig \
--crashdump
./talosctl kubeconfig kubeconfig \
--talosconfig=talosconfig \
--nodes=10.5.0.2 \
--force
env-down: talosctl ## Stop development environment.
./talosctl cluster destroy \
--talosconfig=talosconfig \
--name=cabpt-env
rm -f talosconfig kubeconfig