@@ -465,6 +465,94 @@ 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+ Eventually (func () error {
511+ netAttDef := & netattdefv1.NetworkAttachmentDefinition {}
512+ return clients .Get (context .Background (), runtimeclient.ObjectKey {Name : "test-apivolnetwork" , Namespace : namespaces .Test }, netAttDef )
513+ }, (10 + snoTimeoutMultiplier * 110 )* time .Second , 1 * time .Second ).ShouldNot (HaveOccurred ())
514+
515+ podDefinition := pod .RedefineWithHugepages (pod .DefineWithNetworks ([]string {sriovNetwork .Name }), hugepagesName , hupagesAmount )
516+ created , err := clients .Pods (namespaces .Test ).Create (context .Background (), podDefinition , metav1.CreateOptions {})
517+ Expect (err ).ToNot (HaveOccurred ())
518+
519+ runningPod := waitForPodRunning (created )
520+
521+ var downwardVolume * corev1.Volume
522+ for _ , v := range runningPod .Spec .Volumes {
523+ if v .Name == volumePodNetInfo {
524+ downwardVolume = v .DeepCopy ()
525+ break
526+ }
527+ }
528+
529+ result := strings .Replace (hugepagesName , "-" , "_" , 1 )
530+ if len (result ) > 0 {
531+ result = result [:len (result )- 1 ]
532+ }
533+
534+ Expect (downwardVolume ).ToNot (BeNil (), "Downward volume not found" )
535+ Expect (downwardVolume .DownwardAPI ).ToNot (BeNil (), "Downward api not found in volume" )
536+ Expect (downwardVolume .DownwardAPI .Items ).To (SatisfyAll (
537+ ContainElement (MatchFields (IgnoreExtras , Fields {
538+ "Path" : Equal (fmt .Sprintf ("%s_request_test" , result )),
539+ "ResourceFieldRef" : PointTo (MatchFields (IgnoreExtras , Fields {
540+ "ContainerName" : Equal ("test" ),
541+ "Resource" : Equal (fmt .Sprintf ("requests.%s" , hugepagesName )),
542+ })),
543+ })), ContainElement (MatchFields (IgnoreExtras , Fields {
544+ "Path" : Equal (fmt .Sprintf ("%s_limit_test" , result )),
545+ "ResourceFieldRef" : PointTo (MatchFields (IgnoreExtras , Fields {
546+ "ContainerName" : Equal ("test" ),
547+ "Resource" : Equal (fmt .Sprintf ("limits.%s" , hugepagesName )),
548+ })),
549+ })), ContainElement (MatchFields (IgnoreExtras , Fields {
550+ "Path" : Equal ("annotations" ),
551+ "FieldRef" : PointTo (MatchFields (IgnoreExtras , Fields {
552+ "APIVersion" : Equal ("v1" ),
553+ "FieldPath" : Equal ("metadata.annotations" ),
554+ })),
555+ }))))
468556 })
469557 })
470558
0 commit comments