@@ -794,6 +794,7 @@ func Test_cpusetPlugin_ruleUpdateCbForPods(t *testing.T) {
794794 sandboxID string
795795 }
796796 type args struct {
797+ rule * cpusetRule
797798 pods []* testPod
798799 podAllocs map [string ]ext.ResourceStatus
799800 }
@@ -810,6 +811,15 @@ func Test_cpusetPlugin_ruleUpdateCbForPods(t *testing.T) {
810811 {
811812 name : "set container cpuset" ,
812813 args : args {
814+ rule : & cpusetRule {
815+ sharePools : []ext.CPUSharedPool {
816+ {
817+ Socket : 0 ,
818+ Node : 0 ,
819+ CPUSet : "0-1,5-7" ,
820+ },
821+ },
822+ },
813823 pods : []* testPod {
814824 {
815825 pod : & corev1.Pod {
@@ -834,6 +844,43 @@ func Test_cpusetPlugin_ruleUpdateCbForPods(t *testing.T) {
834844 },
835845 sandboxID : "containerd://pod-with-cpuset-alloc-sandbox-id" ,
836846 },
847+ {
848+ pod : & corev1.Pod {
849+ ObjectMeta : metav1.ObjectMeta {
850+ UID : "pod-cpu-share-uid" ,
851+ Labels : map [string ]string {
852+ ext .LabelPodQoS : string (ext .QoSLS ),
853+ },
854+ },
855+ Spec : corev1.PodSpec {
856+ InitContainers : []corev1.Container {
857+ {
858+ Name : "init-container-with-cpu-share-name" ,
859+ },
860+ },
861+ Containers : []corev1.Container {
862+ {
863+ Name : "container-with-cpu-share-name" ,
864+ },
865+ },
866+ },
867+ Status : corev1.PodStatus {
868+ InitContainerStatuses : []corev1.ContainerStatus {
869+ {
870+ Name : "init-container-with-cpu-share-name" ,
871+ ContainerID : "containerd://init-container-with-cpu-share-uid" ,
872+ },
873+ },
874+ ContainerStatuses : []corev1.ContainerStatus {
875+ {
876+ Name : "container-with-cpu-share-name" ,
877+ ContainerID : "containerd://container-with-cpu-share-uid" ,
878+ },
879+ },
880+ },
881+ },
882+ sandboxID : "containerd://pod-cpu-share-sandbox-id" ,
883+ },
837884 {
838885 pod : & corev1.Pod {
839886 ObjectMeta : metav1.ObjectMeta {
@@ -870,10 +917,13 @@ func Test_cpusetPlugin_ruleUpdateCbForPods(t *testing.T) {
870917 wants : wants {
871918 containersCPUSet : map [string ]string {
872919 "container-with-cpuset-alloc-name" : "2-4" ,
920+ "init-container-with-cpu-share-name" : "0-1,5-7" ,
921+ "container-with-cpu-share-name" : "0-1,5-7" ,
873922 "container-with-bad-cpuset-alloc-name" : "" ,
874923 },
875924 sandboxCPUSet : map [string ]string {
876925 "pod-with-cpuset-alloc-uid" : "2-4" ,
926+ "pod-cpu-share-uid" : "0-1,5-7" ,
877927 "pod-with-bad-cpuset-alloc-uid" : "" ,
878928 },
879929 },
@@ -897,6 +947,11 @@ func Test_cpusetPlugin_ruleUpdateCbForPods(t *testing.T) {
897947 // init cgroups cpuset file
898948 for _ , testPod := range tt .args .pods {
899949 podMeta := podUIDMetas [string (testPod .pod .UID )]
950+ for _ , initContainerStat := range podMeta .Pod .Status .InitContainerStatuses {
951+ containerPath , err := koordletutil .GetContainerCgroupParentDirByID (podMeta .CgroupDir , initContainerStat .ContainerID )
952+ assert .NoError (t , err , "get init container cgroup path during init container cpuset" )
953+ initCPUSet (containerPath , "" , testHelper )
954+ }
900955 for _ , containerStat := range podMeta .Pod .Status .ContainerStatuses {
901956 containerPath , err := koordletutil .GetContainerCgroupParentDirByID (podMeta .CgroupDir , containerStat .ContainerID )
902957 assert .NoError (t , err , "get container cgroup path during init container cpuset" )
@@ -921,7 +976,7 @@ func Test_cpusetPlugin_ruleUpdateCbForPods(t *testing.T) {
921976 }
922977 }
923978
924- p := & cpusetPlugin {executor : resourceexecutor .NewResourceUpdateExecutor ()}
979+ p := & cpusetPlugin {executor : resourceexecutor .NewResourceUpdateExecutor (), rule : tt . args . rule }
925980 stop := make (chan struct {})
926981 defer func () { close (stop ) }()
927982 p .executor .Run (stop )
@@ -940,6 +995,14 @@ func Test_cpusetPlugin_ruleUpdateCbForPods(t *testing.T) {
940995
941996 for _ , testPod := range tt .args .pods {
942997 podMeta := podUIDMetas [string (testPod .pod .UID )]
998+ for _ , initContainerStat := range podMeta .Pod .Status .InitContainerStatuses {
999+ containerPath , err := koordletutil .GetContainerCgroupParentDirByID (podMeta .CgroupDir , initContainerStat .ContainerID )
1000+ assert .NoError (t , err , "get init contaienr cgorup path during check container cpuset" )
1001+ gotCPUSet := getCPUSet (containerPath , testHelper )
1002+ assert .Equal (t , tt .wants .containersCPUSet [initContainerStat .Name ], gotCPUSet ,
1003+ "container cpuset after callback should be equal" )
1004+ }
1005+
9431006 for _ , containerStat := range podMeta .Pod .Status .ContainerStatuses {
9441007 containerPath , err := koordletutil .GetContainerCgroupParentDirByID (podMeta .CgroupDir , containerStat .ContainerID )
9451008 assert .NoError (t , err , "get contaienr cgorup path during check container cpuset" )
0 commit comments