2022-01-07 00:05:59 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
all_services=(
|
|
|
|
coredns
|
|
|
|
local-path-provisioner
|
|
|
|
metrics-server
|
|
|
|
traefik
|
|
|
|
)
|
|
|
|
|
|
|
|
export NUM_SERVERS=2
|
|
|
|
export NUM_AGENTS=0
|
|
|
|
export WAIT_SERVICES="${all_services[@]}"
|
|
|
|
export SERVER_1_ARGS="--cluster-init"
|
|
|
|
|
2022-06-30 00:44:41 +00:00
|
|
|
REPO=${REPO:-rancher}
|
|
|
|
IMAGE_NAME=${IMAGE_NAME:-k3s}
|
|
|
|
PREVIOUS_CHANNEL=$(grep 'k8s.io/kubernetes v' go.mod | head -n1 | awk '{print $2}' | awk -F. '{print "v1." ($2 - 1)}')
|
|
|
|
PREVIOUS_VERSION=$(curl -s https://update.k3s.io/v1-release/channels/${PREVIOUS_CHANNEL} -o /dev/null -w '%{redirect_url}' | awk -F/ '{print gensub(/\+/, "-", "g", $NF)}')
|
|
|
|
STABLE_VERSION=$(curl -s https://update.k3s.io/v1-release/channels/stable -o /dev/null -w '%{redirect_url}' | awk -F/ '{print gensub(/\+/, "-", "g", $NF)}')
|
|
|
|
LATEST_VERSION=$(curl -s https://update.k3s.io/v1-release/channels/latest -o /dev/null -w '%{redirect_url}' | awk -F/ '{print gensub(/\+/, "-", "g", $NF)}')
|
|
|
|
|
2022-01-07 00:05:59 +00:00
|
|
|
server-post-hook() {
|
|
|
|
if [ $1 -eq 1 ]; then
|
|
|
|
local url=$(cat $TEST_DIR/servers/1/metadata/url)
|
|
|
|
export SERVER_ARGS="${SERVER_ARGS} --server $url"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
export -f server-post-hook
|
|
|
|
|
|
|
|
start-test() {
|
|
|
|
echo "Cluster is up"
|
|
|
|
}
|
|
|
|
export -f start-test
|
|
|
|
|
|
|
|
# --- create a basic cluster to test joining managed etcd
|
|
|
|
LABEL="ETCD-JOIN-BASIC" SERVER_ARGS="" run-test
|
|
|
|
|
|
|
|
# --- create a basic cluster to test joining a managed etcd cluster with --agent-token set
|
|
|
|
LABEL="ETCD-JOIN-AGENTTOKEN" SERVER_ARGS="--agent-token ${RANDOM}${RANDOM}${RANDOM}" run-test
|
|
|
|
|
2022-06-30 00:44:41 +00:00
|
|
|
# --- test joining managed etcd cluster with stable-version first server and current-build second server
|
|
|
|
server-post-hook() {
|
|
|
|
if [ $1 -eq 1 ]; then
|
|
|
|
local url=$(cat $TEST_DIR/servers/1/metadata/url)
|
|
|
|
export SERVER_ARGS="${SERVER_ARGS} --server $url"
|
|
|
|
export K3S_IMAGE_SERVER=${K3S_IMAGE}
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
export -f server-post-hook
|
|
|
|
LABEL="ETCD-JOIN-STABLE-FIRST" K3S_IMAGE_SERVER=${REPO}/${IMAGE_NAME}:${STABLE_VERSION} run-test
|
|
|
|
|
|
|
|
# --- test joining managed etcd cluster with current-build first server and stable-version second server
|
|
|
|
server-post-hook() {
|
|
|
|
if [ $1 -eq 1 ]; then
|
|
|
|
local url=$(cat $TEST_DIR/servers/1/metadata/url)
|
|
|
|
export SERVER_ARGS="${SERVER_ARGS} --server $url"
|
|
|
|
export K3S_IMAGE_SERVER=${K3S_IMAGE_SERVER_2}
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
export -f server-post-hook
|
|
|
|
LABEL="ETCD-JOIN-STABLE-SECOND" K3S_IMAGE_SERVER_2=${REPO}/${IMAGE_NAME}:${STABLE_VERSION} run-test
|
|
|
|
|
2022-01-07 00:05:59 +00:00
|
|
|
# --- test joining a managed etcd cluster with incompatible configuration
|
|
|
|
test-post-hook() {
|
|
|
|
if [[ $1 -eq 0 ]]; then
|
|
|
|
return
|
|
|
|
fi
|
2022-01-31 18:57:23 +00:00
|
|
|
dump-logs skip-output
|
2022-01-07 00:05:59 +00:00
|
|
|
grep -sqF 'critical configuration value mismatch' $TEST_DIR/servers/2/logs/system.log
|
|
|
|
}
|
|
|
|
export -f test-post-hook
|
|
|
|
LABEL="ETCD-JOIN-MISMATCH" SERVER_2_ARGS="--cluster-cidr 10.0.0.0/16" run-test
|
|
|
|
|
|
|
|
cleanup-test-env
|