@@ -465,6 +465,93 @@ var _ = Describe("[sriov] operator", Ordered, func() {
465465 FieldPath : "metadata.annotations" ,
466466 },
467467 })))
468+
469+ By ("checking the label is present in the pod" )
470+ stdout , stderr , err := pod .ExecCommand (clients , runningPod , "/bin/bash" , "-c" , "cat /etc/podnetinfo/labels" )
471+ Expect (err ).ToNot (HaveOccurred (), fmt .Sprintf ("stdout: %s, stderr: %s" , stdout , stderr ))
472+ Expect (stdout ).To (ContainSubstring ("anyname=\" anyvalue\" " ))
473+ })
474+
475+ It ("should inject also hugepages if requested in the pod" , func () {
476+ var hugepagesName string
477+ var hupagesAmount int64
478+
479+ hasHugepages := false
480+ nodeObj := & corev1.Node {}
481+ Eventually (func () error {
482+ return clients .Get (context .Background (), runtimeclient.ObjectKey {Name : node }, nodeObj )
483+ }, 10 * time .Second , 1 * time .Second ).ShouldNot (HaveOccurred ())
484+
485+ for resourceName , resource := range nodeObj .Status .Allocatable {
486+ if strings .HasPrefix (string (resourceName ), "hugepages" ) && resource .Value () > 0 {
487+ hasHugepages = true
488+ hugepagesName = string (resourceName )
489+ hupagesAmount = resource .Value ()
490+ break
491+ }
492+ }
493+ if ! hasHugepages {
494+ Skip ("No hugepages found on the node" )
495+ }
496+
497+ sriovNetwork := & sriovv1.SriovNetwork {
498+ ObjectMeta : metav1.ObjectMeta {
499+ Name : "test-apivolnetwork" ,
500+ Namespace : operatorNamespace ,
501+ },
502+ Spec : sriovv1.SriovNetworkSpec {
503+ ResourceName : resourceName ,
504+ IPAM : `{"type":"host-local","subnet":"10.10.10.0/24","rangeStart":"10.10.10.171","rangeEnd":"10.10.10.181"}` ,
505+ NetworkNamespace : namespaces .Test ,
506+ }}
507+ err := clients .Create (context .Background (), sriovNetwork )
508+ Expect (err ).ToNot (HaveOccurred ())
509+
510+ waitForNetAttachDef ("test-apivolnetwork" , namespaces .Test )
511+
512+ podDefinition := pod .RedefineWithHugepages (pod .DefineWithNetworks ([]string {sriovNetwork .Name }), hugepagesName , hupagesAmount )
513+ created , err := clients .Pods (namespaces .Test ).Create (context .Background (), podDefinition , metav1.CreateOptions {})
514+ Expect (err ).ToNot (HaveOccurred ())
515+
516+ runningPod := waitForPodRunning (created )
517+
518+ var downwardVolume * corev1.Volume
519+ for _ , v := range runningPod .Spec .Volumes {
520+ if v .Name == volumePodNetInfo {
521+ downwardVolume = v .DeepCopy ()
522+ break
523+ }
524+ }
525+
526+ // In the DownwardAPI the resource injector rename the hugepage size with underscores
527+ // example hugepages-1Gi -> hugepages_1Gi
528+ result := strings .Replace (hugepagesName , "-" , "_" , 1 )
529+ if len (result ) > 0 {
530+ result = result [:len (result )- 1 ]
531+ }
532+
533+ Expect (downwardVolume ).ToNot (BeNil (), "Downward volume not found" )
534+ Expect (downwardVolume .DownwardAPI ).ToNot (BeNil (), "Downward api not found in volume" )
535+ Expect (downwardVolume .DownwardAPI .Items ).To (SatisfyAll (
536+ ContainElement (MatchFields (IgnoreExtras , Fields {
537+ "Path" : Equal (fmt .Sprintf ("%s_request_test" , result )),
538+ "ResourceFieldRef" : PointTo (MatchFields (IgnoreExtras , Fields {
539+ "ContainerName" : Equal ("test" ),
540+ "Resource" : Equal (fmt .Sprintf ("requests.%s" , hugepagesName )),
541+ })),
542+ })), ContainElement (MatchFields (IgnoreExtras , Fields {
543+ "Path" : Equal (fmt .Sprintf ("%s_limit_test" , result )),
544+ "ResourceFieldRef" : PointTo (MatchFields (IgnoreExtras , Fields {
545+ "ContainerName" : Equal ("test" ),
546+ "Resource" : Equal (fmt .Sprintf ("limits.%s" , hugepagesName )),
547+ })),
548+ })), ContainElement (MatchFields (IgnoreExtras , Fields {
549+ "Path" : Equal ("annotations" ),
550+ "FieldRef" : PointTo (MatchFields (IgnoreExtras , Fields {
551+ "APIVersion" : Equal ("v1" ),
552+ "FieldPath" : Equal ("metadata.annotations" ),
553+ })),
554+ }))))
468555 })
469556 })
470557
0 commit comments