You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
k3s/scripts/build-tests-sonobuoy

67 lines
2.2 KiB

#!/bin/bash
set -e
cd $(dirname $0)/..
REPO="k3s-int-tests"
OUTFILE="./dist/artifacts/k3s-int-tests.yaml"
# Compile all integration tests and containerize them
mkdir -p dist/artifacts
go test -c -v -ldflags "-X 'github.com/rancher/k3s/tests/util.existingServer=True'" -o dist/artifacts/k3s-integration-1.test ./tests/integration/... -run Integration
PKG_TO_TEST=$(find ./pkg/ -type f -name "*_int_test.go" | sed -r 's|/[^/]+$||' |sort -u)
INDEX=1
for i in $PKG_TO_TEST; do
echo $i
go test -c -v -ldflags "-X 'github.com/rancher/k3s/tests/util.existingServer=True'" -o dist/artifacts/k3s-integration-$INDEX.test $i -run Integration
INDEX=$(expr $INDEX + 1)
done
go test -c -v -ldflags "-X 'github.com/rancher/k3s/tests/util.existingServer=True'" -o dist/artifacts/k3s-integration-$INDEX.test ./tests/integration/... -run Integration
docker build -f ./tests/integration/Dockerfile.test -t $REPO .
docker save $REPO -o ./dist/artifacts/$REPO.tar
sudo mkdir -p /var/lib/rancher/k3s/agent/images
sudo mv ./dist/artifacts/$REPO.tar /var/lib/rancher/k3s/agent/images/
# If k3s is already running, attempt to import the image
if [[ "$(pgrep k3s | wc -l)" -gt 0 ]]; then
sudo ./dist/artifacts/k3s ctr images import /var/lib/rancher/k3s/agent/images/$REPO.tar
fi
# Cleanup compiled tests
rm dist/artifacts/k3s-integration-*
# Generate the sonobuoy plugin and inject the necessary
# podSpec and volume mount modifications
PODSPEC=\
' hostNetwork: true
volumes:
- name: var-k3s
hostPath:
path: /var/lib/rancher/k3s/
type: Directory
- name: etc-k3s
hostPath:
path: /etc/rancher/k3s/
type: Directory'
VOLMOUNTS=\
' - mountPath: /var/lib/rancher/k3s/
name: var-k3s
- mountPath: /etc/rancher/k3s/
name: etc-k3s'
sonobuoy gen plugin \
--format=junit \
--image ${REPO} \
--show-default-podspec \
--name k3s-int \
--type job \
--cmd ./test-runner.sh \
--env KUBECONFIG=/etc/rancher/k3s/k3s.yaml \
> $OUTFILE
awk -v PS="$PODSPEC" '/podSpec:/{print;print PS;next}1' $OUTFILE > ./dist/artifacts/temp.yaml
mv ./dist/artifacts/temp.yaml $OUTFILE
awk -v VM="$VOLMOUNTS" '/volumeMounts:/{print;print VM;next}1' $OUTFILE > ./dist/artifacts/temp.yaml
mv ./dist/artifacts/temp.yaml $OUTFILE