mirror of https://github.com/linkerd/linkerd2.git
130 lines
4.3 KiB
Bash
Executable File
130 lines
4.3 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
function check_linkerd_binary(){
|
|
printf "Checking the linkerd binary..."
|
|
if [[ "$linkerd_path" != /* ]]; then
|
|
printf "\\n[%s] is not an absolute path\\n" "$linkerd_path"
|
|
exit 1
|
|
fi
|
|
if [ ! -x "$linkerd_path" ]; then
|
|
printf "\\n[%s] does not exist or is not executable\\n" "$linkerd_path"
|
|
exit 1
|
|
fi
|
|
exit_code=0
|
|
"$linkerd_path" version --client > /dev/null 2>&1 || exit_code=$?
|
|
if [ $exit_code -ne 0 ]; then
|
|
printf "\\nFailed to run linkerd version command\\n"
|
|
exit $exit_code
|
|
fi
|
|
printf "[ok]\\n"
|
|
}
|
|
|
|
function check_if_k8s_reachable(){
|
|
printf "Checking if there is a Kubernetes cluster available..."
|
|
exit_code=0
|
|
kubectl --context=$k8s_context --request-timeout=5s get ns > /dev/null 2>&1 || exit_code=$?
|
|
if [ $exit_code -ne 0 ]; then
|
|
printf "\\nFailed to connect to Kubernetes cluster\\n"
|
|
exit $exit_code
|
|
fi
|
|
printf "[ok]\\n"
|
|
}
|
|
|
|
function remove_l5d_if_exists() {
|
|
resources=$(kubectl get all,clusterrole,clusterrolebinding,mutatingwebhookconfigurations,validatingwebhookconfigurations,psp,crd -l linkerd.io/control-plane-ns --all-namespaces -oname)
|
|
if [ ! -z "$resources" ]; then
|
|
printf "Removing existing l5d installation..."
|
|
cleanup
|
|
printf "[ok]\\n"
|
|
fi
|
|
}
|
|
|
|
function cleanup() {
|
|
$bindir/test-cleanup $k8s_context > /dev/null 2>&1 || exit_code=$?
|
|
if [ $exit_code -ne 0 ]; then
|
|
printf "\\nFailed to remove existing Linkerd resources\\n"
|
|
exit $exit_code
|
|
fi
|
|
}
|
|
|
|
function run_test(){
|
|
filename="$1"
|
|
shift
|
|
|
|
printf "Test script: [%s] Params: [%s]\n" "$(basename $filename)" "$*"
|
|
go test "$filename" --linkerd="$linkerd_path" --k8s-context="$k8s_context" --integration-tests "$@"
|
|
}
|
|
|
|
# Install the latest stable release.
|
|
# $1 - namespace to use for the stable release
|
|
function install_stable() {
|
|
tmp=$(mktemp -d -t l5dbin.XXX)
|
|
trap "rm -rf $tmp" RETURN
|
|
|
|
curl -s https://run.linkerd.io/install | HOME=$tmp sh > /dev/null 2>&1
|
|
|
|
local linkerd_path=$tmp/.linkerd2/bin/linkerd
|
|
local stable_namespace="$1"
|
|
$linkerd_path install --linkerd-namespace="$stable_namespace" | kubectl apply -f - > /dev/null 2>&1
|
|
$linkerd_path check --linkerd-namespace="$stable_namespace" > /dev/null 2>&1
|
|
}
|
|
|
|
# Run the upgrade test by upgrading the most-recent stable release to the HEAD of
|
|
# this branch.
|
|
# $1 - namespace to use for the stable release
|
|
function run_upgrade_test() {
|
|
local stable_namespace="$1"
|
|
local stable_version=$(curl -s https://versioncheck.linkerd.io/version.json | grep -o "stable-[0-9]*.[0-9]*.[0-9]*")
|
|
|
|
install_stable $stable_namespace
|
|
run_test "$test_directory/install_test.go" -failfast --upgrade-from-version=$stable_version --linkerd-namespace=$stable_namespace
|
|
}
|
|
|
|
linkerd_path=$1
|
|
if [ -z "$linkerd_path" ]; then
|
|
echo "usage: $(basename "$0") /path/to/linkerd [namespace] [k8s-context]" >&2
|
|
exit 64
|
|
fi
|
|
|
|
bindir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
test_directory="$bindir/../test"
|
|
linkerd_version=$($linkerd_path version --client --short)
|
|
linkerd_namespace=${2:-l5d-integration}
|
|
k8s_context=${3:-""}
|
|
|
|
check_linkerd_binary
|
|
check_if_k8s_reachable
|
|
remove_l5d_if_exists
|
|
|
|
printf "==================RUNNING ALL TESTS==================\\n"
|
|
printf "Testing Linkerd version [%s] namespace [%s] k8s-context [%s]\\n" "$linkerd_version" "$linkerd_namespace" "$k8s_context"
|
|
|
|
# run upgrade test:
|
|
# 1. install latest stable
|
|
# 2. upgrade to HEAD
|
|
# 3. if failed, exit script to avoid leaving behind stale resources which will
|
|
# fail subsequent tests. `cleanup` is not called if this test failed so that
|
|
# there is a chance to debug the problem
|
|
run_upgrade_test "$linkerd_namespace"-upgrade || exit_code=$?
|
|
if [ $exit_code -ne 0 ]; then
|
|
printf "\\n=== FAIL: Can't upgrade to version $linkerd_version\\n"
|
|
exit $exit_code
|
|
fi
|
|
cleanup
|
|
|
|
# run the rest of the test suite. `cleanup` is not called if this test failed
|
|
# so that there is a chance to debug the problem
|
|
run_test "$test_directory/install_test.go" -failfast --linkerd-namespace=$linkerd_namespace || exit_code=$?
|
|
for test in $(find "$test_directory" -mindepth 2 -name '*_test.go'); do
|
|
run_test "$test" --linkerd-namespace=$linkerd_namespace || exit_code=$?
|
|
done
|
|
|
|
if [ $exit_code -eq 0 ]; then
|
|
printf "\\n=== PASS: all tests passed\\n"
|
|
cleanup
|
|
else
|
|
printf "\\n=== FAIL: at least one test failed\\n"
|
|
fi
|
|
|
|
exit $exit_code
|