@@ -34,18 +34,22 @@ export GO111MODULE=on
3434ROOT_DIR: =$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST ) ) ) )
3535TOOLS_DIR := hack/tools
3636TOOLS_BIN_DIR := $(TOOLS_DIR ) /bin
37+ TEMPLATES_DIR := $(ROOT_DIR ) /templates
3738BIN_DIR := bin
39+ RELEASE_NOTES_BIN := bin/release-notes
3840
3941# Binaries.
4042CLUSTERCTL := $(BIN_DIR ) /clusterctl
4143CONTROLLER_GEN := $(TOOLS_BIN_DIR ) /controller-gen
44+ CONVERSION_GEN := $(TOOLS_BIN_DIR ) /conversion-gen
4245ENVSUBST := $(TOOLS_BIN_DIR ) /envsubst
46+ ETCD =$(TOOLS_BIN_DIR ) /etcd
4347GOLANGCI_LINT := $(TOOLS_BIN_DIR ) /golangci-lint
44- MOCKGEN := $(TOOLS_BIN_DIR ) /mockgen
45- CONVERSION_GEN := $(TOOLS_BIN_DIR ) /conversion-gen
46- KUBECTL =$(TOOLS_BIN_DIR ) /kubectl
4748KUBE_APISERVER =$(TOOLS_BIN_DIR ) /kube-apiserver
48- ETCD =$(TOOLS_BIN_DIR ) /etcd
49+ KUBECTL =$(TOOLS_BIN_DIR ) /kubectl
50+ KUSTOMIZE := $(abspath $(TOOLS_BIN_DIR ) /kustomize)
51+ MOCKGEN := $(TOOLS_BIN_DIR ) /mockgen
52+ RELEASE_NOTES := $(TOOLS_DIR ) /$(RELEASE_NOTES_BIN )
4953
5054# Define Docker related variables. Releases should modify and double check these vars.
5155REGISTRY ?= gcr.io/$(shell gcloud config get-value project)
@@ -66,6 +70,8 @@ RBAC_ROOT ?= $(MANIFEST_ROOT)/rbac
6670# Allow overriding the imagePullPolicy
6771PULL_POLICY ?= Always
6872
73+ CLUSTER_TEMPLATE ?= cluster-template.yaml
74+
6975# # --------------------------------------
7076# # Help
7177# # --------------------------------------
@@ -120,18 +126,21 @@ $(CLUSTERCTL): go.mod ## Build clusterctl binary.
120126$(CONTROLLER_GEN ) : $(TOOLS_DIR ) /go.mod # Build controller-gen from tools folder.
121127 cd $(TOOLS_DIR ) ; go build -tags=tools -o $(BIN_DIR ) /controller-gen sigs.k8s.io/controller-tools/cmd/controller-gen
122128
129+ $(CONVERSION_GEN ) : $(TOOLS_DIR ) /go.mod
130+ cd $(TOOLS_DIR ) ; go build -tags=tools -o $(BIN_DIR ) /conversion-gen k8s.io/code-generator/cmd/conversion-gen
131+
123132$(ENVSUBST ) : $(TOOLS_DIR ) /go.mod # Build envsubst from tools folder.
124133 cd $(TOOLS_DIR ) ; go build -tags=tools -o $(BIN_DIR ) /envsubst github.com/a8m/envsubst/cmd/envsubst
125134
126135$(GOLANGCI_LINT ) : $(TOOLS_DIR ) /go.mod # Build golangci-lint from tools folder.
127136 cd $(TOOLS_DIR ) ; go build -tags=tools -o $(BIN_DIR ) /golangci-lint github.com/golangci/golangci-lint/cmd/golangci-lint
128137
138+ $(KUSTOMIZE ) : $(TOOLS_DIR ) /go.mod # Build kustomize from tools folder.
139+ cd $(TOOLS_DIR ) ; go build -tags=tools -o $(BIN_DIR ) /kustomize sigs.k8s.io/kustomize/kustomize/v3
140+
129141$(MOCKGEN ) : $(TOOLS_DIR ) /go.mod # Build mockgen from tools folder.
130142 cd $(TOOLS_DIR ) ; go build -tags=tools -o $(BIN_DIR ) /mockgen github.com/golang/mock/mockgen
131143
132- $(CONVERSION_GEN ) : $(TOOLS_DIR ) /go.mod
133- cd $(TOOLS_DIR ) ; go build -tags=tools -o $(BIN_DIR ) /conversion-gen k8s.io/code-generator/cmd/conversion-gen
134-
135144$(RELEASE_NOTES ) : $(TOOLS_DIR ) /go.mod
136145 cd $(TOOLS_DIR ) && go build -tags tools -o $(BIN_DIR ) /release-notes sigs.k8s.io/cluster-api/hack/tools/release
137146
@@ -159,6 +168,7 @@ modules: ## Runs go mod to ensure proper vendoring.
159168generate : # # Generate code
160169 $(MAKE ) generate-go
161170 $(MAKE ) generate-manifests
171+ $(MAKE ) generate-flavors
162172
163173.PHONY : generate-go
164174generate-go : $(CONTROLLER_GEN ) $(MOCKGEN ) $(CONVERSION_GEN ) # # Runs Go related generate targets
@@ -185,6 +195,10 @@ generate-manifests: $(CONTROLLER_GEN) ## Generate manifests e.g. CRD, RBAC etc.
185195 output:rbac:dir=$(RBAC_ROOT ) \
186196 rbac:roleName=manager-role
187197
198+ .PHONY : generate-flavors # # Generate template flavors
199+ generate-flavors : $(KUSTOMIZE )
200+ ./hack/gen-flavors.sh
201+
188202# # --------------------------------------
189203# # Docker
190204# # --------------------------------------
@@ -254,11 +268,16 @@ release: clean-release ## Builds and push container images using the latest git
254268 $(MAKE ) set-manifest-image MANIFEST_IMG=$(PROD_REGISTRY ) /$(IMAGE_NAME ) MANIFEST_TAG=$(RELEASE_TAG )
255269 $(MAKE ) set-manifest-pull-policy PULL_POLICY=IfNotPresent
256270 $(MAKE ) release-manifests
271+ $(MAKE ) release-templates
257272
258273.PHONY : release-manifests
259- release-manifests : $(RELEASE_DIR ) # # Builds the manifests to publish with a release
274+ release-manifests : $(KUSTOMIZE ) $( RELEASE_DIR ) # # Builds the manifests to publish with a release
260275 kustomize build config > $(RELEASE_DIR ) /infrastructure-components.yaml
261276
277+ .PHONY : release-templates
278+ release-templates : $(RELEASE_DIR )
279+ cp templates/cluster-template* $(RELEASE_DIR ) /
280+
262281.PHONY : release-binary
263282release-binary : $(RELEASE_DIR )
264283 docker run \
@@ -291,9 +310,9 @@ release-notes: $(RELEASE_NOTES)
291310# # --------------------------------------
292311
293312.PHONY : create-management-cluster
294- create-management-cluster : $(ENVSUBST )
313+ create-management-cluster : $(KUSTOMIZE ) $( ENVSUBST )
295314 # # Create kind management cluster.
296- kind create cluster --name=clusterapi
315+ $( MAKE ) kind-create
297316
298317 # Install cert manager and wait for availability
299318 kubectl create -f https://github.com/jetstack/cert-manager/releases/download/v0.11.1/cert-manager.yaml
@@ -303,7 +322,8 @@ create-management-cluster: $(ENVSUBST)
303322 kubectl apply -f https://github.com/kubernetes-sigs/cluster-api/releases/download/v0.3.3/cluster-api-components.yaml
304323
305324 # Deploy CAPZ
306- kustomize build config | $(ENVSUBST) | kubectl apply -f -
325+ kind load docker-image $(CONTROLLER_IMG)-$(ARCH):$(TAG) --name=capz
326+ $(KUSTOMIZE) build config | $(ENVSUBST) | kubectl apply -f -
307327
308328 # Wait for CAPI pods
309329 kubectl wait --for=condition=Ready --timeout=5m -n capi-system pod -l cluster.x-k8s.io/provider=cluster-api
@@ -312,24 +332,24 @@ create-management-cluster: $(ENVSUBST)
312332
313333 # Wait for CAPZ pods
314334 kubectl wait --for=condition=Ready --timeout=5m -n capz-system pod -l cluster.x-k8s.io/provider=infrastructure-azure
315-
316- # required sleep for when creating management and workload cluster simultaneously
335+
336+ # required sleep for when creating management and workload cluster simultaneously
317337 sleep 10
318- @echo 'Set kubectl context to the kind management cluster by running "kubectl config set-context kind-clusterapi "'
338+ @echo 'Set kubectl context to the kind management cluster by running "kubectl config set-context kind-capz "'
319339
320340.PHONY : create-workload-cluster
321- create-workload-cluster : $(ENVSUBST )
341+ create-workload-cluster : $(KUSTOMIZE ) $( ENVSUBST )
322342 # Create workload Cluster.
323- kustomize build templates | $( ENVSUBST ) | kubectl apply -f -
343+ $( ENVSUBST ) < $( TEMPLATES_DIR ) / $( CLUSTER_TEMPLATE ) | kubectl apply -f -
324344
325345 # Wait for the kubeconfig to become available.
326346 timeout 300 bash -c "while ! kubectl get secrets | grep $(CLUSTER_NAME)-kubeconfig; do sleep 1; done"
327347 # Get kubeconfig and store it locally.
328348 kubectl get secrets $(CLUSTER_NAME)-kubeconfig -o json | jq -r .data.value | base64 --decode > ./kubeconfig
329- timeout 300 bash -c "while ! kubectl --kubeconfig=./kubeconfig get nodes | grep master; do sleep 1; done"
349+ timeout 600 bash -c "while ! kubectl --kubeconfig=./kubeconfig get nodes | grep master; do sleep 1; done"
330350
331351 # Deploy calico
332- kubectl --kubeconfig=./kubeconfig apply -f https://docs.projectcalico.org/v3.13/manifests /calico.yaml
352+ kubectl --kubeconfig=./kubeconfig apply -f templates/addons /calico.yaml
333353
334354 @echo 'run "kubectl --kubeconfig=./kubeconfig ..." to work with the new target cluster'
335355
@@ -340,14 +360,27 @@ create-cluster: create-management-cluster create-workload-cluster ## Create a wo
340360delete-workload-cluster : # # Deletes the example workload Kubernetes cluster
341361 @echo ' Your Azure resources will now be deleted, this can take up to 20 minutes'
342362 kubectl delete cluster $(CLUSTER_NAME )
343-
363+
364+ # # --------------------------------------
365+ # # Tilt / Kind
366+ # # --------------------------------------
367+
368+ .PHONY : kind-create
369+ kind-create : # # create capz kind cluster if needed
370+ ./scripts/kind-with-registry.sh
371+
372+ .PHONY : tilt-up
373+ tilt-up : kind-create # # start tilt and build kind cluster if needed
374+ tilt up
375+
344376.PHONY : delete-cluster
345- delete-cluster : delete-workload-cluster # # Deletes the example kind cluster "clusterapi "
346- kind delete cluster --name=clusterapi
377+ delete-cluster : delete-workload-cluster # # Deletes the example kind cluster "capz "
378+ kind delete cluster --name=capz
347379
348380.PHONY : kind-reset
349- kind-reset : # # Destroys the "clusterapi" kind cluster.
350- kind delete cluster --name=clusterapi || true
381+ kind-reset : # # Destroys the "capz" kind cluster.
382+ kind delete cluster --name=capz || true
383+
351384
352385# # --------------------------------------
353386# # Cleanup / Verification
0 commit comments