Skip to content

Commit feb78dd

Browse files
committed
e2e: add scripts to run e2e tests with k3s
Scripts to run e2e tests on a vanilla node using k3s. Prepares k8s env based on the input from the project, builds the requires images, and runs e2e tests. Signed-off-by: Tuomas Katila <tuomas.katila@intel.com>
1 parent 323c1a1 commit feb78dd

File tree

11 files changed

+406
-36
lines changed

11 files changed

+406
-36
lines changed

.github/workflows/ci.yaml

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,30 @@ permissions:
1313
pull-requests: read
1414

1515
jobs:
16-
trivy:
17-
permissions:
18-
actions: read
19-
contents: read
20-
security-events: write
21-
uses: "./.github/workflows/lib-trivy.yaml"
16+
# trivy:
17+
# permissions:
18+
# actions: read
19+
# contents: read
20+
# security-events: write
21+
# uses: "./.github/workflows/lib-trivy.yaml"
2222

23-
validate:
24-
uses: "./.github/workflows/lib-validate.yaml"
23+
# validate:
24+
# uses: "./.github/workflows/lib-validate.yaml"
2525

26-
codeql:
27-
permissions:
28-
actions: read
29-
contents: read
30-
security-events: write
31-
uses: "./.github/workflows/lib-codeql.yaml"
26+
# codeql:
27+
# permissions:
28+
# actions: read
29+
# contents: read
30+
# security-events: write
31+
# uses: "./.github/workflows/lib-codeql.yaml"
3232

33-
build:
34-
needs:
35-
- trivy
36-
- validate
37-
uses: "./.github/workflows/lib-build.yaml"
38-
39-
# e2e:
33+
# build:
4034
# needs:
41-
# - build
42-
# uses: "./.github/workflows/lib-e2e.yaml"
35+
# - trivy
36+
# - validate
37+
# uses: "./.github/workflows/lib-build.yaml"
38+
39+
e2e:
40+
#needs:
41+
# - build
42+
uses: "./.github/workflows/lib-e2e.yaml"

.github/workflows/lib-e2e.yaml

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,9 @@ jobs:
1818
- intel-qat-plugin
1919
- intel-qat-initcontainer
2020
- openssl-qat-engine
21-
- intel-dsa-plugin
22-
- intel-idxd-config-initcontainer
2321
- accel-config-demo
24-
- dsa-dpdk-dmadevtest
2522
- intel-deviceplugin-operator
26-
- intel-iaa-plugin
2723
- crypto-perf
28-
- intel-gpu-plugin
29-
- intel-gpu-levelzero
3024
- intel-sgx-plugin
3125
- intel-sgx-initcontainer
3226
- intel-sgx-admissionwebhook
@@ -50,9 +44,5 @@ jobs:
5044
echo "SHA: ${{ github.sha }}"
5145
echo "Images: $IMAGES"
5246
echo "Target job: $TARGET_JOB"
53-
- name: Wait for ready state
54-
run: ../../../../bmetal/actions-bmetal-runstage.sh waitready
55-
- name: Prepare test environment
56-
run: ../../../../bmetal/actions-bmetal-runstage.sh prepare
57-
- name: Run tests
58-
run: ../../../../bmetal/actions-bmetal-runstage.sh test
47+
- name: Run e2e tests
48+
run: ./test/e2e/scripts/run.sh

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ e2e-iaa:
164164
@$(GO) test -v ./test/e2e/... -ginkgo.v -ginkgo.show-node-events -ginkgo.focus "Device:iaa.*$(ADDITIONAL_FOCUS_REGEX)" $(GENERATED_SKIP_OPT) -delete-namespace-on-failure=false
165165

166166
e2e-spr:
167-
@$(GO) test -v ./test/e2e/... -ginkgo.v -ginkgo.show-node-events -ginkgo.focus "Device:(iaa|dsa)|Device:qat.*Mode:dpdk.*Resource:(cy|dc).*" -ginkgo.focus "Device:sgx.*|(SGX Admission)" -ginkgo.focus "Device:gpu.*Resource:i915" $(GENERATED_SKIP_OPT) -delete-namespace-on-failure=false
167+
@$(GO) test -v ./test/e2e/... -ginkgo.v -ginkgo.show-node-events -ginkgo.focus "Device:qat.*Mode:dpdk.*Resource:(cy|dc).*" -ginkgo.focus "Device:sgx.*|(SGX Admission)" $(GENERATED_SKIP_OPT) -delete-namespace-on-failure=false
168168

169169
pre-pull:
170170
ifeq ($(TAG),devel)

test/e2e/scripts/build-images.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
script_path=$(dirname $(readlink -f $0))
4+
source $script_path/common.sh
5+
6+
cd $GITHUB_WORKSPACE
7+
8+
install_go
9+
10+
make set-version
11+
12+
print_large "Build and cache images"
13+
14+
prepare_to_build
15+
16+
for img in $IMAGES; do
17+
echo "Building $img with tag $TAG"
18+
make $img || exit 1
19+
done
20+
21+
print_large "build ok"
22+
23+
exit 0
24+

test/e2e/scripts/cache-images.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
script_path=$(dirname $(readlink -f $0))
4+
5+
source $script_path/common.sh
6+
7+
cd $GITHUB_WORKSPACE
8+
9+
for img in $IMAGES; do
10+
echo "Store image to cache"
11+
docker save intel/$img:$TAG | ctr -n k8s.io image import - || exit 1
12+
done

test/e2e/scripts/common.sh

Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
#!/bin/bash
2+
3+
collateral_path=$HOME/collaterals/
4+
5+
K8S_VERSION=""
6+
K3S_VERSION=""
7+
8+
fetch_current_k8s_version() {
9+
local version=$(yq .jobs.envtest.strategy.matrix.version[-1] $GITHUB_WORKSPACE/.github/workflows/lib-validate.yaml)
10+
11+
# cut the ".x" from the version
12+
version=$(echo $version | tr -d '"' | sed 's/\.x$//')
13+
14+
if [ -z "$version" ]; then
15+
echo "Couldn't find k8s version in the workflow file"
16+
exit 1
17+
fi
18+
19+
K8S_VERSION=$version
20+
}
21+
22+
k3s_version_for_k8s_version() {
23+
local requested=$K8S_VERSION
24+
25+
local known_versions="v1.34.1+k3s1;v1.33.5+k3s1;v1.32.9+k3s1;v1.31.9+k3s1;v1.30.13+k3s1"
26+
27+
local latest=$(echo $known_versions | tr ';' '\n' | grep "$requested" | head -1)
28+
if [ -z "$latest" ]; then
29+
echo "No k3s version found for requested k8s version $requested"
30+
31+
exit 1
32+
fi
33+
34+
K3S_VERSION=$latest
35+
}
36+
37+
download_k3s_binaries() {
38+
mkdir -p $collateral_path/k3s-cache
39+
40+
[ -e $collateral_path/k3s-cache/install-k3s.sh ] || {
41+
wget https://get.k3s.io/ -O $collateral_path/k3s-cache/install-k3s.sh || {
42+
echo "Failed to download k3s install script"
43+
exit 1
44+
}
45+
46+
chmod +x $collateral_path/k3s-cache/install-k3s.sh
47+
}
48+
49+
[ -e $collateral_path/k3s-cache/${K3S_VERSION} ] && {
50+
echo "Using cached k3s binary"
51+
return 0
52+
}
53+
54+
local k3s_ver_encoded=$(echo $K3S_VERSION | sed -e 's/+/\%2B/')
55+
56+
local k3s_url="https://github.com/k3s-io/k3s/releases/download/${k3s_ver_encoded}/k3s"
57+
local k3s_images_url="https://github.com/k3s-io/k3s/releases/download/${k3s_ver_encoded}/k3s-airgap-images-amd64.tar.zst"
58+
59+
mkdir -p $collateral_path/k3s-cache/${K3S_VERSION}
60+
61+
wget -q -O $collateral_path/k3s-cache/${K3S_VERSION}/k3s $k3s_url || {
62+
echo "Failed to download k3s binary from $k3s_url"
63+
exit 1
64+
}
65+
66+
wget -q -O $collateral_path/k3s-cache/${K3S_VERSION}/images.tar.zst $k3s_images_url || {
67+
echo "Failed to download k3s images from $k3s_images_url"
68+
exit 1
69+
}
70+
71+
return 0
72+
}
73+
74+
print_large() {
75+
type figlet 2>&1 > /dev/null && {
76+
figlet "$@"
77+
} || {
78+
echo "========================================"
79+
echo "$@"
80+
echo "========================================"
81+
}
82+
}
83+
84+
wait_for_cluster_to_be_ready() {
85+
echo "Waiting for cluster to become accessible"
86+
87+
for i in $(seq 60); do
88+
kubectl get pods -A 2>&1 | grep -q "No resources found" || {
89+
echo "Cluster is accessible"
90+
break
91+
}
92+
93+
echo -n "."
94+
sleep 1
95+
done
96+
97+
echo "Waiting for Pods to become ready"
98+
99+
for i in $(seq 60); do
100+
sleep 1
101+
echo -n "."
102+
103+
allcount=$(kubectl get pods -A | grep -v NAMESPACE | wc -l)
104+
notreadycount=$(kubectl get pods -A | grep -v NAMESPACE | grep -v -e Complete -e Running | wc -l)
105+
106+
if [ $allcount -lt 7 ]; then
107+
continue
108+
fi
109+
110+
if [ $allcount -lt 7 ]; then
111+
continue
112+
fi
113+
114+
if [ $notreadycount -eq 0 ]; then
115+
echo "READY"
116+
117+
return 0
118+
fi
119+
done
120+
121+
echo "\nCluster did not become ready.."
122+
123+
return 1
124+
}
125+
126+
prepare_cluster() {
127+
print_large "Prepare cluster"
128+
129+
echo "Versions: $K3S_VERSION & $K8S_VERSION"
130+
131+
[ -e /usr/local/bin/k3s-uninstall.sh ] && {
132+
echo "Found existing k3s install, removing it"
133+
134+
k3s-uninstall.sh || exit 1
135+
}
136+
137+
echo "prepare images"
138+
sudo mkdir -p /var/lib/rancher/k3s/agent/images/ && \
139+
sudo cp $collateral_path/k3s-cache/$K3S_VERSION/images.tar.zst /var/lib/rancher/k3s/agent/images/k3s-airgap-images-amd64.tar.zst || exit 1
140+
sudo cp $collateral_path/k3s-cache/$K3S_VERSION/k3s /usr/local/bin/ || exit 1
141+
sudo chmod +x /usr/local/bin/k3s || exit 1
142+
143+
echo "prepare k3s cluster"
144+
INSTALL_K3S_SKIP_DOWNLOAD=true $collateral_path/k3s-cache/install-k3s.sh
145+
echo $?
146+
sudo chmod +r /etc/rancher/k3s/k3s.yaml
147+
echo $?
148+
sudo chmod o+rw /run/k3s/containerd/containerd.sock
149+
echo $?
150+
151+
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
152+
153+
wait_for_cluster_to_be_ready || exit 1
154+
155+
kubectl get nodes -o wide
156+
kubectl get pods -A
157+
}
158+
159+
install_go() {
160+
local go_version=$(grep "^go " $GITHUB_WORKSPACE/go.mod | head -1 | cut -c 4-)
161+
[ -e $collateral_path/go$go_version.linux-amd64.tar.gz ] || {
162+
wget -q https://go.dev/dl/go$go_version.linux-amd64.tar.gz -O $collateral_path/go$go_version.linux-amd64.tar.gz || exit 1
163+
}
164+
165+
mkdir -p ~/bin
166+
tar -xf $collateral_path/go$go_version.linux-amd64.tar.gz -C ~/bin || exit 1
167+
168+
export PATH=$PATH:~/bin/go/bin
169+
170+
type go || {
171+
echo "Go installation failed"
172+
exit 1
173+
}
174+
175+
go version || exit 1
176+
}
177+
178+
install_k8s_deps() {
179+
print_large "Install cert-manager"
180+
kubectl apply --wait -f https://github.com/cert-manager/cert-manager/releases/download/v1.18.0/cert-manager.yaml || exit 1
181+
}
182+
183+
prepare_to_build() {
184+
echo "Download licenses"
185+
186+
if [ -e $collateral_path/licenses ]; then
187+
echo ">> Copy from cache"
188+
cp -a $collateral_path/licenses $GITHUB_WORKSPACE/licenses
189+
else
190+
echo ">> Download from internet"
191+
make licenses || exit 1
192+
chmod -R a+rw $GITHUB_WORKSPACE/licenses
193+
194+
mkdir -p $collateral_path && cp -a $GITHUB_WORKSPACE/licenses $collateral_path/licenses || exit 1
195+
fi
196+
}
197+
198+
generate_tag() {
199+
local BUILD_VERSION=$(grep -r --include="*.go" 'ImageMinVersion =' ${GITHUB_WORKSPACE} | head -1 | sed -e 's/.*"\(.*\)".*/\1/' | awk -F. '{ printf "%s.%s.%s\n", $1, $2, ($3 + 1) }')
200+
201+
BUILD_VERSION=$BUILD_VERSION-$GITHUB_RUN_NUMBER-$RANDOM
202+
203+
export TAG=$BUILD_VERSION
204+
}
205+
206+
cache_shared_images() {
207+
echo "Cache shared images"
208+
209+
local SHARED_IMAGES="intel/intel-extension-for-pytorch:2.8.10-xpu"
210+
211+
for image in $(echo $SHARED_IMAGES);
212+
do
213+
echo "Downloading and caching $image"
214+
docker pull $image
215+
docker save $image | sudo ctr -n k8s.io image import -
216+
done
217+
}

test/e2e/scripts/install-deps.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
sudo apt install figlet docker.io git yq make
4+
5+
mkdir ~/collaterals

test/e2e/scripts/prepare-env.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
script_path=$(dirname $(readlink -f $0))
4+
5+
source $script_path/common.sh
6+
7+
cd $GITHUB_WORKSPACE
8+
9+
fetch_current_k8s_version
10+
11+
echo $K8S_VERSION
12+
13+
k3s_version_for_k8s_version
14+
15+
echo $K3S_VERSION
16+
17+
download_k3s_binaries
18+
19+
sudo cp $collateral_path/k3s-cache/$K3S_VERSION/k3s /usr/local/bin/k3s || exit 1
20+
21+
prepare_cluster
22+
23+
install_k8s_deps
24+
25+
# For GPU pytorch
26+
#cache_shared_images
27+
28+
install_go
29+
30+
exit 0

test/e2e/scripts/prune-images.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
docker system prune -f | tail -2 || {
4+
echo "Docker prune failed, exiting"
5+
exit 1
6+
}
7+
8+
exit 0

0 commit comments

Comments
 (0)