From c40decf01120f2d305489ee241720eb98d4531b9 Mon Sep 17 00:00:00 2001 From: Jonathan Tong Date: Wed, 31 Aug 2022 20:17:29 -0400 Subject: [PATCH] Add make targets for Tilt, kind, and clean up --- Makefile | 26 +++++++++++++++++++++++++- docs/book/src/developer/tilt.md | 22 +++++++++++++++++++--- hack/kind-install-for-capd.sh | 9 +++++++-- 3 files changed, 51 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 4ca49aa9362c..23d071179487 100644 --- a/Makefile +++ b/Makefile @@ -175,6 +175,9 @@ CLUSTERCTL_IMG ?= $(REGISTRY)/$(CLUSTERCTL_IMAGE_NAME) TEST_EXTENSION_IMAGE_NAME ?= test-extension TEST_EXTENSION_IMG ?= $(REGISTRY)/$(TEST_EXTENSION_IMAGE_NAME) +# kind +CAPI_KIND_CLUSTER_NAME ?= capi-test + # It is set by Prow GIT_TAG, a git-based tag of the form vYYYYMMDD-hash, e.g., v20210120-v0.3.10-308-gc61521971 TAG ?= dev @@ -669,6 +672,10 @@ test-capd-junit: $(SETUP_ENVTEST) $(GOTESTSUM) ## Run unit and integration tests kind-cluster: ## Create a new kind cluster designed for development with Tilt hack/kind-install-for-capd.sh +.PHONY: tilt-up +tilt-up: kind-cluster ## Start tilt and build kind cluster if needed. + tilt up + .PHONY: docker-build-e2e docker-build-e2e: ## Rebuild all Cluster API provider images to be used in the e2e tests $(MAKE) docker-build REGISTRY=gcr.io/k8s-staging-cluster-api PULL_POLICY=IfNotPresent @@ -934,15 +941,32 @@ set-manifest-image: ##@ clean: .PHONY: clean -clean: ## Remove all generated files +clean: ## Remove generated binaries, GitBook files, Helm charts, and Tilt build files $(MAKE) clean-bin $(MAKE) clean-book + $(MAKE) clean-charts + $(MAKE) clean-tilt + +.PHONY: clean-kind +clean-kind: ## Cleans up the kind cluster with the name $CAPI_KIND_CLUSTER_NAME + kind delete cluster --name="$(CAPI_KIND_CLUSTER_NAME)" || true .PHONY: clean-bin clean-bin: ## Remove all generated binaries rm -rf $(BIN_DIR) rm -rf $(TOOLS_BIN_DIR) +.PHONY: clean-tilt +clean-tilt: ## Remove all files generated by Tilt + rm -rf ./.tiltbuild + rm -rf ./controlplane/kubeadm/.tiltbuild + rm -rf ./bootstrap/kubeadm/.tiltbuild + rm -rf ./test/infrastructure/docker/.tiltbuild + +.PHONY: clean-charts +clean-charts: ## Remove all local copies of Helm charts in ./hack/observability + (for path in "./hack/observability/*"; do rm -rf $$path/charts ; done) + .PHONY: clean-book clean-book: ## Remove all generated GitBook files rm -rf ./docs/book/_book diff --git a/docs/book/src/developer/tilt.md b/docs/book/src/developer/tilt.md index 6a421bd47518..a99318efdc86 100644 --- a/docs/book/src/developer/tilt.md +++ b/docs/book/src/developer/tilt.md @@ -262,12 +262,12 @@ With this config, the respective managers will be invoked with: manager --logging-format=json ``` -### Run Tilt! +### Create a kind cluster and run Tilt! -To launch your development environment, run +To create a pre-configured kind cluster (if you have not already done so) and launch your development environment, run ```bash -tilt up +make tilt-up ``` This will open the command-line HUD as well as a web browser interface. You can monitor Tilt's status in either @@ -297,6 +297,22 @@ kustomize_substitutions: WORKER_MACHINE_COUNT: 3 ``` +### Cleaning up your kind cluster and development environment + +After stopping Tilt, you can clean up your kind cluster and development environment by running + +```bash +make clean-kind +``` + +To remove all generated files, run + +```bash +make clean +``` + +Note that you must run `make clean` or `make clean-charts` to fetch new versions of charts deployed using `deploy_observability` in `tilt-settings.yaml`. +

Use of clusterctl

When the worker cluster has been created using tilt, `clusterctl` should not be used for management diff --git a/hack/kind-install-for-capd.sh b/hack/kind-install-for-capd.sh index edaec2cb7f9d..63a614181230 100755 --- a/hack/kind-install-for-capd.sh +++ b/hack/kind-install-for-capd.sh @@ -26,7 +26,12 @@ set -o errexit set -o nounset set -o pipefail -NAME=${CAPI_KIND_CLUSTER_NAME:-"capi-test"} +KIND_CLUSTER_NAME=${CAPI_KIND_CLUSTER_NAME:-"capi-test"} + +if [[ "$(kind get clusters)" =~ .*"${KIND_CLUSTER_NAME}".* ]]; then + echo "kind cluster already exists, moving on" + exit 0 +fi # create registry container unless it already exists reg_name='kind-registry' @@ -39,7 +44,7 @@ if [ "${running}" != 'true' ]; then fi # create a cluster with the local registry enabled in containerd -cat <