#!/usr/bin/env bash # 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 if [[ "${TRACE-0}" == "1" ]]; then set -o xtrace fi KIND_CLUSTER_NAME=${CAPI_KIND_CLUSTER_NAME:-"capi-test"} # See: https://kind.sigs.k8s.io/docs/user/configuration/#ip-family KIND_NETWORK_IPFAMILY=${KIND_NETWORK_IPFAMILY:-"dual"} # 1. If kind cluster already exists exit. if [[ "$(kind get clusters)" =~ .*"${KIND_CLUSTER_NAME}".* ]]; then echo "kind cluster already exists, moving on" exit 0 fi # 2. Create registry container unless it already exists reg_name='kind-registry' reg_port='5000' if [ "$(docker inspect -f '{{.State.Running}}' "${reg_name}" 2>/dev/null || true)" != 'true' ]; then docker run \ -d --restart=always -p "127.0.0.1:${reg_port}:5000" --name "${reg_name}" \ registry:2 fi # 3. Create kind cluster with containerd registry config dir enabled. # TODO(killianmuldoon): kind will eventually enable this by default and this patch will be unnecessary. # # See: # https://github.com/kubernetes-sigs/kind/issues/2875 # https://github.com/containerd/containerd/blob/main/docs/cri/config.md#registry-configuration # See: https://github.com/containerd/containerd/blob/main/docs/hosts.md cat <