From 27df67bb91ab616dd2de3099237ee22293b24fba Mon Sep 17 00:00:00 2001 From: Max Jonas Werner Date: Thu, 30 Apr 2020 16:41:33 +0200 Subject: [PATCH] chore: make cluster creation work with kind v0.7.0 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 latter 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. pre-commit now uses the kind imave v1.17.5 for tests. Note: This change makes the scripts fail to work with kind version < v0.7.0. --- scripts/create-clusters.sh | 48 ++++++++------------------------ scripts/download-e2e-binaries.sh | 2 +- scripts/pre-commit.sh | 4 +-- 3 files changed, 14 insertions(+), 40 deletions(-) diff --git a/scripts/create-clusters.sh b/scripts/create-clusters.sh index 7fa20390a7..f17d78ea07 100755 --- a/scripts/create-clusters.sh +++ b/scripts/create-clusters.sh @@ -27,12 +27,10 @@ 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() { @@ -92,7 +90,7 @@ EOF " ;; $containerd_config) - echo "sed -i '/\[plugins.cri.registry.mirrors\]/a [plugins.cri.registry.mirrors."\"${CONTAINER_REGISTRY_HOST}\""]\nendpoint = ["\"http://${CONTAINER_REGISTRY_HOST}\""]' ${containerd_config}" + echo 'echo -e "[plugins.\"io.containerd.grpc.v1.cri\".registry.mirrors.\"'${CONTAINER_REGISTRY_HOST}'\"]\n endpoint = [\"http://'${CONTAINER_REGISTRY_HOST}'\"]\n" >> '${containerd_config} ;; *) echo "Sorry, config insecure registy is not supported for $config_file" @@ -123,13 +121,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. @@ -141,27 +132,23 @@ 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 "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 + kubectl config rename-context "kind-cluster${i}" "cluster${i}" } 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 cluster${i} get --raw=/healthz &> /dev/null" 120 done } @@ -184,19 +171,6 @@ fi echo "Creating ${NUM_CLUSTERS} clusters" create-clusters ${NUM_CLUSTERS} +kubectl config use-context cluster1 echo "Complete" - -if [[ ! "${OVERWRITE_KUBECONFIG}" ]]; then - echo < ${kubeconfig} -unset KUBECONFIG -" -EOF -fi diff --git a/scripts/download-e2e-binaries.sh b/scripts/download-e2e-binaries.sh index 30991b0b8f..d815e7afb6 100755 --- a/scripts/download-e2e-binaries.sh +++ b/scripts/download-e2e-binaries.sh @@ -35,7 +35,7 @@ dest_dir="${root_dir}/bin" mkdir -p "${dest_dir}" # kind -kind_version="v0.4.0" +kind_version="v0.7.0" kind_path="${dest_dir}/kind" kind_url="https://github.com/kubernetes-sigs/kind/releases/download/${kind_version}/kind-linux-amd64" curl -Lo "${kind_path}" "${kind_url}" && chmod +x "${kind_path}" diff --git a/scripts/pre-commit.sh b/scripts/pre-commit.sh index 79d9f97aa8..b57fef928d 100755 --- a/scripts/pre-commit.sh +++ b/scripts/pre-commit.sh @@ -150,8 +150,8 @@ 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 \ - KIND_TAG="v1.15.0" ./scripts/create-clusters.sh +CREATE_INSECURE_REGISTRY=y CONFIGURE_INSECURE_REGISTRY_HOST=y \ + KIND_TAG="v1.17.5" ./scripts/create-clusters.sh # Initialize list of clusters to join join-cluster-list > /dev/null