|
| 1 | +# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | + |
| 16 | +include $(CURDIR)/versions.mk |
| 17 | +include $(CURDIR)/common.mk |
| 18 | + |
| 19 | +BATS_IMAGE = batstests:$(GIT_COMMIT_SHORT) |
| 20 | + |
| 21 | +TEST_CHART_REPO ?= "oci://ghcr.io/nvidia/k8s-dra-driver-gpu" |
| 22 | +TEST_CHART_VERSION ?= $(VERSION_GHCR_CHART) |
| 23 | +TEST_CHART_LASTSTABLE_REPO ?= "oci://ghcr.io/nvidia/k8s-dra-driver-gpu" |
| 24 | +TEST_CHART_LASTSTABLE_VERSION ?= "25.3.2-2c250af3-chart" |
| 25 | +TEST_NVIDIA_DRIVER_ROOT ?= "/run/nvidia/driver" |
| 26 | + |
| 27 | +# Currently consumed in upgrade test via |
| 28 | +# kubectl apply -f <URL> (can be a branch, tag, or commit) |
| 29 | +TEST_CRD_UPGRADE_TARGET_GIT_REF ?= $(GIT_COMMIT_SHORT) |
| 30 | + |
| 31 | +default: tests |
| 32 | + |
| 33 | +.PHONY: image |
| 34 | +image: |
| 35 | + docker buildx build . -t $(BATS_IMAGE) -f tests/bats/Dockerfile |
| 36 | + |
| 37 | +# Warning: destructive against currently configured k8s cluster. |
| 38 | +# |
| 39 | +# Explicit invocation of 'cleanup-from-previous-run.sh' (could also be done as |
| 40 | +# suite/file 'setup' in bats, but we'd lose output on success). During dev, you |
| 41 | +# may want to add --show-output-of-passing-tests (and read bats docs for other |
| 42 | +# cmdline args). |
| 43 | +.PHONY: tests |
| 44 | +tests: image |
| 45 | + mkdir -p tests-out |
| 46 | + export _RUNDIR=$(shell mktemp -p tests-out -d -t bats-tests-$$(date +%s)-XXXXX) && \ |
| 47 | + echo "output directory: $${_RUNDIR}" && \ |
| 48 | + time docker run \ |
| 49 | + -it \ |
| 50 | + -v /tmp:/tmp \ |
| 51 | + -v $(CURDIR):/cwd \ |
| 52 | + -v ~/.kube/config:/kubeconfig \ |
| 53 | + --env KUBECONFIG=/kubeconfig \ |
| 54 | + --env TEST_CHART_REPO=$(TEST_CHART_REPO) \ |
| 55 | + --env TEST_CHART_VERSION=$(TEST_CHART_VERSION) \ |
| 56 | + --env TEST_CHART_LASTSTABLE_REPO=$(TEST_CHART_LASTSTABLE_REPO) \ |
| 57 | + --env TEST_CHART_LASTSTABLE_VERSION=$(TEST_CHART_LASTSTABLE_VERSION) \ |
| 58 | + --env TEST_CRD_UPGRADE_TARGET_GIT_REF=$(TEST_CRD_UPGRADE_TARGET_GIT_REF) \ |
| 59 | + --env TEST_NVIDIA_DRIVER_ROOT=$(TEST_NVIDIA_DRIVER_ROOT) \ |
| 60 | + -u $(shell id -u ${USER}):$(shell id -g ${USER}) \ |
| 61 | + --entrypoint "/bin/bash"\ |
| 62 | + $(BATS_IMAGE) \ |
| 63 | + -c "cd /cwd; \ |
| 64 | + echo 'Running k8s cluster cleanup (invasive)... '; \ |
| 65 | + bash tests/bats/cleanup-from-previous-run.sh &> $${_RUNDIR}/cleanup.outerr || \ |
| 66 | + (echo 'Cleanup failed:'; cat $${_RUNDIR}/cleanup.outerr); \ |
| 67 | + TMPDIR=/cwd/$${_RUNDIR} bats \ |
| 68 | + --print-output-on-failure \ |
| 69 | + --no-tempdir-cleanup \ |
| 70 | + --timing \ |
| 71 | + tests/bats/tests.bats \ |
| 72 | + " |
0 commit comments