mirror of https://github.com/k3d-io/k3d
parent
a53af1a24b
commit
4682cea41f
@ -0,0 +1,85 @@ |
||||
#!/bin/bash |
||||
|
||||
RED='\033[1;31m' |
||||
GRN='\033[1;32m' |
||||
YEL='\033[1;33m' |
||||
BLU='\033[1;34m' |
||||
WHT='\033[1;37m' |
||||
MGT='\033[1;95m' |
||||
CYA='\033[1;96m' |
||||
END='\033[0m' |
||||
BLOCK='\033[1;37m' |
||||
|
||||
PATH=/usr/local/bin:$PATH |
||||
export PATH |
||||
|
||||
log() { >&2 printf "${BLOCK}>>>${END} $1\n"; } |
||||
|
||||
info() { log "${BLU}$1${END}"; } |
||||
highlight() { log "${MGT}$1${END}"; } |
||||
|
||||
bye() { |
||||
log "${BLU}$1... exiting${END}" |
||||
exit 0 |
||||
} |
||||
|
||||
warn() { log "${RED}!!! WARNING !!! $1 ${END}"; } |
||||
|
||||
abort() { |
||||
log "${RED}FATAL: $1${END}" |
||||
exit 1 |
||||
} |
||||
|
||||
command_exists() { |
||||
command -v $1 >/dev/null 2>&1 |
||||
} |
||||
|
||||
failed() { |
||||
if [ -z "$1" ] ; then |
||||
log "${RED}failed!!!${END}" |
||||
else |
||||
log "${RED}$1${END}" |
||||
fi |
||||
abort "test failed" |
||||
} |
||||
|
||||
passed() { |
||||
if [ -z "$1" ] ; then |
||||
log "${GRN}done!${END}" |
||||
else |
||||
log "${GRN}$1${END}" |
||||
fi |
||||
} |
||||
|
||||
dump_registries_yaml_in() { |
||||
for cluster in $@ ; do |
||||
info "registries.yaml in cluster $cluster:" |
||||
docker exec -t k3d-$cluster-server cat /etc/rancher/k3s/registries.yaml |
||||
done |
||||
} |
||||
|
||||
# checks that a URL is available, with an optional error message |
||||
check_url() { |
||||
command_exists curl || abort "curl is not installed" |
||||
curl -L --silent -k --output /dev/null --fail "$1" |
||||
} |
||||
|
||||
check_k3d_clusters() { |
||||
[ -n "$EXE" ] || abort "EXE is not defined" |
||||
for c in "c1" "c2" ; do |
||||
kc=$($EXE get-kubeconfig --name "$c") |
||||
[ -n "$kc" ] || abort "could not obtain a kubeconfig for $c" |
||||
if kubectl --kubeconfig="$kc" cluster-info ; then |
||||
passed "cluster $c is reachable (with kubeconfig=$kc)" |
||||
else |
||||
warn "could not obtain cluster info for $c (with kubeconfig=$kc). Contents:\n$(cat $kc)" |
||||
return 1 |
||||
fi |
||||
done |
||||
return 0 |
||||
} |
||||
|
||||
check_registry() { |
||||
check_url $REGISTRY/v2/_catalog |
||||
} |
||||
|
@ -0,0 +1,32 @@ |
||||
#!/bin/bash |
||||
|
||||
K3D_EXE=${EXE:-/bin/k3d} |
||||
K3D_IMAGE_TAG=$1 |
||||
|
||||
# define E2E_KEEP to non-empty for keeping the e2e runner container after running the tests |
||||
E2E_KEEP=${E2E_KEEP:-} |
||||
|
||||
#################################################################################### |
||||
|
||||
TIMESTAMP=$(date "+%m%d%H%M%S") |
||||
|
||||
k3de2e=$(docker run -d \ |
||||
-v "$(pwd)"/tests:/tests \ |
||||
--privileged \ |
||||
-e EXE="$K3D_EXE" \ |
||||
-e CI="true" \ |
||||
--name "k3d-e2e-runner-$TIMESTAMP" \ |
||||
k3d:$K3D_IMAGE_TAG) |
||||
|
||||
sleep 5 # wait 5 seconds for docker to start |
||||
|
||||
# Execute tests |
||||
finish() { |
||||
docker stop "$k3de2e" || /bin/true |
||||
if [ -z "$E2E_KEEP" ] ; then |
||||
docker rm "$k3de2e" || /bin/true |
||||
fi |
||||
} |
||||
trap finish EXIT |
||||
|
||||
docker exec "$k3de2e" /tests/runner.sh |
@ -0,0 +1,22 @@ |
||||
#!/bin/bash |
||||
|
||||
CURR_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" |
||||
[ -d "$CURR_DIR" ] || { echo "FATAL: no current dir (maybe running in zsh?)"; exit 1; } |
||||
|
||||
# shellcheck source=./common.sh |
||||
source "$CURR_DIR/common.sh" |
||||
|
||||
######################################################################################### |
||||
|
||||
[ -n "$EXE" ] || abort "no EXE provided" |
||||
|
||||
info "Starting e2e tests..." |
||||
|
||||
for i in $CURR_DIR/test_*.sh ; do |
||||
base=$(basename $i .sh) |
||||
highlight "***** Running $base *****" |
||||
$i || abort "test $base failed" |
||||
done |
||||
|
||||
exit 0 |
||||
|
@ -0,0 +1,23 @@ |
||||
#!/bin/bash |
||||
|
||||
CURR_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" |
||||
[ -d "$CURR_DIR" ] || { echo "FATAL: no current dir (maybe running in zsh?)"; exit 1; } |
||||
|
||||
# shellcheck source=./common.sh |
||||
source "$CURR_DIR/common.sh" |
||||
|
||||
info "Creating two clusters..." |
||||
$EXE create --wait 60 --name "c1" --api-port 6443 || failed "could not create cluster c1" |
||||
$EXE create --wait 60 --name "c2" --api-port 6444 || failed "could not create cluster c2" |
||||
|
||||
info "Checking we have access to both clusters..." |
||||
check_k3d_clusters "c1" "c2" || failed "error checking cluster" |
||||
dump_registries_yaml_in "c1" "c2" |
||||
|
||||
info "Deleting clusters..." |
||||
$EXE delete --name "c1" || failed "could not delete the cluster c1" |
||||
$EXE delete --name "c2" || failed "could not delete the cluster c2" |
||||
|
||||
exit 0 |
||||
|
||||
|
Loading…
Reference in new issue