Skip to content

Commit e0d9e10

Browse files
authored
Merge pull request #2148 from tkatila/reintroduce-e2e
e2e: add scripts to run e2e tests with k3s
2 parents 7168e39 + 8c44f38 commit e0d9e10

File tree

12 files changed

+424
-23
lines changed

12 files changed

+424
-23
lines changed

.github/workflows/ci.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
- validate
3737
uses: "./.github/workflows/lib-build.yaml"
3838

39-
# e2e:
40-
# needs:
41-
# - build
42-
# uses: "./.github/workflows/lib-e2e.yaml"
39+
e2e:
40+
needs:
41+
- build
42+
uses: "./.github/workflows/lib-e2e.yaml"

.github/workflows/devel.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,18 @@ jobs:
3939
- trivy
4040
uses: "./.github/workflows/lib-build.yaml"
4141

42-
# e2e:
43-
# needs:
44-
# - build
45-
# uses: "./.github/workflows/lib-e2e.yaml"
42+
e2e:
43+
needs:
44+
- build
45+
uses: "./.github/workflows/lib-e2e.yaml"
4646

4747
# devel image push
4848
publish:
4949
permissions:
5050
contents: read
5151
id-token: write
5252
needs:
53-
# - e2e
53+
- e2e
5454
- build
5555
uses: "./.github/workflows/lib-publish.yaml"
5656
secrets: inherit

.github/workflows/lib-e2e.yaml

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,16 @@ jobs:
1212
matrix:
1313
include:
1414
- name: e2e-spr
15-
targetjob: e2e-spr SKIP="App:compress-perf"
15+
targetjob: e2e-spr
1616
runner: spr
17+
skip: App:compress-perf
1718
images:
1819
- intel-qat-plugin
1920
- intel-qat-initcontainer
2021
- openssl-qat-engine
21-
- intel-dsa-plugin
22-
- intel-idxd-config-initcontainer
2322
- accel-config-demo
24-
- dsa-dpdk-dmadevtest
2523
- intel-deviceplugin-operator
26-
- intel-iaa-plugin
2724
- crypto-perf
28-
- intel-gpu-plugin
29-
- intel-gpu-levelzero
3025
- intel-sgx-plugin
3126
- intel-sgx-initcontainer
3227
- intel-sgx-admissionwebhook
@@ -37,6 +32,7 @@ jobs:
3732
env:
3833
TARGET_JOB: ${{ matrix.targetjob || matrix.name }}
3934
IMAGES: ${{ join(matrix.images, ' ') }}
35+
SKIP: ${{ matrix.skip || '' }}
4036

4137
steps:
4238
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v4
@@ -50,9 +46,5 @@ jobs:
5046
echo "SHA: ${{ github.sha }}"
5147
echo "Images: $IMAGES"
5248
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
49+
- name: Run e2e tests
50+
run: ./test/e2e/scripts/run.sh

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,9 @@ e2e-dsa:
163163
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

166+
# This is a CI specific target to run all tests that are possible in the SPR host
166167
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
168+
@$(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
168169

169170
pre-pull:
170171
ifeq ($(TAG),devel)

test/e2e/scripts/build-images.sh

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

test/e2e/scripts/cache-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+
cd "$GITHUB_WORKSPACE" || exit 1
4+
5+
for img in $IMAGES; do
6+
echo "Store image to cache: $img:$TAG"
7+
docker save intel/$img:$TAG | ctr -n k8s.io image import - || exit 1
8+
done

test/e2e/scripts/common.sh

Lines changed: 254 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,254 @@
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
10+
11+
version=$(yq .jobs.envtest.strategy.matrix.version[-1] $GITHUB_WORKSPACE/.github/workflows/lib-validate.yaml)
12+
13+
# cut the ".x" from the version
14+
version=$(echo $version | tr -d '"' | sed 's/\.x$//')
15+
16+
if [ -z "$version" ]; then
17+
echo "Couldn't find k8s version in the workflow file"
18+
19+
return 1
20+
fi
21+
22+
K8S_VERSION=$version
23+
}
24+
25+
k3s_version_for_k8s_version() {
26+
local requested="$K8S_VERSION"
27+
28+
local known_versions
29+
30+
known_versions="v1.34.1+k3s1;v1.33.5+k3s1;v1.32.9+k3s1;v1.31.9+k3s1;v1.30.13+k3s1"
31+
32+
local latest
33+
latest=$(echo $known_versions | tr ';' '\n' | grep "$requested" | head -1)
34+
if [ -z "$latest" ]; then
35+
echo "No k3s version found for requested k8s version $requested"
36+
37+
return 1
38+
fi
39+
40+
K3S_VERSION=$latest
41+
}
42+
43+
download_k3s_binaries() {
44+
mkdir -p $collateral_path/k3s-cache
45+
46+
[ -e $collateral_path/k3s-cache/install-k3s.sh ] || {
47+
wget https://get.k3s.io/ -O $collateral_path/k3s-cache/install-k3s.sh || {
48+
echo "Failed to download k3s install script"
49+
50+
return 1
51+
}
52+
53+
chmod +x $collateral_path/k3s-cache/install-k3s.sh
54+
}
55+
56+
[ -e $collateral_path/k3s-cache/${K3S_VERSION} ] && {
57+
echo "Using cached k3s binary"
58+
59+
return 0
60+
}
61+
62+
local k3s_ver_encoded
63+
64+
k3s_ver_encoded=$(echo "$K3S_VERSION" | sed -e 's/+/\%2B/')
65+
66+
local k3s_url
67+
k3s_url="https://github.com/k3s-io/k3s/releases/download/${k3s_ver_encoded}/k3s"
68+
69+
local k3s_images_url
70+
k3s_images_url="https://github.com/k3s-io/k3s/releases/download/${k3s_ver_encoded}/k3s-airgap-images-amd64.tar.zst"
71+
72+
mkdir -p $collateral_path/k3s-cache/${K3S_VERSION}
73+
74+
wget -q -O $collateral_path/k3s-cache/${K3S_VERSION}/k3s $k3s_url || {
75+
echo "Failed to download k3s binary from $k3s_url"
76+
return 1
77+
}
78+
79+
chmod +x $collateral_path/k3s-cache/${K3S_VERSION}/k3s
80+
81+
wget -q -O $collateral_path/k3s-cache/${K3S_VERSION}/images.tar.zst $k3s_images_url || {
82+
echo "Failed to download k3s images from $k3s_images_url"
83+
return 1
84+
}
85+
86+
return 0
87+
}
88+
89+
print_large() {
90+
type figlet > /dev/null 2>&1 && {
91+
figlet "$@"
92+
} || {
93+
echo "========================================"
94+
echo "$@"
95+
echo "========================================"
96+
}
97+
}
98+
99+
wait_for_cluster_to_be_ready() {
100+
echo "Waiting for cluster to become accessible"
101+
102+
for _ in $(seq 60); do
103+
kubectl get pods -A 2>&1 | grep -q "No resources found" || {
104+
echo "Cluster is accessible"
105+
break
106+
}
107+
108+
echo -n "."
109+
sleep 1
110+
done
111+
112+
echo "Waiting for Pods to become ready"
113+
114+
for _ in $(seq 60); do
115+
sleep 1
116+
echo -n "."
117+
118+
allcount=$(kubectl get pods -A --no-headers=true | wc -l)
119+
notreadycount=$(kubectl get pods -A --no-headers=true | grep -c -v -e Complete -e Running)
120+
121+
if [ $allcount -lt 7 ]; then
122+
continue
123+
fi
124+
125+
if [ $notreadycount -eq 0 ]; then
126+
echo "READY"
127+
128+
return 0
129+
fi
130+
done
131+
132+
echo ""
133+
echo "Cluster did not become ready.."
134+
135+
return 1
136+
}
137+
138+
prepare_cluster() {
139+
print_large "Prepare cluster"
140+
141+
echo "Versions: $K3S_VERSION & $K8S_VERSION"
142+
143+
[ -e /usr/local/bin/k3s-uninstall.sh ] && {
144+
echo "Found existing k3s install, removing it"
145+
146+
k3s-uninstall.sh || return 1
147+
}
148+
149+
echo "prepare images"
150+
sudo mkdir -p /var/lib/rancher/k3s/agent/images/ && \
151+
sudo cp $collateral_path/k3s-cache/$K3S_VERSION/images.tar.zst /var/lib/rancher/k3s/agent/images/k3s-airgap-images-amd64.tar.zst || return 1
152+
sudo cp $collateral_path/k3s-cache/$K3S_VERSION/k3s /usr/local/bin/ || return 1
153+
sudo chmod +x /usr/local/bin/k3s || return 1
154+
155+
echo "prepare kubelet config"
156+
cat <<EOF > /tmp/kubelet.conf
157+
apiVersion: kubelet.config.k8s.io/v1beta1
158+
kind: KubeletConfiguration
159+
cpuManagerPolicy: static
160+
systemReserved:
161+
cpu: 2000m
162+
memory: 512M
163+
kubeReserved:
164+
cpu: 1000m
165+
memory: 256M
166+
EOF
167+
168+
sudo mkdir -p /etc/rancher/k3s
169+
cat <<EOF > /tmp/k3s-config.yaml
170+
kubelet-arg:
171+
- config=/tmp/kubelet.conf
172+
EOF
173+
sudo mv /tmp/k3s-config.yaml /etc/rancher/k3s/config.yaml
174+
175+
echo "prepare k3s cluster"
176+
INSTALL_K3S_SKIP_DOWNLOAD=true INSTALL_K3S_EXEC='--write-kubeconfig-mode=644' $collateral_path/k3s-cache/install-k3s.sh && \
177+
sudo chmod +r /etc/rancher/k3s/k3s.yaml && \
178+
sudo chmod o+rw /run/k3s/containerd/containerd.sock || {
179+
return 1
180+
}
181+
182+
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
183+
184+
wait_for_cluster_to_be_ready || return 1
185+
186+
kubectl get nodes -o wide
187+
kubectl get pods -A
188+
}
189+
190+
install_go() {
191+
local go_version
192+
go_version=$(grep "^go " $GITHUB_WORKSPACE/go.mod | head -1 | cut -c 4-)
193+
194+
[ -e $collateral_path/go$go_version.linux-amd64.tar.gz ] || {
195+
wget https://go.dev/dl/go$go_version.linux-amd64.tar.gz -O $collateral_path/go$go_version.linux-amd64.tar.gz || exit 1
196+
}
197+
198+
mkdir -p ~/bin
199+
tar -xf $collateral_path/go$go_version.linux-amd64.tar.gz -C ~/bin || exit 1
200+
201+
export PATH=$PATH:~/bin/go/bin
202+
203+
type go || {
204+
echo "Go installation failed"
205+
return 1
206+
}
207+
208+
go version || return 1
209+
}
210+
211+
install_k8s_deps() {
212+
print_large "Install cert-manager"
213+
kubectl apply --wait -f https://github.com/cert-manager/cert-manager/releases/download/v1.18.0/cert-manager.yaml || return 1
214+
}
215+
216+
prepare_to_build() {
217+
echo "Fetch vendor dependencies"
218+
make vendor || return 1
219+
220+
echo "Generate dummy licenses"
221+
222+
for ldir in $(ls --ignore=internal cmd | xargs -I"{}" echo licenses/{}); do
223+
mkdir -p $GITHUB_WORKSPACE/$ldir
224+
touch $GITHUB_WORKSPACE/$ldir/dummy-license.txt
225+
done
226+
}
227+
228+
# This should be executed only once per run.
229+
generate_tag() {
230+
# Extract the version from the reconciler.
231+
local BUILD_VERSION
232+
BUILD_VERSION=$(grep -r --include="*.go" 'ImageMinVersion =' ${GITHUB_WORKSPACE} | head -1 | sed -e 's/.*"\(.*\)".*/\1/')
233+
234+
# Add random components to avoid collision with other images.
235+
BUILD_VERSION=$BUILD_VERSION-$GITHUB_RUN_NUMBER-$RANDOM
236+
237+
export TAG=$BUILD_VERSION
238+
}
239+
240+
cache_shared_images() {
241+
echo "Cache shared images"
242+
243+
local SHARED_IMAGES=""
244+
245+
echo $IMAGES | grep -q gpu && {
246+
SHARED_IMAGES="${SHARED_IMAGES}intel/intel-extension-for-pytorch:2.8.10-xpu "
247+
}
248+
249+
for image in $SHARED_IMAGES;
250+
do
251+
echo "Downloading and caching $image"
252+
docker pull $image && docker save $image | sudo ctr -n k8s.io image import - || return 1
253+
done
254+
}

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

0 commit comments

Comments
 (0)