Skip to content

Commit b47c656

Browse files
committed
.github: Add k8s conformance tests in Nightly
1 parent 590f4e9 commit b47c656

File tree

4 files changed

+283
-11
lines changed

4 files changed

+283
-11
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: "Run K8s Conformance"
2+
description: "Run the Kubernetes Conformance tests"
3+
4+
inputs:
5+
metalk8s-short-version:
6+
description: "The MetalK8s short version to use in the PR content"
7+
required: true
8+
dest:
9+
description: "Destination directory for results + PR content"
10+
required: false
11+
default: "artifacts/conformance"
12+
13+
runs:
14+
using: "composite"
15+
steps:
16+
- name: Create result directory
17+
shell: bash
18+
run: |
19+
result_dir="${{ inputs.dest }}/sonobuoy-results"
20+
echo "result_dir=$result_dir" >> $GITHUB_ENV
21+
mkdir -p "$result_dir"
22+
- name: Retrieve the Kubernetes version
23+
id: get-k8s-version
24+
uses: ./.github/actions/run-command-ssh
25+
with:
26+
COMMAND: |
27+
sudo rpm -q --queryformat '%{VERSION}' kubelet | cut -d'.' -f1,2
28+
CAPTURE_RESULT: "true"
29+
- name: Get sonobuoy bin
30+
shell: bash
31+
env:
32+
SONOBUOY_VERSION: "0.56.15"
33+
run: |
34+
curl -Lo "sonobuoy.tar.gz" https://github.com/vmware-tanzu/sonobuoy/releases/download/v${SONOBUOY_VERSION}/sonobuoy_${SONOBUOY_VERSION}_linux_amd64.tar.gz
35+
tar xvf sonobuoy.tar.gz
36+
- name: Copy sonobuoy bin to Bootstrap node
37+
uses: ./.github/actions/copy-file-ssh
38+
with:
39+
SOURCE_FILE: "sonobuoy"
40+
- name: Run conformance tests from Bootstrap node
41+
uses: ./.github/actions/run-command-ssh
42+
with:
43+
COMMAND: |
44+
sudo ./sonobuoy run --kubeconfig=/etc/kubernetes/admin.conf --mode=certified-conformance --wait
45+
SSH_OPTIONS: "-o ServerAliveInterval=15"
46+
- name: Retrieve conformance tests result
47+
uses: ./.github/actions/run-command-ssh
48+
with:
49+
COMMAND: |
50+
sudo ./sonobuoy retrieve --kubeconfig=/etc/kubernetes/admin.conf --filename sonobuoy_result.tar.gz
51+
- name: Retrieve conformance tests result from Bootstrap node
52+
uses: ./.github/actions/copy-file-ssh
53+
with:
54+
NODE_TO: ""
55+
NODE_FROM: "bootstrap"
56+
SOURCE_FILE: "sonobuoy_result.tar.gz"
57+
DESTINATION_FILE: "${{ env.result_dir }}/"
58+
- name: Extract conformance tests result
59+
shell: bash
60+
working-directory: ${{ env.result_dir }}
61+
run: tar xvf sonobuoy_result.tar.gz
62+
- name: Check conformance tests result
63+
shell: bash
64+
run: |
65+
failed_tests=$(./sonobuoy results "$result_dir/sonobuoy_result.tar.gz" --mode=detailed --plugin=e2e | jq 'select(.status=="failed")')
66+
[ -n "$failed_tests" ] && echo $failed_tests && exit 1 || exit 0
67+
- name: Prepare conformance PR content
68+
shell: bash
69+
env:
70+
DIRECTORY: "${{ inputs.dest }}/pr-content"
71+
SONOBUOY_RES_DIR: "${{ env.result_dir }}"
72+
K8S_VERSION: "${{ steps.get-k8s-version.outputs.RESULT }}"
73+
METALK8S_VERSION: "${{ inputs.metalk8s-short-version }}"
74+
run: |
75+
.github/scripts/build-conformance-pr-content.sh
76+
tar cvf "${{ inputs.dest }}/pr-content.tar.gz" -C "$DIRECTORY" "v$K8S_VERSION"
77+
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
#!/bin/bash
2+
3+
DIRECTORY=${DIRECTORY:-pr-content}
4+
SONOBUOY_RES_DIR=${SONOBUOY_RES_DIR:-sonobuoy-results}
5+
6+
K8S_VERSION=${K8S_VERSION:-}
7+
METALK8S_VERSION=${METALK8S_VERSION:-}
8+
9+
dest="${DIRECTORY}/v${K8S_VERSION}/MetalK8s"
10+
doc_url="https://metal-k8s.readthedocs.io/en/development-${METALK8S_VERSION}/"
11+
12+
mkdir -p "$dest"
13+
14+
cat > "$dest/PRODUCT.yaml" << EOF
15+
vendor: Scality
16+
name: MetalK8s
17+
description: "An opinionated Kubernetes distribution with a focus on long-term on-prem deployments"
18+
version: ${METALK8S_VERSION}
19+
type: distribution
20+
website_url: https://github.com/scality/metalk8s/
21+
repo_url: https://github.com/scality/metalk8s.git
22+
product_logo_url: https://raw.githubusercontent.com/scality/metalk8s/development/${METALK8S_VERSION}/artwork/metalk8s-logo-vertical.svg
23+
documentation_url: ${doc_url}
24+
EOF
25+
26+
sed "s%@@DOC_URL@@%${doc_url}%g" > "$dest/README.md" << 'ENDREADME'
27+
# MetalK8s
28+
Official documentation: @@DOC_URL@@
29+
30+
## Prerequisites
31+
- An OpenStack cluster
32+
- The official CentOS 7.9 2009 image pre-loaded in Glance
33+
- Three VMs with 8 vCPUs, 16 GB of RAM, 40GB of local storage
34+
35+
## Provisioning
36+
- Create two private network in the OpenStack cluster with port security
37+
disabled, and a subnet in each:
38+
39+
* Control-plane network: 192.168.1.0/24
40+
* Workload-plane network: 192.168.2.0/24
41+
42+
- Create VM instances using the CentOS 7.9 image, and attach each of them to a
43+
public network (for internet access) and the two private networks.
44+
45+
- Configure the interface for private networks (make sure to fill in the
46+
appropriate MAC address):
47+
48+
```
49+
$ cat > /etc/sysconfig/network-scripts/ifcfg-eth1 << EOF
50+
BOOTPROTO=dhcp
51+
DEVICE=eth1
52+
HWADDR=...
53+
ONBOOT=yes
54+
TYPE=Ethernet
55+
USERCTL=no
56+
PEERDNS=no
57+
EOF
58+
$ cat > /etc/sysconfig/network-scripts/ifcfg-eth2 << EOF
59+
BOOTPROTO=dhcp
60+
DEVICE=eth2
61+
HWADDR=...
62+
ONBOOT=yes
63+
TYPE=Ethernet
64+
USERCTL=no
65+
PEERDNS=no
66+
EOF
67+
$ systemctl restart network
68+
```
69+
70+
### Provisioning the Bootstrap Node
71+
On one of the VMs, which will act as the *bootstrap* node, perform the following
72+
steps:
73+
74+
- Set up the Salt Minion ID:
75+
76+
```
77+
$ mkdir /etc/salt; chmod 0700 /etc/salt
78+
$ echo metalk8s-bootstrap > /etc/salt/minion_id
79+
```
80+
81+
- Download MetalK8s ISO to `/home/centos/metalk8s.iso`
82+
83+
- Create `/etc/metalk8s/bootstrap.yaml`:
84+
85+
```
86+
$ mkdir /etc/metalk8s
87+
$ cat > /etc/metalk8s/bootstrap.yaml << EOF
88+
apiVersion: metalk8s.scality.com/v1alpha3
89+
kind: BootstrapConfiguration
90+
networks:
91+
controlPlane:
92+
cidr: 192.168.1.0/24
93+
workloadPlane:
94+
cidr: 192.168.2.0/24
95+
portmap:
96+
cidr: 0.0.0.0/0
97+
nodeport:
98+
cidr: 0.0.0.0/0
99+
ca:
100+
minion: metalk8s-bootstrap
101+
archives:
102+
- /home/centos/metalk8s.iso
103+
EOF
104+
```
105+
106+
- Bootstrap the cluster
107+
108+
```
109+
$ mkdir /mnt/metalk8s
110+
$ mount /home/centos/metalk8s.iso /mnt/metalk8s
111+
$ cd /mnt/metalk8s
112+
$ ./bootstrap.sh
113+
```
114+
115+
### Provisioning the Cluster Nodes
116+
Add the 2 other nodes to the cluster according to the procedure outlined in the
117+
MetalK8s documentation. The easiest way to achieve this is through the MetalK8s
118+
UI.
119+
120+
## Preparing the Cluster to Run Sonobuoy
121+
On the *bootstrap* node:
122+
123+
- Configure access to the Kubernetes API server
124+
125+
```
126+
$ export KUBECONFIG=/etc/kubernetes/admin.conf
127+
```
128+
129+
- Remove taints from the node, which would prevent the Sonobuoy *Pod*s from
130+
being scheduled:
131+
132+
```
133+
$ kubectl taint node metalk8s-bootstrap node-role.kubernetes.io/bootstrap-
134+
node/metalk8s-bootstrap untainted
135+
$ kubectl taint node metalk8s-bootstrap node-role.kubernetes.io/infra-
136+
node/metalk8s-bootstrap untainted
137+
```
138+
139+
## Running Sonobuoy and Collecting Results
140+
Follow the
141+
[instructions](https://github.com/cncf/k8s-conformance/blob/master/instructions.md)
142+
as found in the [CNCF K8s Conformance repository](https://github.com/cncf/k8s-conformance).
143+
ENDREADME
144+
145+
cp "${SONOBUOY_RES_DIR}/plugins/e2e/results/global/e2e.log" "$dest/"
146+
cp "${SONOBUOY_RES_DIR}/plugins/e2e/results/global/junit_01.xml" "$dest/"

.github/workflows/multi-node-test.yaml

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ on:
4141
required: false
4242
type: boolean
4343
default: false
44+
k8s-conformance:
45+
description: "Whether or not k8s conformance tests should be ran"
46+
required: false
47+
type: boolean
48+
default: false
4449
enable-debug-when-failure:
4550
description: "Whether or not debug when failure should be enabled or not"
4651
required: false
@@ -82,7 +87,7 @@ jobs:
8287
- name: Checkout
8388
uses: actions/checkout@v3
8489
- name: Install deps
85-
run: sudo yum install -y isomd5sum
90+
run: sudo yum install -y isomd5sum jq
8691

8792
## Spawn {{{
8893
- name: Export environment variables for accessing the cloud
@@ -262,15 +267,17 @@ jobs:
262267
SOURCE_FILE: "metalk8s.iso"
263268
- name: Mount MetalK8s ISO on the new Bootstrap node
264269
if: inputs.bootstrap-restore
265-
id: get-new-mnt
270+
id: mount-iso
266271
uses: ./.github/actions/mount-iso
267272
- name: Run restore tests from Bastion
268273
if: inputs.bootstrap-restore
269274
uses: ./.github/actions/bastion-tests
270275
with:
271276
PYTEST_FILTERS: "restore"
272277
BOOTSTRAP_BACKUP_ARCHIVE: "/tmp/${{ steps.backup.outputs.filename }}"
273-
mountpoint: ${{ steps.get-new-mnt.outputs.mountpoint }}
278+
# NOTE: We need to specify the mountpoint since it will not be
279+
# able to auto-discover it because the bootstrap node is down
280+
mountpoint: ${{ steps.mount-iso.outputs.mountpoint }}
274281
- name: Wait for pods to stabilize after restore
275282
if: inputs.bootstrap-restore
276283
uses: ./.github/actions/wait-pod-stable
@@ -281,6 +288,42 @@ jobs:
281288
PYTEST_FILTERS: "post and ci and not slow"
282289
# }}}
283290

291+
# Retrieve information {{{
292+
- name: Retrieve product.txt from artifacts
293+
run: >
294+
curl --fail -LO -u ${{ secrets.ARTIFACTS_USER }}:${{ secrets.ARTIFACTS_PASSWORD }}
295+
${{ inputs.artifacts-url }}/product.txt
296+
- name: Get full MetalK8s version
297+
run: |
298+
source product.txt
299+
echo "METALK8S_VERSION=$VERSION" >> $GITHUB_ENV
300+
echo "METALK8S_SHORT_VERSION=$SHORT_VERSION" >> $GITHUB_ENV
301+
# }}}
302+
303+
# Run k8s conformance tests (if enabled) {{{
304+
- name: Untaint bootstrap node for conformance tests
305+
if: inputs.k8s-conformance
306+
uses: ./.github/actions/untaint
307+
- name: Expose nodeport and portmap on every IPs
308+
if: inputs.k8s-conformance
309+
uses: ./.github/actions/run-command-ssh
310+
with:
311+
COMMAND: |
312+
sudo salt-call --local --retcode-passthrough state.single file.serialize /etc/metalk8s/bootstrap.yaml dataset='{"networks": {"nodeport": {"cidr": "0.0.0.0/0"}, "portmap": {"cidr": "0.0.0.0/0"}}}' merge_if_exists=True
313+
SALT_MASTER=\$(sudo crictl ps --label="io.kubernetes.container.name=salt-master" -q)
314+
sudo crictl exec \$SALT_MASTER salt-run state.sls metalk8s.kubernetes.kube-proxy.deployed saltenv=metalk8s-$METALK8S_VERSION
315+
sudo crictl exec \$SALT_MASTER salt-run state.sls metalk8s.kubernetes.cni.calico.deployed saltenv=metalk8s-$METALK8S_VERSION
316+
sudo crictl exec \$SALT_MASTER salt '*' state.sls metalk8s.addons.nginx-ingress.certs saltenv=metalk8s-$METALK8S_VERSION
317+
- name: Wait for pods to stabilize before conformance tests
318+
if: inputs.k8s-conformance
319+
uses: ./.github/actions/wait-pod-stable
320+
- name: Run the k8s conformance tests
321+
if: inputs.k8s-conformance
322+
uses: ./.github/actions/run-k8s-conformance
323+
with:
324+
metalk8s-short-version: "${{ env.METALK8S_SHORT_VERSION }}"
325+
# }}}
326+
284327
- name: Generate and Collect sosreport
285328
if: always()
286329
uses: ./.github/actions/sosreport-logs
@@ -299,16 +342,9 @@ jobs:
299342
## }}
300343

301344
# Generate snapshots (if enabled) {{{
302-
- name: Retrieve product.txt from artifacts
303-
if: inputs.generate-snapshots
304-
run: >
305-
curl --fail -LO -u ${{ secrets.ARTIFACTS_USER }}:${{ secrets.ARTIFACTS_PASSWORD }}
306-
${{ inputs.artifacts-url }}/product.txt
307-
- name: Get full MetalK8s version and total number of nodes
345+
- name: Get total number of nodes
308346
if: inputs.generate-snapshots
309347
run: |
310-
source product.txt
311-
echo "METALK8S_VERSION=$VERSION" >> $GITHUB_ENV
312348
echo "TOTAL_NB_NODES=$((${{ env.NODES_COUNT }} + 1))" >> $GITHUB_ENV
313349
- name: Generate snapshot
314350
if: inputs.generate-snapshots

.github/workflows/nightly.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,25 @@ jobs:
190190
nodes-count: 2
191191
bootstrap-restore: true
192192

193+
k8s-conformance:
194+
uses: ./.github/workflows/multi-node-test.yaml
195+
secrets: inherit
196+
needs:
197+
- retrieve-info
198+
with:
199+
name: k8s-conformance
200+
artifacts-url: ${{ needs.retrieve-info.outputs.artifacts-link }}
201+
nodes-count: 2
202+
k8s-conformance: true
203+
193204
write-final-failed-status:
194205
runs-on: ubuntu-22.04
195206
needs:
196207
- lifecycle-promoted
197208
- lifecycle-dev
198209
- install
199210
- bootstrap-restore
211+
- k8s-conformance
200212
if: failure()
201213
steps:
202214
- name: Checkout
@@ -223,6 +235,7 @@ jobs:
223235
- lifecycle-dev
224236
- install
225237
- bootstrap-restore
238+
- k8s-conformance
226239
if: success()
227240
steps:
228241
- name: Checkout

0 commit comments

Comments
 (0)