mirror of
https://github.com/k3s-io/k3s.git
synced 2024-06-07 19:41:36 +00:00
Bump test framework versions and add hooks to helpers
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
This commit is contained in:
parent
31539b7937
commit
f96d86f077
@ -15,9 +15,9 @@ ENTRYPOINT ["/bin/test-mods"]
|
|||||||
|
|
||||||
From test-base as test-k3s
|
From test-base as test-k3s
|
||||||
|
|
||||||
RUN apk -U --no-cache add git gcc musl-dev docker curl coreutils python3 openssl py3-pip procps
|
RUN apk -U --no-cache add git gcc musl-dev docker curl coreutils python3 openssl py3-pip procps findutils
|
||||||
|
|
||||||
ENV SONOBUOY_VERSION 0.56.5
|
ENV SONOBUOY_VERSION 0.56.10
|
||||||
|
|
||||||
RUN OS=linux; \
|
RUN OS=linux; \
|
||||||
ARCH=$(go env GOARCH); \
|
ARCH=$(go env GOARCH); \
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
FROM alpine:3.16
|
FROM alpine:3.16
|
||||||
ENV SONOBUOY_VERSION 0.56.5
|
ENV SONOBUOY_VERSION 0.56.10
|
||||||
RUN apk add curl tar gzip
|
RUN apk add curl tar gzip
|
||||||
RUN curl -sfL https://github.com/vmware-tanzu/sonobuoy/releases/download/v${SONOBUOY_VERSION}/sonobuoy_${SONOBUOY_VERSION}_linux_amd64.tar.gz | tar xvzf - -C /usr/bin
|
RUN curl -sfL https://github.com/vmware-tanzu/sonobuoy/releases/download/v${SONOBUOY_VERSION}/sonobuoy_${SONOBUOY_VERSION}_linux_amd64.tar.gz | tar xvzf - -C /usr/bin
|
||||||
COPY run-test.sh /usr/bin
|
COPY run-test.sh /usr/bin
|
||||||
|
@ -263,7 +263,6 @@ test-cleanup() {
|
|||||||
echo 'Cleaning up...'
|
echo 'Cleaning up...'
|
||||||
trap - EXIT INT TERM
|
trap - EXIT INT TERM
|
||||||
if has-function test-post-hook; then
|
if has-function test-post-hook; then
|
||||||
echo 'Running post-hook'
|
|
||||||
test-post-hook $code
|
test-post-hook $code
|
||||||
code=$?
|
code=$?
|
||||||
fi
|
fi
|
||||||
@ -276,6 +275,9 @@ test-cleanup() {
|
|||||||
echo "Removing container $container"
|
echo "Removing container $container"
|
||||||
docker rm -f -v $container
|
docker rm -f -v $container
|
||||||
done
|
done
|
||||||
|
if has-function test-cleanup-hook; then
|
||||||
|
test-cleanup-hook
|
||||||
|
fi
|
||||||
echo
|
echo
|
||||||
if [ "$TEST_CLEANUP" = true ]; then
|
if [ "$TEST_CLEANUP" = true ]; then
|
||||||
echo "Removing test directory $TEST_DIR"
|
echo "Removing test directory $TEST_DIR"
|
||||||
@ -336,68 +338,6 @@ export -f test-setup
|
|||||||
|
|
||||||
# ---
|
# ---
|
||||||
|
|
||||||
gen-certs() {(
|
|
||||||
set -e -x
|
|
||||||
#umask 077
|
|
||||||
|
|
||||||
local opensslConfig=$(pwd)/scripts/test-certs-openssl.cnf
|
|
||||||
local subject="/C=US/ST=AZ/L=Tempe/O=Rancher/OU=DevOps/DC=com/DC=rancher"
|
|
||||||
local caDir=$TEST_DIR/db-ca
|
|
||||||
[ -d $caDir ] && rm -rf $caDir
|
|
||||||
mkdir -p $caDir
|
|
||||||
|
|
||||||
cd $caDir
|
|
||||||
mkdir -p private certs newcerts crl
|
|
||||||
touch index.txt
|
|
||||||
echo '01' > serial
|
|
||||||
|
|
||||||
openssl req \
|
|
||||||
-config $opensslConfig \
|
|
||||||
-new -x509 \
|
|
||||||
-nodes \
|
|
||||||
-subj $subject \
|
|
||||||
-extensions v3_ca \
|
|
||||||
-keyout private/ca.key \
|
|
||||||
-out certs/ca.crt
|
|
||||||
|
|
||||||
openssl req \
|
|
||||||
-config $opensslConfig \
|
|
||||||
-new \
|
|
||||||
-nodes \
|
|
||||||
-subj $subject"/CN=server" \
|
|
||||||
-keyout private/db.key \
|
|
||||||
-out db.csr
|
|
||||||
|
|
||||||
openssl ca \
|
|
||||||
-config $opensslConfig \
|
|
||||||
-batch \
|
|
||||||
-extensions db_server \
|
|
||||||
-keyfile private/ca.key \
|
|
||||||
-cert certs/ca.crt \
|
|
||||||
-out certs/db.crt \
|
|
||||||
-infiles db.csr
|
|
||||||
|
|
||||||
openssl req \
|
|
||||||
-config $opensslConfig \
|
|
||||||
-new \
|
|
||||||
-nodes \
|
|
||||||
-subj $subject"/CN=client" \
|
|
||||||
-keyout private/client.key \
|
|
||||||
-out client.csr
|
|
||||||
|
|
||||||
openssl ca \
|
|
||||||
-config $opensslConfig \
|
|
||||||
-batch \
|
|
||||||
-extensions db_client \
|
|
||||||
-keyfile private/ca.key \
|
|
||||||
-cert certs/ca.crt \
|
|
||||||
-out certs/client.crt \
|
|
||||||
-infiles client.csr
|
|
||||||
)}
|
|
||||||
export -f gen-certs
|
|
||||||
|
|
||||||
# ---
|
|
||||||
|
|
||||||
inc-count() {(
|
inc-count() {(
|
||||||
shopt -s extglob
|
shopt -s extglob
|
||||||
local count=$(exec 2>/dev/null; ls -1d $TEST_DIR/$1/+([0-9]) | xargs -n1 basename | sort -n -r | head -1)
|
local count=$(exec 2>/dev/null; ls -1d $TEST_DIR/$1/+([0-9]) | xargs -n1 basename | sort -n -r | head -1)
|
||||||
@ -427,7 +367,7 @@ export -f run-function
|
|||||||
provision-server() {
|
provision-server() {
|
||||||
local count=$(inc-count servers)
|
local count=$(inc-count servers)
|
||||||
local testID=$(basename $TEST_DIR)
|
local testID=$(basename $TEST_DIR)
|
||||||
local name=$(echo "k3s-server-$count-$testID" | tee $TEST_DIR/servers/$count/metadata/name)
|
local name=$(echo "k3s-server-${count}-${testID,,}" | tee $TEST_DIR/servers/$count/metadata/name)
|
||||||
local port=$(timeout --foreground 5s bash -c get-port | tee $TEST_DIR/servers/$count/metadata/port)
|
local port=$(timeout --foreground 5s bash -c get-port | tee $TEST_DIR/servers/$count/metadata/port)
|
||||||
local SERVER_INSTANCE_ARGS="SERVER_${count}_ARGS"
|
local SERVER_INSTANCE_ARGS="SERVER_${count}_ARGS"
|
||||||
|
|
||||||
@ -435,14 +375,15 @@ provision-server() {
|
|||||||
|
|
||||||
docker run \
|
docker run \
|
||||||
-d --name $name \
|
-d --name $name \
|
||||||
|
--hostname $name \
|
||||||
--privileged \
|
--privileged \
|
||||||
-v $TEST_DIR/db-ca/:/db-ca \
|
|
||||||
-p 127.0.0.1:$port:6443 \
|
-p 127.0.0.1:$port:6443 \
|
||||||
-p 6443 \
|
-p 6443 \
|
||||||
-e K3S_TOKEN=$(cat $TEST_DIR/metadata/secret) \
|
-e K3S_TOKEN=$(cat $TEST_DIR/metadata/secret) \
|
||||||
-e K3S_DEBUG=true \
|
-e K3S_DEBUG=true \
|
||||||
|
${SERVER_DOCKER_ARGS:-} \
|
||||||
${REGISTRY_CLUSTER_ARGS:-} \
|
${REGISTRY_CLUSTER_ARGS:-} \
|
||||||
${K3S_IMAGE_SERVER:-$K3S_IMAGE} server $ARGS $SERVER_ARGS ${!SERVER_INSTANCE_ARGS}
|
${K3S_IMAGE_SERVER:-$K3S_IMAGE} server ${ARGS} ${SERVER_ARGS} ${!SERVER_INSTANCE_ARGS}
|
||||||
|
|
||||||
local ip=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' $name | tee $TEST_DIR/servers/$count/metadata/ip)
|
local ip=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' $name | tee $TEST_DIR/servers/$count/metadata/ip)
|
||||||
local url=$(echo "https://$ip:6443" | tee $TEST_DIR/servers/$count/metadata/url)
|
local url=$(echo "https://$ip:6443" | tee $TEST_DIR/servers/$count/metadata/url)
|
||||||
@ -458,17 +399,21 @@ provision-agent() {
|
|||||||
local K3S_URL=${K3S_URL:-"$(cat $TEST_DIR/servers/1/metadata/url)"}
|
local K3S_URL=${K3S_URL:-"$(cat $TEST_DIR/servers/1/metadata/url)"}
|
||||||
local count=$(inc-count agents)
|
local count=$(inc-count agents)
|
||||||
local testID=$(basename $TEST_DIR)
|
local testID=$(basename $TEST_DIR)
|
||||||
local name=$(echo "k3s-agent-$count-$testID" | tee $TEST_DIR/agents/$count/metadata/name)
|
local name=$(echo "k3s-agent-${count}-${testID,,}" | tee $TEST_DIR/agents/$count/metadata/name)
|
||||||
local AGENT_INSTANCE_ARGS="AGENT_${count}_ARGS"
|
local AGENT_INSTANCE_ARGS="AGENT_${count}_ARGS"
|
||||||
|
|
||||||
run-function agent-pre-hook $count
|
run-function agent-pre-hook $count
|
||||||
docker run \
|
docker run \
|
||||||
-d --name $name \
|
-d --name $name \
|
||||||
|
--hostname $name \
|
||||||
--privileged \
|
--privileged \
|
||||||
-e K3S_TOKEN=$(cat $TEST_DIR/metadata/secret) \
|
-e K3S_TOKEN=$(cat $TEST_DIR/metadata/secret) \
|
||||||
-e K3S_URL=$K3S_URL \
|
-e K3S_URL=$K3S_URL \
|
||||||
|
${AGENT_DOCKER_ARGS:-} \
|
||||||
${REGISTRY_CLUSTER_ARGS:-} \
|
${REGISTRY_CLUSTER_ARGS:-} \
|
||||||
${K3S_IMAGE_AGENT:-$K3S_IMAGE} agent $ARGS $AGENT_ARGS ${!AGENT_INSTANCE_ARGS}
|
${K3S_IMAGE_AGENT:-$K3S_IMAGE} agent ${ARGS} ${AGENT_ARGS} ${!AGENT_INSTANCE_ARGS}
|
||||||
|
|
||||||
|
local ip=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' $name | tee $TEST_DIR/agents/$count/metadata/ip)
|
||||||
|
|
||||||
echo "Started $name"
|
echo "Started $name"
|
||||||
run-function agent-post-hook $count
|
run-function agent-post-hook $count
|
||||||
@ -592,10 +537,10 @@ cleanup-test-env(){
|
|||||||
export SERVER_ARGS=''
|
export SERVER_ARGS=''
|
||||||
export WAIT_SERVICES="${all_services[@]}"
|
export WAIT_SERVICES="${all_services[@]}"
|
||||||
|
|
||||||
unset AGENT_1_ARGS AGENT_2_ARGS AGENT_3_ARGS
|
unset AGENT_1_ARGS AGENT_2_ARGS AGENT_3_ARGS AGENT_DOCKER_ARGS
|
||||||
unset SERVER_1_ARGS SERVER_2_ARGS SERVER_3_ARGS
|
unset SERVER_1_ARGS SERVER_2_ARGS SERVER_3_ARGS SERVER_DOCKER_ARGS
|
||||||
|
|
||||||
unset -f server-pre-hook server-post-hook agent-pre-hook agent-post-hook cluster-pre-hook cluster-post-hook test-post-hook
|
unset -f server-pre-hook server-post-hook agent-pre-hook agent-post-hook cluster-pre-hook cluster-post-hook test-post-hook test-cleanup-hook
|
||||||
}
|
}
|
||||||
|
|
||||||
# ---
|
# ---
|
||||||
|
@ -5,26 +5,19 @@
|
|||||||
# ---
|
# ---
|
||||||
|
|
||||||
cluster-pre-hook() {
|
cluster-pre-hook() {
|
||||||
# gen-certs
|
|
||||||
|
|
||||||
mkdir -p $TEST_DIR/db/$LABEL_SUFFIX/metadata
|
mkdir -p $TEST_DIR/db/$LABEL_SUFFIX/metadata
|
||||||
local testID=$(basename $TEST_DIR)
|
local testID=$(basename $TEST_DIR)
|
||||||
local name=$(echo $LABEL_SUFFIX-$testID | tee $TEST_DIR/db/$LABEL_SUFFIX/metadata/name)
|
local name=$(echo ${LABEL_SUFFIX}-${testID,,} | tee $TEST_DIR/db/$LABEL_SUFFIX/metadata/name)
|
||||||
local port=$(timeout --foreground 5s bash -c get-port | tee $TEST_DIR/db/$LABEL_SUFFIX/metadata/port)
|
local port=$(timeout --foreground 5s bash -c get-port | tee $TEST_DIR/db/$LABEL_SUFFIX/metadata/port)
|
||||||
local secret=$(echo "${RANDOM}${RANDOM}${RANDOM}" | tee $TEST_DIR/db/$LABEL_SUFFIX/metadata/secret)
|
local secret=$(echo "${RANDOM}${RANDOM}${RANDOM}" | tee $TEST_DIR/db/$LABEL_SUFFIX/metadata/secret)
|
||||||
|
|
||||||
docker run --name $name \
|
docker run --name $name \
|
||||||
--privileged \
|
--privileged \
|
||||||
-p 0.0.0.0:$port:3306 \
|
-p 0.0.0.0:$port:3306 \
|
||||||
-v $TEST_DIR/db-ca/:/db-ca \
|
|
||||||
-e MYSQL_ROOT_PASSWORD=$secret \
|
-e MYSQL_ROOT_PASSWORD=$secret \
|
||||||
-e MYSQL_ROOT_HOST=% \
|
-e MYSQL_ROOT_HOST=% \
|
||||||
-d mysql:latest \
|
-d mysql:latest \
|
||||||
>/dev/null
|
>/dev/null
|
||||||
# --require-secure-transport=ON \
|
|
||||||
# --ssl-ca /db-ca/certs/ca.crt \
|
|
||||||
# --ssl-cert /db-ca/certs/db.crt \
|
|
||||||
# --ssl-key /db-ca/private/db.key \
|
|
||||||
|
|
||||||
local ip=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' $name | tee $TEST_DIR/db/$LABEL_SUFFIX/metadata/ip)
|
local ip=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' $name | tee $TEST_DIR/db/$LABEL_SUFFIX/metadata/ip)
|
||||||
# local host=host.docker.internal
|
# local host=host.docker.internal
|
||||||
@ -32,7 +25,6 @@ cluster-pre-hook() {
|
|||||||
|
|
||||||
DB_CONNECTION_TEST="
|
DB_CONNECTION_TEST="
|
||||||
docker run
|
docker run
|
||||||
-v $TEST_DIR/db-ca/:/db-ca
|
|
||||||
--rm mysql
|
--rm mysql
|
||||||
mysql
|
mysql
|
||||||
-h$host
|
-h$host
|
||||||
@ -41,17 +33,11 @@ cluster-pre-hook() {
|
|||||||
-p$secret
|
-p$secret
|
||||||
-e status" \
|
-e status" \
|
||||||
timeout --foreground 1m bash -c "wait-for-db-connection"
|
timeout --foreground 1m bash -c "wait-for-db-connection"
|
||||||
# --ssl-ca /db-ca/certs/ca.crt
|
|
||||||
# --ssl-cert /db-ca/certs/client.crt
|
|
||||||
# --ssl-key /db-ca/private/client.key
|
|
||||||
|
|
||||||
echo "Started $LABEL_SUFFIX db @ $host"
|
echo "Started $LABEL_SUFFIX db @ $host"
|
||||||
export SERVER_ARGS="${SERVER_ARGS}
|
export SERVER_ARGS="${SERVER_ARGS}
|
||||||
--datastore-endpoint=mysql://root:$secret@tcp($host:$port)/testdb
|
--datastore-endpoint=mysql://root:$secret@tcp($host:$port)/testdb
|
||||||
"
|
"
|
||||||
# --datastore-cafile /db-ca/certs/ca.crt
|
|
||||||
# --datastore-certfile /db-ca/certs/client.crt
|
|
||||||
# --datastore-keyfile /db-ca/private/client.key
|
|
||||||
}
|
}
|
||||||
export -f cluster-pre-hook
|
export -f cluster-pre-hook
|
||||||
|
|
||||||
|
@ -5,26 +5,19 @@
|
|||||||
# ---
|
# ---
|
||||||
|
|
||||||
cluster-pre-hook() {
|
cluster-pre-hook() {
|
||||||
# gen-certs
|
|
||||||
|
|
||||||
mkdir -p $TEST_DIR/db/$LABEL_SUFFIX/metadata
|
mkdir -p $TEST_DIR/db/$LABEL_SUFFIX/metadata
|
||||||
local testID=$(basename $TEST_DIR)
|
local testID=$(basename $TEST_DIR)
|
||||||
local name=$(echo $LABEL_SUFFIX-$testID | tee $TEST_DIR/db/$LABEL_SUFFIX/metadata/name)
|
local name=$(echo ${LABEL_SUFFIX}-${testID,,} | tee $TEST_DIR/db/$LABEL_SUFFIX/metadata/name)
|
||||||
local port=$(timeout --foreground 5s bash -c get-port | tee $TEST_DIR/db/$LABEL_SUFFIX/metadata/port)
|
local port=$(timeout --foreground 5s bash -c get-port | tee $TEST_DIR/db/$LABEL_SUFFIX/metadata/port)
|
||||||
local secret=$(echo "${RANDOM}${RANDOM}${RANDOM}" | tee $TEST_DIR/db/$LABEL_SUFFIX/metadata/secret)
|
local secret=$(echo "${RANDOM}${RANDOM}${RANDOM}" | tee $TEST_DIR/db/$LABEL_SUFFIX/metadata/secret)
|
||||||
|
|
||||||
docker run --name $name \
|
docker run --name $name \
|
||||||
--privileged \
|
--privileged \
|
||||||
-p 0.0.0.0:$port:5432 \
|
-p 0.0.0.0:$port:5432 \
|
||||||
-v $TEST_DIR/db-ca/:/db-ca \
|
|
||||||
-e POSTGRES_USER=root \
|
-e POSTGRES_USER=root \
|
||||||
-e POSTGRES_PASSWORD=$secret \
|
-e POSTGRES_PASSWORD=$secret \
|
||||||
-d postgres:latest \
|
-d postgres:latest \
|
||||||
>/dev/null
|
>/dev/null
|
||||||
# -c ssl=on \
|
|
||||||
# -c ssl_ca_file=/db-ca/certs/ca.crt \
|
|
||||||
# -c ssl_cert_file=/db-ca/certs/db.crt \
|
|
||||||
# -c ssl_key_file=/db-ca/private/db.key \
|
|
||||||
|
|
||||||
local ip=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' $name | tee $TEST_DIR/db/$LABEL_SUFFIX/metadata/ip)
|
local ip=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' $name | tee $TEST_DIR/db/$LABEL_SUFFIX/metadata/ip)
|
||||||
# local host=host.docker.internal
|
# local host=host.docker.internal
|
||||||
@ -32,7 +25,6 @@ cluster-pre-hook() {
|
|||||||
|
|
||||||
DB_CONNECTION_TEST="
|
DB_CONNECTION_TEST="
|
||||||
docker run
|
docker run
|
||||||
-v $TEST_DIR/db-ca/:/db-ca
|
|
||||||
-e PGPASSWORD=$secret
|
-e PGPASSWORD=$secret
|
||||||
--rm postgres
|
--rm postgres
|
||||||
psql
|
psql
|
||||||
@ -41,17 +33,11 @@ cluster-pre-hook() {
|
|||||||
-U root
|
-U root
|
||||||
-c \conninfo" \
|
-c \conninfo" \
|
||||||
timeout --foreground 1m bash -c "wait-for-db-connection"
|
timeout --foreground 1m bash -c "wait-for-db-connection"
|
||||||
# --set sslrootcert=/db-ca/certs/ca.crt
|
|
||||||
# --set sslcert=/db-ca/certs/client.crt
|
|
||||||
# --set sslkey=/db-ca/private/client.key
|
|
||||||
|
|
||||||
echo "Started $LABEL_SUFFIX db @ $host"
|
echo "Started $LABEL_SUFFIX db @ $host"
|
||||||
export SERVER_ARGS="${SERVER_ARGS}
|
export SERVER_ARGS="${SERVER_ARGS}
|
||||||
--datastore-endpoint=postgres://root:$secret@$host:$port/testdb?sslmode=disable
|
--datastore-endpoint=postgres://root:$secret@$host:$port/testdb?sslmode=disable
|
||||||
"
|
"
|
||||||
# --datastore-cafile /db-ca/certs/ca.crt
|
|
||||||
# --datastore-certfile /db-ca/certs/client.crt
|
|
||||||
# --datastore-keyfile /db-ca/private/client.key
|
|
||||||
}
|
}
|
||||||
export -f cluster-pre-hook
|
export -f cluster-pre-hook
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user