@@ -228,6 +228,93 @@ var _ = Describe("[sriov] operator", Ordered, func() {
228228 FieldPath : "metadata.annotations" ,
229229 },
230230 })))
231+
232+ By ("checking the label is present in the pod" )
233+ stdout , stderr , err := pod .ExecCommand (clients , runningPod , "/bin/bash" , "-c" , "cat /etc/podnetinfo/labels" )
234+ Expect (err ).ToNot (HaveOccurred (), fmt .Sprintf ("stdout: %s, stderr: %s" , stdout , stderr ))
235+ Expect (stdout ).To (ContainSubstring ("anyname=\" anyvalue\" " ))
236+ })
237+
238+ It ("should inject also hugepages if requested in the pod" , func () {
239+ var hugepagesName string
240+ var hupagesAmount int64
241+
242+ hasHugepages := false
243+ nodeObj := & corev1.Node {}
244+ Eventually (func () error {
245+ return clients .Get (context .Background (), runtimeclient.ObjectKey {Name : node }, nodeObj )
246+ }, 10 * time .Second , 1 * time .Second ).ShouldNot (HaveOccurred ())
247+
248+ for resourceName , resource := range nodeObj .Status .Allocatable {
249+ if strings .HasPrefix (string (resourceName ), "hugepages" ) && resource .Value () > 0 {
250+ hasHugepages = true
251+ hugepagesName = string (resourceName )
252+ hupagesAmount = resource .Value ()
253+ break
254+ }
255+ }
256+ if ! hasHugepages {
257+ Skip ("No hugepages found on the node" )
258+ }
259+
260+ sriovNetwork := & sriovv1.SriovNetwork {
261+ ObjectMeta : metav1.ObjectMeta {
262+ Name : "test-apivolnetwork" ,
263+ Namespace : operatorNamespace ,
264+ },
265+ Spec : sriovv1.SriovNetworkSpec {
266+ ResourceName : resourceName ,
267+ IPAM : `{"type":"host-local","subnet":"10.10.10.0/24","rangeStart":"10.10.10.171","rangeEnd":"10.10.10.181"}` ,
268+ NetworkNamespace : namespaces .Test ,
269+ }}
270+ err := clients .Create (context .Background (), sriovNetwork )
271+ Expect (err ).ToNot (HaveOccurred ())
272+
273+ waitForNetAttachDef ("test-apivolnetwork" , namespaces .Test )
274+
275+ podDefinition := pod .RedefineWithHugepages (pod .DefineWithNetworks ([]string {sriovNetwork .Name }), hugepagesName , hupagesAmount )
276+ created , err := clients .Pods (namespaces .Test ).Create (context .Background (), podDefinition , metav1.CreateOptions {})
277+ Expect (err ).ToNot (HaveOccurred ())
278+
279+ runningPod := waitForPodRunning (created )
280+
281+ var downwardVolume * corev1.Volume
282+ for _ , v := range runningPod .Spec .Volumes {
283+ if v .Name == volumePodNetInfo {
284+ downwardVolume = v .DeepCopy ()
285+ break
286+ }
287+ }
288+
289+ // In the DownwardAPI the resource injector rename the hugepage size with underscores
290+ // example hugepages-1Gi -> hugepages_1Gi
291+ result := strings .Replace (hugepagesName , "-" , "_" , 1 )
292+ if len (result ) > 0 {
293+ result = result [:len (result )- 1 ]
294+ }
295+
296+ Expect (downwardVolume ).ToNot (BeNil (), "Downward volume not found" )
297+ Expect (downwardVolume .DownwardAPI ).ToNot (BeNil (), "Downward api not found in volume" )
298+ Expect (downwardVolume .DownwardAPI .Items ).To (SatisfyAll (
299+ ContainElement (MatchFields (IgnoreExtras , Fields {
300+ "Path" : Equal (fmt .Sprintf ("%s_request_test" , result )),
301+ "ResourceFieldRef" : PointTo (MatchFields (IgnoreExtras , Fields {
302+ "ContainerName" : Equal ("test" ),
303+ "Resource" : Equal (fmt .Sprintf ("requests.%s" , hugepagesName )),
304+ })),
305+ })), ContainElement (MatchFields (IgnoreExtras , Fields {
306+ "Path" : Equal (fmt .Sprintf ("%s_limit_test" , result )),
307+ "ResourceFieldRef" : PointTo (MatchFields (IgnoreExtras , Fields {
308+ "ContainerName" : Equal ("test" ),
309+ "Resource" : Equal (fmt .Sprintf ("limits.%s" , hugepagesName )),
310+ })),
311+ })), ContainElement (MatchFields (IgnoreExtras , Fields {
312+ "Path" : Equal ("annotations" ),
313+ "FieldRef" : PointTo (MatchFields (IgnoreExtras , Fields {
314+ "APIVersion" : Equal ("v1" ),
315+ "FieldPath" : Equal ("metadata.annotations" ),
316+ })),
317+ }))))
231318 })
232319 })
233320
0 commit comments