From a6042b80137519915b7c756ed4b12ed637b2ca40 Mon Sep 17 00:00:00 2001 From: Chris Kim Date: Tue, 14 Jul 2020 21:35:57 -0700 Subject: [PATCH 1/7] Add ci test to verify index migration --- .github/workflows/ci.yml | 3 + hack/verify-index-migration.sh | 115 +++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100755 hack/verify-index-migration.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2752c7ba..516a9341 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -60,6 +60,9 @@ jobs: - name: Run integration tests run: hack/run-integration-tests.sh + - name: Verify index migration from 0.3.x to 0.4.x + run: hack/verify-index-migration.sh + - name: Create a new release if: contains(github.ref, 'tags') id: create_release diff --git a/hack/verify-index-migration.sh b/hack/verify-index-migration.sh new file mode 100755 index 00000000..4eaaacc7 --- /dev/null +++ b/hack/verify-index-migration.sh @@ -0,0 +1,115 @@ +#!/usr/bin/env bash + +# Copyright 2020 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 tests the automatic index migration which was added for +# migrating krew 0.3.x to krew 0.4.x. +# +# TODO(ahmetb,corneliusweig,chriskim06) remove at/after krew 0.5.x when +# index-migration is no longer supported. + +set -euo pipefail + +[[ -n "${DEBUG:-}" ]] && set -x + +SCRIPTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +BINDIR="${SCRIPTDIR}/../out/bin" +goos="$(go env GOOS)" +goarch="$(go env GOARCH)" + +install_krew_0_3_4() { + krew_root="${1}" + temp_dir="$(mktemp -d)" + trap 'rm -rf "${temp_dir}"' RETURN + ( + set -x; cd "$(mktemp -d)" && + curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/krew.{tar.gz,yaml}" && + tar zxvf krew.tar.gz && + KREW=./krew-"$(uname | tr '[:upper:]' '[:lower:]')_amd64" && + "$KREW" install --manifest=krew.yaml --archive=krew.tar.gz && + "$KREW" update + ) +} + +install_plugin() { + krew_root="${1}" + plugin="${2}" + + run_krew "${1}" install "${plugin}" 1>/dev/null +} + +# patch_krew_bin replaces the installed krew 0.2.x binary with the specified +patch_krew_bin() { + krew_root="${1}" + new_binary="${2}" + + local old_binary + old_binary="$(readlink -f "${krew_root}/bin/kubectl-krew")" + cp -f "${new_binary}" "${old_binary}" +} + +# run_krew runs 'krew' with the specified KREW_ROOT and arguments. +run_krew() { + krew_root="${1}" + shift + + env KREW_ROOT="${krew_root}" \ + PATH="${krew_root}/bin:$PATH" \ + kubectl krew "$@" +} + +# run_krew runs 'krew' with the specified KREW_ROOT and arguments. +run_krew_with_multi_index_flag() { + krew_root="${1}" + shift + + env KREW_ROOT="${krew_root}" \ + PATH="${krew_root}/bin:$PATH" \ + X_KREW_ENABLE_MULTI_INDEX=1 \ + kubectl krew "$@" +} + +verify_index_migrated() { + krew_root="${1}" + [[ -d "${krew_root}/index/default" ]] +} + +main() { + new_krew="${BINDIR}/krew-${goos}_${goarch}" + if [[ ! -e "${new_krew}" ]]; then + echo >&2 "Could not find ${new_krew}." + exit 1 + fi + + krew_root="$(mktemp -d)" + trap 'rm -rf "${krew_root}"' RETURN + + echo >&2 "Test directory: ${krew_root}" + install_krew_0_3_4 "${krew_root}" + install_plugin "${krew_root}" "get-all" + echo >&2 "Swapping krew binary" + patch_krew_bin "${krew_root}" "${new_krew}" + run_krew_with_multi_index_flag "${krew_root}" list || ( + echo >&2 "krew list is failing" + exit 1 + ) + verify_index_migrated "${krew_root}" || ( + echo >&2 "index was not migrated" + ls -la "${krew_root}/index" + exit 1 + ) +} + +main From 05da94b845df023ac5f84bdc09fb856c3fb53b9c Mon Sep 17 00:00:00 2001 From: Chris Kim Date: Tue, 14 Jul 2020 21:38:48 -0700 Subject: [PATCH 2/7] Run shfmt --- hack/verify-index-migration.sh | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/hack/verify-index-migration.sh b/hack/verify-index-migration.sh index 4eaaacc7..dadf35a7 100755 --- a/hack/verify-index-migration.sh +++ b/hack/verify-index-migration.sh @@ -34,12 +34,13 @@ install_krew_0_3_4() { temp_dir="$(mktemp -d)" trap 'rm -rf "${temp_dir}"' RETURN ( - set -x; cd "$(mktemp -d)" && - curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/krew.{tar.gz,yaml}" && - tar zxvf krew.tar.gz && - KREW=./krew-"$(uname | tr '[:upper:]' '[:lower:]')_amd64" && - "$KREW" install --manifest=krew.yaml --archive=krew.tar.gz && - "$KREW" update + set -x + cd "$(mktemp -d)" && + curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/krew.{tar.gz,yaml}" && + tar zxvf krew.tar.gz && + KREW=./krew-"$(uname | tr '[:upper:]' '[:lower:]')_amd64" && + "$KREW" install --manifest=krew.yaml --archive=krew.tar.gz && + "$KREW" update ) } @@ -70,7 +71,7 @@ run_krew() { kubectl krew "$@" } -# run_krew runs 'krew' with the specified KREW_ROOT and arguments. +# TODO(chriskim06): remove this after multi index flag is removed run_krew_with_multi_index_flag() { krew_root="${1}" shift @@ -101,6 +102,7 @@ main() { install_plugin "${krew_root}" "get-all" echo >&2 "Swapping krew binary" patch_krew_bin "${krew_root}" "${new_krew}" + # TODO(chriskim06): replace with run_krew after multi index flag is removed run_krew_with_multi_index_flag "${krew_root}" list || ( echo >&2 "krew list is failing" exit 1 From afd961f19ed638673af446083821f3e9755b67fb Mon Sep 17 00:00:00 2001 From: Chris Kim Date: Tue, 14 Jul 2020 21:51:22 -0700 Subject: [PATCH 3/7] Install krew 0.3.4 --- hack/verify-index-migration.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hack/verify-index-migration.sh b/hack/verify-index-migration.sh index dadf35a7..f21f2d4e 100755 --- a/hack/verify-index-migration.sh +++ b/hack/verify-index-migration.sh @@ -36,7 +36,7 @@ install_krew_0_3_4() { ( set -x cd "$(mktemp -d)" && - curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/krew.{tar.gz,yaml}" && + curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/download/v0.3.4/krew.{tar.gz,yaml}" && tar zxvf krew.tar.gz && KREW=./krew-"$(uname | tr '[:upper:]' '[:lower:]')_amd64" && "$KREW" install --manifest=krew.yaml --archive=krew.tar.gz && From abe02dfab2788034e56fd684ce516fa040b70ca0 Mon Sep 17 00:00:00 2001 From: Chris Kim Date: Tue, 14 Jul 2020 22:04:10 -0700 Subject: [PATCH 4/7] Install to correct dir --- hack/verify-index-migration.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hack/verify-index-migration.sh b/hack/verify-index-migration.sh index f21f2d4e..fa835b26 100755 --- a/hack/verify-index-migration.sh +++ b/hack/verify-index-migration.sh @@ -35,10 +35,11 @@ install_krew_0_3_4() { trap 'rm -rf "${temp_dir}"' RETURN ( set -x - cd "$(mktemp -d)" && + cd "${temp_dir}" && curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/download/v0.3.4/krew.{tar.gz,yaml}" && tar zxvf krew.tar.gz && KREW=./krew-"$(uname | tr '[:upper:]' '[:lower:]')_amd64" && + env KREW_ROOT="${krew_root}" && "$KREW" install --manifest=krew.yaml --archive=krew.tar.gz && "$KREW" update ) From 117c8e7df5d273753d1d2639191a6860aa81dae7 Mon Sep 17 00:00:00 2001 From: Chris Kim Date: Tue, 14 Jul 2020 22:10:27 -0700 Subject: [PATCH 5/7] Set krew root properly --- hack/verify-index-migration.sh | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/hack/verify-index-migration.sh b/hack/verify-index-migration.sh index fa835b26..d1d7df88 100755 --- a/hack/verify-index-migration.sh +++ b/hack/verify-index-migration.sh @@ -39,20 +39,18 @@ install_krew_0_3_4() { curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/download/v0.3.4/krew.{tar.gz,yaml}" && tar zxvf krew.tar.gz && KREW=./krew-"$(uname | tr '[:upper:]' '[:lower:]')_amd64" && - env KREW_ROOT="${krew_root}" && - "$KREW" install --manifest=krew.yaml --archive=krew.tar.gz && - "$KREW" update + env KREW_ROOT="${krew_root}" "$KREW" install --manifest=krew.yaml --archive=krew.tar.gz && + env KREW_ROOT="${krew_root}" "$KREW" update ) } install_plugin() { - krew_root="${1}" plugin="${2}" run_krew "${1}" install "${plugin}" 1>/dev/null } -# patch_krew_bin replaces the installed krew 0.2.x binary with the specified +# patch_krew_bin replaces the installed krew binary with the new version patch_krew_bin() { krew_root="${1}" new_binary="${2}" From 89d21807f5c85e54e6bcd19d4a2a408e80450e64 Mon Sep 17 00:00:00 2001 From: Chris Kim Date: Tue, 14 Jul 2020 22:14:29 -0700 Subject: [PATCH 6/7] Remove ls --- hack/verify-index-migration.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/hack/verify-index-migration.sh b/hack/verify-index-migration.sh index d1d7df88..f5918e72 100755 --- a/hack/verify-index-migration.sh +++ b/hack/verify-index-migration.sh @@ -108,7 +108,6 @@ main() { ) verify_index_migrated "${krew_root}" || ( echo >&2 "index was not migrated" - ls -la "${krew_root}/index" exit 1 ) } From 7cf272fde69d72756205a92f0b49417fe121a1b1 Mon Sep 17 00:00:00 2001 From: Chris Kim Date: Tue, 14 Jul 2020 22:18:07 -0700 Subject: [PATCH 7/7] Remove unnecessary function --- hack/verify-index-migration.sh | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/hack/verify-index-migration.sh b/hack/verify-index-migration.sh index f5918e72..a73299f4 100755 --- a/hack/verify-index-migration.sh +++ b/hack/verify-index-migration.sh @@ -65,16 +65,7 @@ run_krew() { krew_root="${1}" shift - env KREW_ROOT="${krew_root}" \ - PATH="${krew_root}/bin:$PATH" \ - kubectl krew "$@" -} - -# TODO(chriskim06): remove this after multi index flag is removed -run_krew_with_multi_index_flag() { - krew_root="${1}" - shift - + # TODO(chriskim06): remove multi index flag once feature gate is removed env KREW_ROOT="${krew_root}" \ PATH="${krew_root}/bin:$PATH" \ X_KREW_ENABLE_MULTI_INDEX=1 \ @@ -101,8 +92,7 @@ main() { install_plugin "${krew_root}" "get-all" echo >&2 "Swapping krew binary" patch_krew_bin "${krew_root}" "${new_krew}" - # TODO(chriskim06): replace with run_krew after multi index flag is removed - run_krew_with_multi_index_flag "${krew_root}" list || ( + run_krew "${krew_root}" list || ( echo >&2 "krew list is failing" exit 1 )