|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -euxo pipefail |
| 4 | + |
| 5 | +KUBE_MAJOR=$(oc version -o json | jq -r '.serverVersion.major' | tr -d '+') |
| 6 | +KUBE_MINOR=$(oc version -o json | jq -r '.serverVersion.minor' | tr -d '+') |
| 7 | +if [ "${KUBE_MAJOR}" -eq 1 ] && [ "${KUBE_MINOR}" -lt 34 ]; then |
| 8 | + echo "SKIP: DRA requires Kubernetes >= 1.34, got ${KUBE_MAJOR}.${KUBE_MINOR}" |
| 9 | + exit 0 |
| 10 | +fi |
| 11 | + |
| 12 | +echo "Get a worker node..." |
| 13 | +export NODE=$(oc get nodes -l node-role.kubernetes.io/worker -o jsonpath='{.items[0].metadata.name}') |
| 14 | + |
| 15 | +echo "Label the node to match the Module selector..." |
| 16 | +oc label node "${NODE}" task=kmm-ci-dra |
| 17 | + |
| 18 | +oc project openshift-kmm |
| 19 | + |
| 20 | +oc wait --for=condition=Available deployment/kmm-operator-controller deployment/kmm-operator-webhook |
| 21 | + |
| 22 | +echo "Create a build secret" |
| 23 | +oc create secret generic build-secret --from-literal=ci-build-secret=super-secret-value |
| 24 | + |
| 25 | +echo "Add a configmap that contains the kernel module build dockerfile" |
| 26 | +oc apply -f ci/kmm-kmod-dockerfile.yaml |
| 27 | + |
| 28 | +echo "Add a Module with DRA spec" |
| 29 | +timeout 1m bash -c 'until oc apply -f ci/e2e-dra/module-kmm-ci-dra.yaml; do sleep 3; done' |
| 30 | + |
| 31 | +echo "Check that the module gets loaded on the node" |
| 32 | +timeout 10m bash -c 'until oc debug node/${NODE} -- chroot host/ lsmod | grep kmm_ci_a; do sleep 3; done' |
| 33 | + |
| 34 | +echo "Check that the DRA DaemonSet gets created" |
| 35 | +timeout 2m bash -c 'until oc get ds -l kmm.node.kubernetes.io/role=dra,kmm.node.kubernetes.io/module.name=kmm-ci-dra -o name 2>/dev/null | grep -q daemonset; do sleep 3; done' |
| 36 | + |
| 37 | +echo "Check that the DRA DaemonSet pod is ready" |
| 38 | +timeout 5m bash -c 'until [ "$(oc get ds -l kmm.node.kubernetes.io/role=dra,kmm.node.kubernetes.io/module.name=kmm-ci-dra -o jsonpath="{.items[0].status.numberReady}" 2>/dev/null)" = "1" ]; do sleep 3; done' |
| 39 | + |
| 40 | +echo "Check that the DeviceClass was created with correct labels" |
| 41 | +DC_MODULE_NAME=$(oc get deviceclass kmm-ci-test-device -o jsonpath='{.metadata.labels.kmm\.node\.kubernetes\.io/module\.name}') |
| 42 | +DC_MODULE_NS=$(oc get deviceclass kmm-ci-test-device -o jsonpath='{.metadata.labels.kmm\.node\.kubernetes\.io/module\.namespace}') |
| 43 | +[ "${DC_MODULE_NAME}" = "kmm-ci-dra" ] |
| 44 | +[ "${DC_MODULE_NS}" = "openshift-kmm" ] |
| 45 | + |
| 46 | +echo "Check that the DRA node label was set" |
| 47 | +timeout 2m bash -c 'until oc get node ${NODE} -o jsonpath="{.metadata.labels}" | grep "kmm\.node\.kubernetes\.io/openshift-kmm\.kmm-ci-dra\.dra-ready"; do sleep 3; done' |
| 48 | + |
| 49 | +echo "Check that ResourceSlices were published by the driver" |
| 50 | +timeout 2m bash -c 'until [ "$(oc get resourceslice --no-headers 2>/dev/null | grep gpu.example.com | wc -l)" -gt 0 ]; do sleep 3; done' |
| 51 | + |
| 52 | +echo "Check that Module status.dra is populated" |
| 53 | +[ "$(oc get module kmm-ci-dra -o jsonpath='{.status.dra.availableNumber}')" = "1" ] |
| 54 | + |
| 55 | +echo "Deploy a consumer pod requesting DRA hardware" |
| 56 | +oc apply -f ci/e2e-dra/dra-consumer-pod.yaml |
| 57 | + |
| 58 | +echo "Check that the consumer pod is running on the node with the DRA driver" |
| 59 | +oc wait --for=condition=Ready pod/dra-consumer --timeout=2m |
| 60 | +[ "$(oc get pod dra-consumer -o jsonpath='{.spec.nodeName}')" = "${NODE}" ] |
| 61 | + |
| 62 | +echo "Remove the consumer pod" |
| 63 | +oc delete -f ci/e2e-dra/dra-consumer-pod.yaml |
| 64 | +timeout 1m bash -c 'until ! oc get pod dra-consumer 2>/dev/null; do sleep 3; done' |
| 65 | + |
| 66 | +echo "Remove the Module" |
| 67 | +oc delete -f ci/e2e-dra/module-kmm-ci-dra.yaml --wait=false |
| 68 | + |
| 69 | +echo "Check that the DRA DaemonSet gets cleaned up" |
| 70 | +timeout 2m bash -c 'until [ "$(oc get ds -l kmm.node.kubernetes.io/role=dra,kmm.node.kubernetes.io/module.name=kmm-ci-dra --no-headers 2>/dev/null | wc -l)" -eq 0 ]; do sleep 3; done' |
| 71 | + |
| 72 | +echo "Check that the DeviceClass gets cleaned up" |
| 73 | +timeout 1m bash -c 'until ! oc get deviceclass kmm-ci-test-device 2>/dev/null; do sleep 3; done' |
| 74 | + |
| 75 | +echo "Check that the module gets unloaded from the node" |
| 76 | +timeout 1m bash -c 'until ! oc debug node/${NODE} -- chroot host/ lsmod | grep kmm_ci_a; do sleep 3; done' |
| 77 | + |
| 78 | +echo "Wait for the Module to be deleted" |
| 79 | +oc wait --for delete modules.kmm.sigs.x-k8s.io/kmm-ci-dra |
0 commit comments