example

package
v0.0.0-...-e4a8a9b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 10, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

README

DRA Example Driver Extended Tests for OpenShift

This directory contains extended tests for the upstream dra-example-driver on OpenShift clusters. These tests provide hardware-independent DRA regression coverage — no GPU or special hardware is required.

Overview

These tests validate:

  • DRA example driver installation and lifecycle
  • Single device allocation via ResourceClaims
  • Multi-device allocation
  • Pod lifecycle and resource cleanup
  • Claim sharing behavior
  • ResourceClaimTemplate-based claim creation and cleanup

Prerequisites

  1. OpenShift 4.21+ cluster (DRA API enabled by default)
  2. Helm 3 installed and available in PATH
  3. git installed and available in PATH
  4. Cluster-admin access

The test framework automatically:

  • Clones the upstream dra-example-driver repository
  • Installs the driver via Helm with OpenShift SCC permissions
  • Waits for driver components to be ready

Quick Start

# 1. Build test binary
make WHAT=cmd/openshift-tests

# 2. Set kubeconfig
export KUBECONFIG=/path/to/kubeconfig

# 3. Run all DRA example driver tests (local binary)
OPENSHIFT_SKIP_EXTERNAL_TESTS=1 \
  ./openshift-tests run --dry-run all 2>&1 | \
  grep "\[Feature:DRA-Example\]" | \
  OPENSHIFT_SKIP_EXTERNAL_TESTS=1 ./openshift-tests run -f -

# OR run a specific test
OPENSHIFT_SKIP_EXTERNAL_TESTS=1 ./openshift-tests run-test \
  '[sig-scheduling][Feature:DRA-Example][Suite:openshift/dra-example][Serial] Basic Device Allocation should allocate single device to pod via DRA'

# OR list all available tests
OPENSHIFT_SKIP_EXTERNAL_TESTS=1 \
  ./openshift-tests run --dry-run all 2>&1 | grep "\[Feature:DRA-Example\]"

Note: OPENSHIFT_SKIP_EXTERNAL_TESTS=1 is required when running a locally built binary. Without it, the run command attempts to extract test binaries from the cluster's release payload, which does not contain your local changes. This variable is NOT needed in CI where the binary is part of the payload.

Environment Variables

Variable Default Description
DRA_EXAMPLE_DRIVER_REF main Git ref (branch/tag) of the upstream dra-example-driver to install

Test Scenarios

1. Single Device Allocation
  • Creates DeviceClass with CEL selector for gpu.example.com driver
  • Creates ResourceClaim requesting 1 device
  • Schedules pod with ResourceClaim
  • Validates device allocation in ResourceClaim status
2. Resource Cleanup
  • Creates pod with device ResourceClaim
  • Deletes pod
  • Verifies ResourceClaim persists after pod deletion but is unreserved
3. Multi-Device Allocation
  • Creates ResourceClaim requesting 2 devices
  • Schedules pod requiring multiple devices
  • Validates all devices are allocated (driver publishes 9 virtual devices per node)
4. Claim Sharing
  • Creates a single ResourceClaim
  • Creates two pods referencing the same ResourceClaim
  • Verifies behavior: both pods run (sharing supported) or second pod stays Pending
5. ResourceClaimTemplate
  • Creates a ResourceClaimTemplate
  • Creates pod with ResourceClaimTemplate reference
  • Validates that ResourceClaim is auto-created from template
  • Validates automatic cleanup of template-generated claim when pod is deleted

OpenShift-Specific Adaptations

The upstream dra-example-driver Helm chart requires the following OpenShift adaptations (handled automatically by the test framework):

  1. SCC Grant: The kubelet plugin DaemonSet runs with privileged: true and mounts hostPath volumes. A ClusterRoleBinding grants the system:openshift:scc:privileged ClusterRole to the driver ServiceAccount.

  2. Tolerations: Control-plane tolerations are added to allow scheduling on the OpenShift clusters.

Troubleshooting

Helm not found

Cause: Helm 3 not installed.

Solution: Install Helm following official instructions.

SCC denied — kubelet plugin pod rejected

Cause: ClusterRoleBinding for privileged SCC not created.

Solution: The test framework creates this automatically. For manual debugging:

oc adm policy add-scc-to-user privileged \
  -n dra-example-driver \
  -z dra-example-driver-service-account
ResourceSlices not appearing

Cause: DRA driver DaemonSet not ready.

Solution:

# Check DRA driver pods
oc get pods -n dra-example-driver

# Check DaemonSet logs
oc logs -n dra-example-driver -l app.kubernetes.io/name=dra-example-driver --all-containers

Architecture

test/extended/node/dra/
├── common/                  # Shared DRA test utilities
│   ├── resource_builder.go  # Parameterized builder (DriverConfig)
│   └── crud_helpers.go      # GVR declarations and CRUD helpers
├── example/                 # dra-example-driver tests (this package)
│   ├── example_dra.go
│   ├── device_validator.go
│   ├── prerequisites_installer.go
│   ├── OWNERS
│   └── README.md
└── nvidia/                  # NVIDIA DRA tests

The common/ package provides a DriverConfig struct and a parameterized ResourceBuilder so that each driver test package (example, nvidia, future drivers) can reuse the same object-building and CRUD logic without duplication. Each package supplies its own config:

builder = dracommon.NewResourceBuilder(namespace, dracommon.DriverConfig{
    DriverName:   "gpu.example.com",
    DefaultClass: "gpu.example.com",
    // ...
})

References

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DeviceValidator

type DeviceValidator struct {
	// contains filtered or unexported fields
}

DeviceValidator validates device allocation and ResourceSlice state

func NewDeviceValidator

func NewDeviceValidator(f *framework.Framework) *DeviceValidator

NewDeviceValidator creates a new validator instance

func (*DeviceValidator) GetTotalDeviceCount

func (dv *DeviceValidator) GetTotalDeviceCount(ctx context.Context) (int, error)

GetTotalDeviceCount returns the total number of devices available

func (*DeviceValidator) IsDriverPublishingDevices

func (dv *DeviceValidator) IsDriverPublishingDevices(ctx context.Context) bool

IsDriverPublishingDevices checks if the driver is publishing devices

func (*DeviceValidator) ValidateDeviceAllocation

func (dv *DeviceValidator) ValidateDeviceAllocation(ctx context.Context, namespace, claimName string, expectedCount int) error

ValidateDeviceAllocation validates that claim is properly allocated

func (*DeviceValidator) ValidateResourceSlice

func (dv *DeviceValidator) ValidateResourceSlice(ctx context.Context, nodeName string) (*resourceapi.ResourceSlice, error)

ValidateResourceSlice validates ResourceSlice for the example driver node

type PrerequisitesInstaller

type PrerequisitesInstaller struct {
	// contains filtered or unexported fields
}

PrerequisitesInstaller manages dra-example-driver installation and cleanup

func NewPrerequisitesInstaller

func NewPrerequisitesInstaller(f *framework.Framework) *PrerequisitesInstaller

NewPrerequisitesInstaller creates a new installer

func (*PrerequisitesInstaller) InstallAll

func (pi *PrerequisitesInstaller) InstallAll(ctx context.Context) error

InstallAll installs the dra-example-driver prerequisites

func (*PrerequisitesInstaller) IsDriverInstalled

func (pi *PrerequisitesInstaller) IsDriverInstalled(ctx context.Context) bool

IsDriverInstalled checks if the driver is already installed

func (*PrerequisitesInstaller) RollbackMutations

func (pi *PrerequisitesInstaller) RollbackMutations(ctx context.Context)

RollbackMutations performs best-effort cleanup after partial install failure

func (*PrerequisitesInstaller) UninstallAll

func (pi *PrerequisitesInstaller) UninstallAll(ctx context.Context) error

UninstallAll removes the driver and cleans up resources

func (*PrerequisitesInstaller) WaitForDriver

func (pi *PrerequisitesInstaller) WaitForDriver(ctx context.Context, timeout time.Duration) error

WaitForDriver waits for the driver to be ready and publishing devices

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL