@@ -107,6 +107,15 @@ func TestStaticPolicyStart(t *testing.T) {
107
107
stDefaultCPUSet : cpuset .New (0 , 1 ),
108
108
expErr : fmt .Errorf ("not all reserved cpus: \" 0,6\" are present in defaultCpuSet: \" 0-1\" " ),
109
109
},
110
+ {
111
+ description : "some of reserved cores are present in available cpuset (StrictCPUReservationOption)" ,
112
+ topo : topoDualSocketHT ,
113
+ numReservedCPUs : 2 ,
114
+ options : map [string ]string {StrictCPUReservationOption : "true" },
115
+ stAssignments : state.ContainerCPUAssignments {},
116
+ stDefaultCPUSet : cpuset .New (0 , 1 ),
117
+ expErr : fmt .Errorf ("some of strictly reserved cpus: \" 0\" are present in defaultCpuSet: \" 0-1\" " ),
118
+ },
110
119
{
111
120
description : "assigned core 2 is still present in available cpuset" ,
112
121
topo : topoDualSocketHT ,
@@ -118,6 +127,18 @@ func TestStaticPolicyStart(t *testing.T) {
118
127
stDefaultCPUSet : cpuset .New (2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 ),
119
128
expErr : fmt .Errorf ("pod: fakePod, container: 0 cpuset: \" 0-2\" overlaps with default cpuset \" 2-11\" " ),
120
129
},
130
+ {
131
+ description : "assigned core 2 is still present in available cpuset (StrictCPUReservationOption)" ,
132
+ topo : topoDualSocketHT ,
133
+ options : map [string ]string {StrictCPUReservationOption : "true" },
134
+ stAssignments : state.ContainerCPUAssignments {
135
+ "fakePod" : map [string ]cpuset.CPUSet {
136
+ "0" : cpuset .New (0 , 1 , 2 ),
137
+ },
138
+ },
139
+ stDefaultCPUSet : cpuset .New (2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 ),
140
+ expErr : fmt .Errorf ("pod: fakePod, container: 0 cpuset: \" 0-2\" overlaps with default cpuset \" 2-11\" " ),
141
+ },
121
142
{
122
143
description : "core 12 is not present in topology but is in state cpuset" ,
123
144
topo : topoDualSocketHT ,
@@ -145,7 +166,8 @@ func TestStaticPolicyStart(t *testing.T) {
145
166
}
146
167
for _ , testCase := range testCases {
147
168
t .Run (testCase .description , func (t * testing.T ) {
148
- p , _ := NewStaticPolicy (testCase .topo , testCase .numReservedCPUs , cpuset .New (), topologymanager .NewFakeManager (), nil )
169
+ featuregatetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , pkgfeatures .CPUManagerPolicyAlphaOptions , true )
170
+ p , _ := NewStaticPolicy (testCase .topo , testCase .numReservedCPUs , cpuset .New (), topologymanager .NewFakeManager (), testCase .options )
149
171
policy := p .(* staticPolicy )
150
172
st := & mockState {
151
173
assignments : testCase .stAssignments ,
@@ -939,17 +961,18 @@ func TestTopologyAwareAllocateCPUs(t *testing.T) {
939
961
// above test cases are without kubelet --reserved-cpus cmd option
940
962
// the following tests are with --reserved-cpus configured
941
963
type staticPolicyTestWithResvList struct {
942
- description string
943
- topo * topology.CPUTopology
944
- numReservedCPUs int
945
- reserved cpuset.CPUSet
946
- stAssignments state.ContainerCPUAssignments
947
- stDefaultCPUSet cpuset.CPUSet
948
- pod * v1.Pod
949
- expErr error
950
- expNewErr error
951
- expCPUAlloc bool
952
- expCSet cpuset.CPUSet
964
+ description string
965
+ topo * topology.CPUTopology
966
+ numReservedCPUs int
967
+ reserved cpuset.CPUSet
968
+ cpuPolicyOptions map [string ]string
969
+ stAssignments state.ContainerCPUAssignments
970
+ stDefaultCPUSet cpuset.CPUSet
971
+ pod * v1.Pod
972
+ expErr error
973
+ expNewErr error
974
+ expCPUAlloc bool
975
+ expCSet cpuset.CPUSet
953
976
}
954
977
955
978
func TestStaticPolicyStartWithResvList (t * testing.T ) {
@@ -963,6 +986,16 @@ func TestStaticPolicyStartWithResvList(t *testing.T) {
963
986
stDefaultCPUSet : cpuset .New (),
964
987
expCSet : cpuset .New (0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 ),
965
988
},
989
+ {
990
+ description : "empty cpuset with StrictCPUReservationOption enabled" ,
991
+ topo : topoDualSocketHT ,
992
+ numReservedCPUs : 2 ,
993
+ reserved : cpuset .New (0 , 1 ),
994
+ cpuPolicyOptions : map [string ]string {StrictCPUReservationOption : "true" },
995
+ stAssignments : state.ContainerCPUAssignments {},
996
+ stDefaultCPUSet : cpuset .New (),
997
+ expCSet : cpuset .New (2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 ),
998
+ },
966
999
{
967
1000
description : "reserved cores 0 & 1 are not present in available cpuset" ,
968
1001
topo : topoDualSocketHT ,
@@ -972,6 +1005,16 @@ func TestStaticPolicyStartWithResvList(t *testing.T) {
972
1005
stDefaultCPUSet : cpuset .New (2 , 3 , 4 , 5 ),
973
1006
expErr : fmt .Errorf ("not all reserved cpus: \" 0-1\" are present in defaultCpuSet: \" 2-5\" " ),
974
1007
},
1008
+ {
1009
+ description : "reserved cores 0 & 1 are present in available cpuset with StrictCPUReservationOption enabled" ,
1010
+ topo : topoDualSocketHT ,
1011
+ numReservedCPUs : 2 ,
1012
+ reserved : cpuset .New (0 , 1 ),
1013
+ cpuPolicyOptions : map [string ]string {StrictCPUReservationOption : "true" },
1014
+ stAssignments : state.ContainerCPUAssignments {},
1015
+ stDefaultCPUSet : cpuset .New (0 , 1 , 2 , 3 , 4 , 5 ),
1016
+ expErr : fmt .Errorf ("some of strictly reserved cpus: \" 0-1\" are present in defaultCpuSet: \" 0-5\" " ),
1017
+ },
975
1018
{
976
1019
description : "inconsistency between numReservedCPUs and reserved" ,
977
1020
topo : topoDualSocketHT ,
@@ -984,7 +1027,8 @@ func TestStaticPolicyStartWithResvList(t *testing.T) {
984
1027
}
985
1028
for _ , testCase := range testCases {
986
1029
t .Run (testCase .description , func (t * testing.T ) {
987
- p , err := NewStaticPolicy (testCase .topo , testCase .numReservedCPUs , testCase .reserved , topologymanager .NewFakeManager (), nil )
1030
+ featuregatetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , pkgfeatures .CPUManagerPolicyAlphaOptions , true )
1031
+ p , err := NewStaticPolicy (testCase .topo , testCase .numReservedCPUs , testCase .reserved , topologymanager .NewFakeManager (), testCase .cpuPolicyOptions )
988
1032
if ! reflect .DeepEqual (err , testCase .expNewErr ) {
989
1033
t .Errorf ("StaticPolicy Start() error (%v). expected error: %v but got: %v" ,
990
1034
testCase .description , testCase .expNewErr , err )
0 commit comments