@@ -20,12 +20,8 @@ import (
2020 "strconv"
2121 "testing"
2222
23- "github.com/stretchr/testify/assert"
2423 corev1 "k8s.io/api/core/v1"
25- "k8s.io/utils/pointer"
2624
27- ext "github.com/koordinator-sh/koordinator/apis/extension"
28- runtimeapi "github.com/koordinator-sh/koordinator/apis/runtime/v1alpha1"
2925 "github.com/koordinator-sh/koordinator/pkg/util"
3026 "github.com/koordinator-sh/koordinator/pkg/util/system"
3127)
@@ -34,101 +30,12 @@ func initCPUBvt(dirWithKube string, value int64, helper *system.FileTestUtil) {
3430 helper .WriteCgroupFileContents (dirWithKube , system .CPUBVTWarpNs , strconv .FormatInt (value , 10 ))
3531}
3632
37- func getPodCPUBurst (podDirWithKube string , helper * system.FileTestUtil ) int64 {
33+ func getPodCPUBvt (podDirWithKube string , helper * system.FileTestUtil ) int64 {
3834 valueStr := helper .ReadCgroupFileContents (podDirWithKube , system .CPUBVTWarpNs )
3935 value , _ := strconv .ParseInt (valueStr , 10 , 64 )
4036 return value
4137}
4238
43- func Test_bvtPlugin_PreRunPodSandbox (t * testing.T ) {
44- defaultRule := & bvtRule {
45- podQOSParams : map [ext.QoSClass ]int64 {
46- ext .QoSLSR : 2 ,
47- ext .QoSLS : 2 ,
48- ext .QoSBE : - 1 ,
49- },
50- kubeQOSDirParams : map [corev1.PodQOSClass ]int64 {
51- corev1 .PodQOSGuaranteed : 0 ,
52- corev1 .PodQOSBurstable : 2 ,
53- corev1 .PodQOSBestEffort : - 1 ,
54- },
55- kubeQOSPodParams : map [corev1.PodQOSClass ]int64 {
56- corev1 .PodQOSGuaranteed : 2 ,
57- corev1 .PodQOSBurstable : 2 ,
58- corev1 .PodQOSBestEffort : - 1 ,
59- },
60- }
61- type fields struct {
62- systemSupported * bool
63- }
64- type args struct {
65- request * runtimeapi.PodSandboxHookRequest
66- response * runtimeapi.PodSandboxHookResponse
67- }
68- type want struct {
69- bvtValue int64
70- }
71- tests := []struct {
72- name string
73- fields fields
74- args args
75- want want
76- }{
77- {
78- name : "set ls pod bvt" ,
79- fields : fields {
80- systemSupported : pointer .Bool (true ),
81- },
82- args : args {
83- request : & runtimeapi.PodSandboxHookRequest {
84- Labels : map [string ]string {
85- ext .LabelPodQoS : string (ext .QoSLS ),
86- },
87- CgroupParent : "kubepods/pod-guaranteed-test-uid/" ,
88- },
89- response : & runtimeapi.PodSandboxHookResponse {},
90- },
91- want : want {
92- bvtValue : 2 ,
93- },
94- },
95- {
96- name : "set be pod bvt" ,
97- fields : fields {
98- systemSupported : pointer .Bool (true ),
99- },
100- args : args {
101- request : & runtimeapi.PodSandboxHookRequest {
102- Labels : map [string ]string {
103- ext .LabelPodQoS : string (ext .QoSBE ),
104- },
105- CgroupParent : "kubepods/besteffort/pod-besteffort-test-uid/" ,
106- },
107- response : & runtimeapi.PodSandboxHookResponse {},
108- },
109- want : want {
110- bvtValue : - 1 ,
111- },
112- },
113- }
114- for _ , tt := range tests {
115- t .Run (tt .name , func (t * testing.T ) {
116- testHelper := system .NewFileTestUtil (t )
117- initCPUBvt (tt .args .request .CgroupParent , 0 , testHelper )
118-
119- b := & bvtPlugin {
120- rule : defaultRule ,
121- sysSupported : tt .fields .systemSupported ,
122- }
123- err := b .PreRunPodSandbox (tt .args .request , tt .args .response )
124- assert .NoError (t , err )
125-
126- gotBvt := getPodCPUBurst (tt .args .request .CgroupParent , testHelper )
127- assert .Equal (t , tt .want .bvtValue , gotBvt , "pod bvt should equal" )
128- })
129- }
130- }
131-
13239func Test_bvtPlugin_systemSupported (t * testing.T ) {
13340 kubeRootDir := util .GetKubeQosRelativePath (corev1 .PodQOSGuaranteed )
13441 type fields struct {
@@ -165,3 +72,10 @@ func Test_bvtPlugin_systemSupported(t *testing.T) {
16572 })
16673 }
16774}
75+
76+ func Test_bvtPlugin_Register (t * testing.T ) {
77+ t .Run ("register bvt plugin" , func (t * testing.T ) {
78+ b := & bvtPlugin {}
79+ b .Register ()
80+ })
81+ }
0 commit comments