@@ -430,6 +430,93 @@ var _ = Describe("[sriov] operator", Ordered, func() {
430430 FieldPath : "metadata.annotations" ,
431431 },
432432 })))
433+
434+ By ("checking the label is present in the pod" )
435+ stdout , stderr , err := pod .ExecCommand (clients , runningPod , "/bin/bash" , "-c" , "cat /etc/podnetinfo/labels" )
436+ Expect (err ).ToNot (HaveOccurred (), fmt .Sprintf ("stdout: %s, stderr: %s" , stdout , stderr ))
437+ Expect (stdout ).To (ContainSubstring ("anyname=\" anyvalue\" " ))
438+ })
439+
440+ It ("should inject also hugepages if requested in the pod" , func () {
441+ var hugepagesName string
442+ var hupagesAmount int64
443+
444+ hasHugepages := false
445+ nodeObj := & corev1.Node {}
446+ Eventually (func () error {
447+ return clients .Get (context .Background (), runtimeclient.ObjectKey {Name : node }, nodeObj )
448+ }, 10 * time .Second , 1 * time .Second ).ShouldNot (HaveOccurred ())
449+
450+ for resourceName , resource := range nodeObj .Status .Allocatable {
451+ if strings .HasPrefix (string (resourceName ), "hugepages" ) && resource .Value () > 0 {
452+ hasHugepages = true
453+ hugepagesName = string (resourceName )
454+ hupagesAmount = resource .Value ()
455+ break
456+ }
457+ }
458+ if ! hasHugepages {
459+ Skip ("No hugepages found on the node" )
460+ }
461+
462+ sriovNetwork := & sriovv1.SriovNetwork {
463+ ObjectMeta : metav1.ObjectMeta {
464+ Name : "test-apivolnetwork" ,
465+ Namespace : operatorNamespace ,
466+ },
467+ Spec : sriovv1.SriovNetworkSpec {
468+ ResourceName : resourceName ,
469+ IPAM : `{"type":"host-local","subnet":"10.10.10.0/24","rangeStart":"10.10.10.171","rangeEnd":"10.10.10.181"}` ,
470+ NetworkNamespace : namespaces .Test ,
471+ }}
472+ err := clients .Create (context .Background (), sriovNetwork )
473+ Expect (err ).ToNot (HaveOccurred ())
474+
475+ waitForNetAttachDef ("test-apivolnetwork" , namespaces .Test )
476+
477+ podDefinition := pod .RedefineWithHugepages (pod .DefineWithNetworks ([]string {sriovNetwork .Name }), hugepagesName , hupagesAmount )
478+ created , err := clients .Pods (namespaces .Test ).Create (context .Background (), podDefinition , metav1.CreateOptions {})
479+ Expect (err ).ToNot (HaveOccurred ())
480+
481+ runningPod := waitForPodRunning (created )
482+
483+ var downwardVolume * corev1.Volume
484+ for _ , v := range runningPod .Spec .Volumes {
485+ if v .Name == volumePodNetInfo {
486+ downwardVolume = v .DeepCopy ()
487+ break
488+ }
489+ }
490+
491+ // In the DownwardAPI the resource injector rename the hugepage size with underscores
492+ // example hugepages-1Gi -> hugepages_1Gi
493+ result := strings .Replace (hugepagesName , "-" , "_" , 1 )
494+ if len (result ) > 0 {
495+ result = result [:len (result )- 1 ]
496+ }
497+
498+ Expect (downwardVolume ).ToNot (BeNil (), "Downward volume not found" )
499+ Expect (downwardVolume .DownwardAPI ).ToNot (BeNil (), "Downward api not found in volume" )
500+ Expect (downwardVolume .DownwardAPI .Items ).To (SatisfyAll (
501+ ContainElement (MatchFields (IgnoreExtras , Fields {
502+ "Path" : Equal (fmt .Sprintf ("%s_request_test" , result )),
503+ "ResourceFieldRef" : PointTo (MatchFields (IgnoreExtras , Fields {
504+ "ContainerName" : Equal ("test" ),
505+ "Resource" : Equal (fmt .Sprintf ("requests.%s" , hugepagesName )),
506+ })),
507+ })), ContainElement (MatchFields (IgnoreExtras , Fields {
508+ "Path" : Equal (fmt .Sprintf ("%s_limit_test" , result )),
509+ "ResourceFieldRef" : PointTo (MatchFields (IgnoreExtras , Fields {
510+ "ContainerName" : Equal ("test" ),
511+ "Resource" : Equal (fmt .Sprintf ("limits.%s" , hugepagesName )),
512+ })),
513+ })), ContainElement (MatchFields (IgnoreExtras , Fields {
514+ "Path" : Equal ("annotations" ),
515+ "FieldRef" : PointTo (MatchFields (IgnoreExtras , Fields {
516+ "APIVersion" : Equal ("v1" ),
517+ "FieldPath" : Equal ("metadata.annotations" ),
518+ })),
519+ }))))
433520 })
434521 })
435522
0 commit comments