@@ -24,6 +24,7 @@ import (
2424 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2525)
2626
27+ // DynamicClient returns a dynamic client for the kubernetes cluster.
2728func (h * ValidatorHarness ) DynamicClient () dynamic.Interface {
2829 if h .dynamicClient == nil {
2930 dynamicClient , err := dynamic .NewForConfig (h .restConfig )
@@ -35,6 +36,7 @@ func (h *ValidatorHarness) DynamicClient() dynamic.Interface {
3536 return h .dynamicClient
3637}
3738
39+ // DeviceClass is a wrapper around the DRA DeviceClass type.
3840type DeviceClass struct {
3941 u * unstructured.Unstructured
4042}
@@ -49,6 +51,7 @@ var deviceClassGVR = schema.GroupVersionResource{
4951 Resource : "deviceclasses" ,
5052}
5153
54+ // ListDeviceClasses lists all device classes in the cluster.
5255func (h * ValidatorHarness ) ListDeviceClasses () []* DeviceClass {
5356 objectList , err := h .DynamicClient ().Resource (deviceClassGVR ).List (h .Context (), metav1.ListOptions {})
5457 if err != nil {
@@ -60,3 +63,41 @@ func (h *ValidatorHarness) ListDeviceClasses() []*DeviceClass {
6063 }
6164 return out
6265}
66+
67+ // HasDeviceClass returns true if a device class with the given name exists.
68+ func (h * ValidatorHarness ) HasDeviceClass (name string ) bool {
69+ for _ , deviceClass := range h .ListDeviceClasses () {
70+ if deviceClass .Name () == name {
71+ return true
72+ }
73+ }
74+ return false
75+ }
76+
77+ // ResourceSlice is a wrapper around the DRA ResourceSlice type.
78+ type ResourceSlice struct {
79+ u * unstructured.Unstructured
80+ }
81+
82+ func (d * ResourceSlice ) Name () string {
83+ return d .u .GetName ()
84+ }
85+
86+ var resourceSliceGVR = schema.GroupVersionResource {
87+ Group : "resource.k8s.io" ,
88+ Version : "v1" ,
89+ Resource : "resourceslices" ,
90+ }
91+
92+ // ListResourceSlices lists all resource slices in the cluster.
93+ func (h * ValidatorHarness ) ListResourceSlices () []* ResourceSlice {
94+ objectList , err := h .DynamicClient ().Resource (resourceSliceGVR ).List (h .Context (), metav1.ListOptions {})
95+ if err != nil {
96+ h .Fatalf ("failed to list resource slices: %v" , err )
97+ }
98+ var out []* ResourceSlice
99+ for i := range objectList .Items {
100+ out = append (out , & ResourceSlice {u : & objectList .Items [i ]})
101+ }
102+ return out
103+ }
0 commit comments