Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Index migration ci test #621

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
105 changes: 105 additions & 0 deletions hack/verify-index-migration.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#!/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 "${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 &&
env KREW_ROOT="${krew_root}" "$KREW" update
)
}

install_plugin() {
plugin="${2}"

run_krew "${1}" install "${plugin}" 1>/dev/null
}

# patch_krew_bin replaces the installed krew binary with the new version
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

# 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 \
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 "${krew_root}" list || (
echo >&2 "krew list is failing"
exit 1
)
verify_index_migrated "${krew_root}" || (
echo >&2 "index was not migrated"
exit 1
)
}

main