Skip to content

Commit c87e471

Browse files
authored
Merge pull request #622 from jgehrcke/jp/bats-dynamic-api-version
tests: dynamically inject DRA API version into spec
2 parents 8b17bb2 + eed8b15 commit c87e471

File tree

4 files changed

+52
-3
lines changed

4 files changed

+52
-3
lines changed

tests/bats/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ TEST_NVIDIA_DRIVER_ROOT ?= "/run/nvidia/driver"
4949
TEST_EXPECTED_IMAGE_SPEC_SUBSTRING ?= $(VERSION)
5050

5151
ifneq ($(TEST_CHART_LOCAL),"false")
52-
TEST_CHART_REPO = "deployments/helm/nvidia-dra-driver-gpu/"
52+
TEST_CHART_REPO = "deployments/helm/nvidia-dra-driver-gpu"
5353
TEST_CHART_VERSION = $(VERSION:v%=%)
5454
endif
5555

tests/bats/setup_suite.bash

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
#
3+
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
# Reference:
19+
# https://bats-core.readthedocs.io/en/latest/writing-tests.html#setup-and-teardown-pre-and-post-test-hooks
20+
21+
# Validate that some prerequisites are met, and inspect environment for
22+
# characteristics, such as DRA API group version. A failing setup_suit()
23+
# function aborts the suite (fail fast).
24+
setup_suite () {
25+
# Probe: kubectl configured against a k8s cluster.
26+
kubectl cluster-info | grep "control plane is running at"
27+
28+
# Show, for debugging.
29+
kubectl api-resources --api-group=resource.k8s.io
30+
31+
# Require DRA API group to be enabled (for now, maybe we want to add a test
32+
# later that shows how Helm chart installation fails when DRA is not
33+
# enabled, and then this suite-setup check could get in the way). The
34+
# command below is expected to emit deviceclasses, resourceclaims,
35+
# resourceclaimtemplates, resourceslices -- probe just one.
36+
kubectl api-resources --api-group=resource.k8s.io | grep resourceslices
37+
38+
TEST_K8S_RESOURCE_API_VERSION=$( \
39+
kubectl api-resources --api-group=resource.k8s.io -o json | \
40+
jq -r '.resources | map(select(.version)) | .[0].version'
41+
)
42+
43+
# Examples: v1, or v1beta1
44+
export TEST_K8S_RESOURCE_API_VERSION
45+
}

tests/bats/specs/rc-opaque-cfg-unknown-field.yaml renamed to tests/bats/specs/rc-opaque-cfg-unknown-field.yaml.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
apiVersion: resource.k8s.io/v1beta1
1+
apiVersion: resource.k8s.io/${TEST_K8S_RESOURCE_API_VERSION}
22
kind: ResourceClaim
33
metadata:
44
name: batssuite-rc-bad-opaque-config

tests/bats/tests.bats

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,11 @@ apply_check_delete_workload_imex_chan_inject() {
164164
}
165165

166166
@test "NodePrepareResources: catch unknown field in opaque cfg in ResourceClaim" {
167-
local SPEC="tests/bats/specs/rc-opaque-cfg-unknown-field.yaml"
167+
envsubst < tests/bats/specs/rc-opaque-cfg-unknown-field.yaml.tmpl > \
168+
"${BATS_TEST_TMPDIR}"/rc-opaque-cfg-unknown-field.yaml
169+
cd "${BATS_TEST_TMPDIR}"
170+
171+
local SPEC="rc-opaque-cfg-unknown-field.yaml"
168172

169173
# Create pod with random name suffix.
170174
# Store ref of the form `pod/batssuite-pod-boc-brs2l`.

0 commit comments

Comments
 (0)