From a4a567f4e77e03ee571454edfe530ebc9974d997 Mon Sep 17 00:00:00 2001 From: killianmuldoon Date: Mon, 13 Sep 2021 13:53:37 +0100 Subject: [PATCH] Add script to install Kind for testing with CAPD --- Makefile | 4 ++ hack/kind-install-for-capd.sh | 85 +++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100755 hack/kind-install-for-capd.sh diff --git a/Makefile b/Makefile index 06a9f6a4451e..ada87257c107 100644 --- a/Makefile +++ b/Makefile @@ -166,6 +166,10 @@ docker-build-e2e: ## Rebuild all Cluster API provider images to be used in the e test-e2e: ## Run the e2e tests $(MAKE) -C $(TEST_DIR)/e2e run +.PHONY: kind-cluster +kind-cluster: ## Create a new kind cluster designed for testing with Tilt + hack/kind-install-for-capd.sh + ## -------------------------------------- ## Binaries ## -------------------------------------- diff --git a/hack/kind-install-for-capd.sh b/hack/kind-install-for-capd.sh new file mode 100755 index 000000000000..b7c19b9ca2ea --- /dev/null +++ b/hack/kind-install-for-capd.sh @@ -0,0 +1,85 @@ +#!/bin/sh + +# Copyright 2021 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. + + +# This script installs a local KIND cluster with a local container registry and the correct files mounted for using CAPD +# to test Cluster API. +# This script is a customized version of the kind_with_local_registry script supplied by the KIND maintainers at +# https://kind.sigs.k8s.io/docs/user/local-registry/ +# The modifications mount the docker socket inside the KIND cluster so that CAPD can be used to +# created docker containers. + +set -o errexit +set -o nounset +set -o pipefail + +NAME="capi-test" + +while [[ $# -gt 0 ]]; do + key="$1" + case $key in + -n|--name) + NAME="$2" + shift + shift + ;; + esac +done + + +# create registry container unless it already exists +reg_name='kind-registry' +reg_port='5000' +running="$(docker inspect -f '{{.State.Running}}' "${reg_name}" 2>/dev/null || true)" +if [ "${running}" != 'true' ]; then + docker run \ + -d --restart=always -p "127.0.0.1:${reg_port}:5000" --name "${reg_name}" \ + registry:2 +fi + +# create a cluster with the local registry enabled in containerd +cat <