Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
chore: make cluster creation work with kind >= v0.6.0
Browse files Browse the repository at this point in the history
The command 'kind get kubeconfig-path' has been deprecated in kind
v0.6.0 and removed in v0.7.0 so the cluster creation script doesn't
work with the newest version. To account for this fact and other
changes (such as kind now respecting `KUBECONFIG` and falling back to
the same defaults that `kubectl` uses), I reworked some parts of the
script.

This makes the scripts fail to work with kind version < v0.6.0.
  • Loading branch information
Max Jonas Werner committed Apr 30, 2020
1 parent 2470f01 commit e430f26
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 38 deletions.
46 changes: 9 additions & 37 deletions scripts/create-clusters.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@ CONFIGURE_INSECURE_REGISTRY_HOST="${CONFIGURE_INSECURE_REGISTRY_HOST:-}"
CONFIGURE_INSECURE_REGISTRY_CLUSTER="${CONFIGURE_INSECURE_REGISTRY_CLUSTER-y}"
CONTAINER_REGISTRY_HOST="${CONTAINER_REGISTRY_HOST:-172.17.0.1:5000}"
NUM_CLUSTERS="${NUM_CLUSTERS:-2}"
OVERWRITE_KUBECONFIG="${OVERWRITE_KUBECONFIG:-}"
KIND_IMAGE="${KIND_IMAGE:-}"
KIND_TAG="${KIND_TAG:-}"
docker_daemon_config="/etc/docker/daemon.json"
containerd_config="/etc/containerd/config.toml"
kubeconfig="${HOME}/.kube/config"

OS=`uname`

function create-insecure-registry() {
Expand Down Expand Up @@ -123,13 +122,6 @@ function create-clusters() {
echo "Waiting for clusters to be ready"
check-clusters-ready ${num_clusters}

# TODO(font): kind will create separate kubeconfig files for each cluster.
# Remove once https://github.com/kubernetes-sigs/kind/issues/113 is resolved.
if [[ "${OVERWRITE_KUBECONFIG}" ]]; then
kubectl config view --flatten > ${kubeconfig}
unset KUBECONFIG
fi

if [[ "${CONFIGURE_INSECURE_REGISTRY_CLUSTER}" ]]; then
# TODO(font): Configure insecure registry on kind host cluster. Remove once
# https://github.com/kubernetes-sigs/kind/issues/110 is resolved.
Expand All @@ -141,27 +133,21 @@ function create-clusters() {
function fixup-cluster() {
local i=${1} # cluster num

local kubeconfig_path="$(kind get kubeconfig-path --name cluster${i})"
export KUBECONFIG="${KUBECONFIG:-}:${kubeconfig_path}"

if [ "$OS" != "Darwin" ];then
# Set container IP address as kube API endpoint in order for clusters to reach kube API servers in other clusters.
kind get kubeconfig --name "cluster${i}" --internal >${kubeconfig_path}
OLD_KUBECONFIG=${KUBECONFIG}
export KUBECONFIG=$(mktemp)
kind get kubeconfig --name "kind-cluster${i}" --internal > ${KUBECONFIG}
SERVER=$(kubectl config view -o jsonpath='{.clusters[0].cluster.server}')
rm ${KUBECONFIG}
KUBECONFIG=${OLD_KUBECONFIG}
kubectl config set-cluster kind-cluster${i} --server=${SERVER}
fi

# Simplify context name
kubectl config rename-context "kubernetes-admin@cluster${i}" "cluster${i}"

# TODO(font): Need to rename auth user name to avoid conflicts when using
# multiple cluster kubeconfigs. Remove once
# https://github.com/kubernetes-sigs/kind/issues/112 is resolved.
sed -i.bak "s/kubernetes-admin/kubernetes-cluster${i}-admin/" ${kubeconfig_path} && rm -rf ${kubeconfig_path}.bak
}

function check-clusters-ready() {
for i in $(seq ${1}); do
local kubeconfig_path="$(kind get kubeconfig-path --name cluster${i})"
util::wait-for-condition 'ok' "kubectl --kubeconfig ${kubeconfig_path} --context cluster${i} get --raw=/healthz &> /dev/null" 120
util::wait-for-condition 'ok' "kubectl --context kind-cluster${i} get --raw=/healthz &> /dev/null" 120
done
}

Expand All @@ -186,17 +172,3 @@ echo "Creating ${NUM_CLUSTERS} clusters"
create-clusters ${NUM_CLUSTERS}

echo "Complete"

if [[ ! "${OVERWRITE_KUBECONFIG}" ]]; then
echo <<EOF "OVERWRITE_KUBECONFIG was not set so ${kubeconfig} was not modified. \
You can access your clusters by setting your KUBECONFIG environment variable using:
export KUBECONFIG=\"${KUBECONFIG}\"
Then you can overwrite ${kubeconfig} if you prefer using:
kubectl config view --flatten > ${kubeconfig}
unset KUBECONFIG
"
EOF
fi
2 changes: 1 addition & 1 deletion scripts/pre-commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ run-unit-tests
echo "Downloading e2e test dependencies"
./scripts/download-e2e-binaries.sh

CREATE_INSECURE_REGISTRY=y CONFIGURE_INSECURE_REGISTRY_HOST=y OVERWRITE_KUBECONFIG=y \
CREATE_INSECURE_REGISTRY=y CONFIGURE_INSECURE_REGISTRY_HOST=y \
KIND_TAG="v1.15.0" ./scripts/create-clusters.sh

# Initialize list of clusters to join
Expand Down

0 comments on commit e430f26

Please sign in to comment.