@@ -35,37 +35,28 @@ import (
3535 "github.com/NVIDIA/k8s-device-plugin/tests/e2e/internal"
3636)
3737
38+ var expectedLabelPatterns = k8sLabels {
39+ "nvidia.com/gfd.timestamp" : "[0-9]{10}" ,
40+ "nvidia.com/cuda.driver.major" : "[0-9]+" ,
41+ "nvidia.com/cuda.driver.minor" : "[0-9]+" ,
42+ "nvidia.com/cuda.driver.rev" : "[0-9]*" ,
43+ "nvidia.com/cuda.runtime.major" : "[0-9]+" ,
44+ "nvidia.com/cuda.runtime.minor" : "[0-9]+" ,
45+ "nvidia.com/gpu.machine" : ".*" ,
46+ "nvidia.com/gpu.count" : "[0-9]+" ,
47+ "nvidia.com/gpu.replicas" : "[0-9]+" ,
48+ "nvidia.com/gpu.sharing-strategy" : "[none|mps|time-slicing]" ,
49+ "nvidia.com/gpu.product" : "[A-Za-z_-]+" ,
50+ "nvidia.com/gpu.memory" : "[0-9]+" ,
51+ "nvidia.com/gpu.family" : "[a-z]+" ,
52+ "nvidia.com/mig.capable" : "[true|false]" ,
53+ "nvidia.com/gpu.compute.major" : "[0-9]+" ,
54+ "nvidia.com/gpu.compute.minor" : "[0-9]+" ,
55+ "nvidia.com/mps.capable" : "[true|false]" ,
56+ }
57+
3858// Actual test suite
3959var _ = Describe ("GPU Feature Discovery" , Ordered , Label ("gfd" , "gpu" , "e2e" ), func () {
40- expectedLabelPatterns := k8sLabels {
41- "nvidia.com/gfd.timestamp" : "[0-9]{10}" ,
42- "nvidia.com/cuda.driver.major" : "[0-9]+" ,
43- "nvidia.com/cuda.driver.minor" : "[0-9]+" ,
44- "nvidia.com/cuda.driver.rev" : "[0-9]*" ,
45- "nvidia.com/cuda.runtime.major" : "[0-9]+" ,
46- "nvidia.com/cuda.runtime.minor" : "[0-9]+" ,
47- "nvidia.com/gpu.machine" : ".*" ,
48- "nvidia.com/gpu.count" : "[0-9]+" ,
49- "nvidia.com/gpu.replicas" : "[0-9]+" ,
50- "nvidia.com/gpu.sharing-strategy" : "[none|mps|time-slicing]" ,
51- "nvidia.com/gpu.product" : "[A-Za-z_-]+" ,
52- "nvidia.com/gpu.memory" : "[0-9]+" ,
53- "nvidia.com/gpu.family" : "[a-z]+" ,
54- "nvidia.com/mig.capable" : "[true|false]" ,
55- "nvidia.com/gpu.compute.major" : "[0-9]+" ,
56- "nvidia.com/gpu.compute.minor" : "[0-9]+" ,
57- "nvidia.com/mps.capable" : "[true|false]" ,
58- }
59-
60- defaultCollectorObjects := []string {
61- "pods" ,
62- "nodes" ,
63- "namespaces" ,
64- "deployments" ,
65- "daemonsets" ,
66- "nodeFeature" ,
67- }
68-
6960 // Init global suite vars
7061 var (
7162 helmReleaseName string
@@ -75,6 +66,18 @@ var _ = Describe("GPU Feature Discovery", Ordered, Label("gfd", "gpu", "e2e"), f
7566 diagnosticsCollector diagnostics.Collector
7667 )
7768
69+ collectLogsFrom = []string {
70+ "pods" ,
71+ "nodes" ,
72+ "namespaces" ,
73+ "deployments" ,
74+ "daemonsets" ,
75+ "nodeFeature" ,
76+ }
77+ if CollectLogsFrom != "" && CollectLogsFrom != "default" {
78+ collectLogsFrom = strings .Split (CollectLogsFrom , "," )
79+ }
80+
7881 values := helmValues.Options {
7982 Values : []string {
8083 fmt .Sprintf ("image.repository=%s" , ImageRepo ),
@@ -92,12 +95,6 @@ var _ = Describe("GPU Feature Discovery", Ordered, Label("gfd", "gpu", "e2e"), f
9295 return err == nil
9396 }
9497
95- // check Collector objects
96- collectLogsFrom = defaultCollectorObjects
97- if CollectLogsFrom != "" && CollectLogsFrom != "default" {
98- collectLogsFrom = strings .Split (CollectLogsFrom , "," )
99- }
100-
10198 BeforeAll (func (ctx SpecContext ) {
10299 helmReleaseName = "gfd-e2e-test" + rand .String (5 )
103100
@@ -152,115 +149,66 @@ var _ = Describe("GPU Feature Discovery", Ordered, Label("gfd", "gpu", "e2e"), f
152149 })
153150
154151 When ("When deploying GFD" , Ordered , Label ("serial" ), func () {
155- Context ("NV Driver is not installed" , func () {
156- BeforeEach (func () {
157- // Skip this context when driver is enabled since "NV Driver is installed"
158- // context provides more comprehensive testing
159- if NVIDIA_DRIVER_ENABLED {
160- Skip ("Skipping driver-not-installed tests when NVIDIA_DRIVER_ENABLED is true" )
161- }
162- })
163-
164- It ("it should create nvidia.com timestamp label" , Label ("timestamp" ), func (ctx SpecContext ) {
165- nodeList , err := clientSet .CoreV1 ().Nodes ().List (ctx , metav1.ListOptions {})
166- Expect (err ).NotTo (HaveOccurred ())
167- Expect (len (nodeList .Items )).ToNot (BeZero ())
168-
169- // We pick one node targeted for our NodeFeature objects
170- nodes , err := getNonControlPlaneNodes (ctx , clientSet )
171- Expect (err ).NotTo (HaveOccurred ())
172-
173- targetNodeName := nodes [0 ].Name
174- Expect (targetNodeName ).ToNot (BeEmpty ())
152+ It ("it should create nvidia.com labels" , func (ctx SpecContext ) {
153+ nodeList , err := clientSet .CoreV1 ().Nodes ().List (ctx , metav1.ListOptions {})
154+ Expect (err ).NotTo (HaveOccurred ())
155+ Expect (len (nodeList .Items )).ToNot (BeZero ())
175156
176- By ("Checking the node labels" )
177- labelChecker := map [string ]k8sLabels {
178- targetNodeName : {
179- "nvidia.com/gfd.timestamp" : "[0-9]{10}" ,
180- }}
181- eventuallyNonControlPlaneNodes (ctx , clientSet ).Should (MatchLabels (labelChecker , nodes ))
182- })
183- Context ("and the NodeFeature API is enabled" , func () {
184- It ("gfd should create node feature object" , Label ("nodefeature" ), func (ctx SpecContext ) {
185- By ("Updating GFD Helm chart values" )
186- newValues := values
187- newValues .Values = append (newValues .Values , "nfd.enableNodeFeatureApi=true" )
188- chartSpec .ValuesOptions = newValues
189- chartSpec .Replace = true
190- _ , err := helmClient .UpgradeChart (ctx , & chartSpec , nil )
191- Expect (err ).NotTo (HaveOccurred ())
157+ // We pick one node targeted for our NodeFeature objects
158+ nodes , err := getNonControlPlaneNodes (ctx , clientSet )
159+ Expect (err ).NotTo (HaveOccurred ())
192160
193- By ("Checking if NodeFeature CR object is created" )
194- nodes , err := getNonControlPlaneNodes (ctx , clientSet )
195- Expect (err ).NotTo (HaveOccurred ())
161+ targetNodeName := nodes [0 ].Name
162+ Expect (targetNodeName ).ToNot (BeEmpty ())
196163
197- targetNodeName := nodes [0 ].Name
198- Expect (targetNodeName ).ToNot (BeEmpty ())
199- Eventually (func (g Gomega ) bool {
200- return checkNodeFeatureObject (ctx , targetNodeName )
201- }).WithContext (ctx ).WithPolling (5 * time .Second ).WithTimeout (2 * time .Minute ).Should (BeTrue ())
164+ By ("Checking the node labels" )
202165
203- By ("Checking that node labels are created from NodeFeature object" )
204- labelChecker := map [string ]k8sLabels {
205- targetNodeName : {
206- "nvidia.com/gfd.timestamp" : "[0-9]{10}" ,
207- }}
208- eventuallyNonControlPlaneNodes (ctx , clientSet ).Should (MatchLabels (labelChecker , nodes ))
209- })
210- })
211- })
212-
213- When ("NV Driver is installed" , func () {
214- It ("it should create nvidia.com labels" , Label ("driver" , "labels" ), func (ctx SpecContext ) {
215- if ! NVIDIA_DRIVER_ENABLED {
216- Skip ("NVIDIA_DRIVER_ENABLED is not set" )
166+ labelChecker := map [string ]k8sLabels {
167+ targetNodeName : expectedLabelPatterns ,
168+ }
169+ if ! NVIDIA_DRIVER_ENABLED {
170+ // If the NVIDIA driver is not installed, we only check the
171+ // timestamp label to allow for local testing on non-GPU
172+ // systems.
173+ labelChecker [targetNodeName ] = k8sLabels {
174+ "nvidia.com/gfd.timestamp" : "[0-9]{10}" ,
217175 }
218-
219- By ("Checking the node labels" )
220- nodeList , err := clientSet .CoreV1 ().Nodes ().List (ctx , metav1.ListOptions {})
176+ }
177+ eventuallyNonControlPlaneNodes (ctx , clientSet ).Should (MatchLabels (labelChecker , nodes ))
178+ })
179+ Context ("and the NodeFeature API is enabled" , func () {
180+ It ("gfd should create node feature object" , Label ("nodefeature" ), func (ctx SpecContext ) {
181+ By ("Updating GFD Helm chart values" )
182+ newValues := values
183+ newValues .Values = append (newValues .Values , "nfd.enableNodeFeatureApi=true" )
184+ chartSpec .ValuesOptions = newValues
185+ chartSpec .Replace = true
186+ _ , err := helmClient .UpgradeChart (ctx , & chartSpec , nil )
221187 Expect (err ).NotTo (HaveOccurred ())
222- Expect (len (nodeList .Items )).ToNot (BeZero ())
223188
224- // We pick one node targeted for our NodeFeature objects
189+ By ( "Checking if NodeFeature CR object is created" )
225190 nodes , err := getNonControlPlaneNodes (ctx , clientSet )
226191 Expect (err ).NotTo (HaveOccurred ())
227192
228193 targetNodeName := nodes [0 ].Name
229194 Expect (targetNodeName ).ToNot (BeEmpty ())
195+ Eventually (func (g Gomega ) bool {
196+ return checkNodeFeatureObject (ctx , targetNodeName )
197+ }).WithContext (ctx ).WithPolling (5 * time .Second ).WithTimeout (2 * time .Minute ).Should (BeTrue ())
230198
231- By ("Checking the node labels" )
199+ By ("Checking that node labels are created from NodeFeature object " )
232200 labelChecker := map [string ]k8sLabels {
233- targetNodeName : expectedLabelPatterns }
234- eventuallyNonControlPlaneNodes (ctx , clientSet ).Should (MatchLabels (labelChecker , nodes ))
235- })
236- Context ("and the NodeFeature API is enabled" , func () {
237- It ("gfd should create node feature object" , Label ("driver" , "nodefeature" ), func (ctx SpecContext ) {
238- if ! NVIDIA_DRIVER_ENABLED {
239- Skip ("NVIDIA_DRIVER_ENABLED is not set" )
201+ targetNodeName : expectedLabelPatterns ,
202+ }
203+ if ! NVIDIA_DRIVER_ENABLED {
204+ // If the NVIDIA driver is not installed, we only check the
205+ // timestamp label to allow for local testing on non-GPU
206+ // systems.
207+ labelChecker [targetNodeName ] = k8sLabels {
208+ "nvidia.com/gfd.timestamp" : "[0-9]{10}" ,
240209 }
241- By ("Updating GFD Helm chart values" )
242- newValues := values
243- newValues .Values = append (newValues .Values , "nfd.enableNodeFeatureApi=true" )
244- chartSpec .ValuesOptions = newValues
245- chartSpec .Replace = true
246- _ , err := helmClient .UpgradeChart (ctx , & chartSpec , nil )
247- Expect (err ).NotTo (HaveOccurred ())
248-
249- By ("Checking if NodeFeature CR object is created" )
250- nodes , err := getNonControlPlaneNodes (ctx , clientSet )
251- Expect (err ).NotTo (HaveOccurred ())
252-
253- targetNodeName := nodes [0 ].Name
254- Expect (targetNodeName ).ToNot (BeEmpty ())
255- Eventually (func (g Gomega ) bool {
256- return checkNodeFeatureObject (ctx , targetNodeName )
257- }).WithContext (ctx ).WithPolling (5 * time .Second ).WithTimeout (2 * time .Minute ).Should (BeTrue ())
258-
259- By ("Checking that node labels are created from NodeFeature CR object" )
260- checkForLabels := map [string ]k8sLabels {
261- targetNodeName : expectedLabelPatterns }
262- eventuallyNonControlPlaneNodes (ctx , clientSet ).Should (MatchLabels (checkForLabels , nodes ))
263- })
210+ }
211+ eventuallyNonControlPlaneNodes (ctx , clientSet ).Should (MatchLabels (labelChecker , nodes ))
264212 })
265213 })
266214 })
0 commit comments