2020-10-09 21:25:34 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2023-08-28 21:57:43 +00:00
|
|
|
# Copyright 2020-2023 the Pinniped contributors. All Rights Reserved.
|
2020-10-09 21:25:34 +00:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
2023-09-27 19:32:49 +00:00
|
|
|
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
2020-10-09 21:25:34 +00:00
|
|
|
cd "${ROOT}"
|
|
|
|
|
2023-10-20 16:36:26 +00:00
|
|
|
|
|
|
|
if [[ "${PINNIPED_USE_LOCAL_KIND_REGISTRY:-}" != "" ]]; then
|
|
|
|
# create registry container unless it already exists
|
|
|
|
reg_name='kind-registry.local'
|
|
|
|
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
|
2023-09-28 18:48:06 +00:00
|
|
|
fi
|
|
|
|
|
2023-10-20 16:36:26 +00:00
|
|
|
|
|
|
|
if [[ "${PINNIPED_USE_CONTOUR:-}" != "" && "$PINNIPED_USE_LOCAL_KIND_REGISTRY" != "" ]]; then
|
|
|
|
echo "Adding Contour port mapping and local registry to Kind config."
|
|
|
|
ytt -f "${ROOT}/hack/lib/kind-config/single-node.yaml" \
|
|
|
|
-f "${ROOT}/hack/lib/kind-config/contour-overlay.yaml" \
|
|
|
|
-f "${ROOT}/hack/lib/kind-config/kind-registry-overlay.yaml" >/tmp/kind-config.yaml
|
|
|
|
kind create cluster --config /tmp/kind-config.yaml --name pinniped
|
|
|
|
elif [[ "${PINNIPED_USE_CONTOUR:-}" != "" ]]; then
|
2023-09-27 19:32:49 +00:00
|
|
|
echo "Adding Contour port mapping to Kind config."
|
|
|
|
ytt -f "${ROOT}/hack/lib/kind-config/single-node.yaml" \
|
|
|
|
-f "${ROOT}/hack/lib/kind-config/contour-overlay.yaml" >/tmp/kind-config.yaml
|
|
|
|
kind create cluster --config /tmp/kind-config.yaml --name pinniped
|
2023-10-20 16:36:26 +00:00
|
|
|
elif [[ "$PINNIPED_USE_LOCAL_KIND_REGISTRY" != "" ]]; then
|
|
|
|
echo "Adding local registry to Kind config."
|
|
|
|
ytt -f "${ROOT}/hack/lib/kind-config/single-node.yaml" \
|
|
|
|
-f "${ROOT}/hack/lib/kind-config/kind-registry-overlay.yaml" >/tmp/kind-config.yaml
|
|
|
|
kind create cluster --config /tmp/kind-config.yaml --name pinniped
|
2023-09-27 19:32:49 +00:00
|
|
|
else
|
|
|
|
# To choose a specific version of kube, add this option to the command below: `--image kindest/node:v1.28.0`.
|
|
|
|
# To debug the kind config, add this option to the command below: `-v 10`
|
|
|
|
kind create cluster --config "hack/lib/kind-config/single-node.yaml" --name pinniped
|
|
|
|
fi
|
2023-09-28 18:48:06 +00:00
|
|
|
|
|
|
|
|
2023-10-20 16:36:26 +00:00
|
|
|
if [[ "${PINNIPED_USE_LOCAL_KIND_REGISTRY:-}" != "" ]]; then
|
|
|
|
# connect the registry to the cluster network if not already connected
|
|
|
|
if [ "$(docker inspect -f='{{json .NetworkSettings.Networks.kind}}' "${reg_name}")" = 'null' ]; then
|
|
|
|
docker network connect "kind" "${reg_name}"
|
|
|
|
fi
|
2023-09-28 18:48:06 +00:00
|
|
|
|
2023-10-20 16:36:26 +00:00
|
|
|
# Document the local registry
|
|
|
|
# https://github.com/kubernetes/enhancements/tree/master/keps/sig-cluster-lifecycle/generic/1755-communicating-a-local-registry
|
|
|
|
cat <<EOF | kubectl apply -f -
|
2023-09-28 18:48:06 +00:00
|
|
|
apiVersion: v1
|
|
|
|
kind: ConfigMap
|
|
|
|
metadata:
|
|
|
|
name: local-registry-hosting
|
|
|
|
namespace: kube-public
|
|
|
|
data:
|
|
|
|
localRegistryHosting.v1: |
|
|
|
|
host: "localhost:${reg_port}"
|
|
|
|
help: "https://kind.sigs.k8s.io/docs/user/local-registry/"
|
|
|
|
EOF
|
2023-10-20 16:36:26 +00:00
|
|
|
|
|
|
|
fi
|