mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
add GetAllocatableCPUs test in cpumanager
Signed-off-by: Garrybest <garrybest@foxmail.com>
This commit is contained in:
parent
d446f5f90e
commit
95eb5670cf
@ -31,6 +31,7 @@ import (
|
|||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
|
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
|
||||||
|
|
||||||
"k8s.io/kubernetes/pkg/kubelet/cm/containermap"
|
"k8s.io/kubernetes/pkg/kubelet/cm/containermap"
|
||||||
"k8s.io/kubernetes/pkg/kubelet/cm/cpumanager/state"
|
"k8s.io/kubernetes/pkg/kubelet/cm/cpumanager/state"
|
||||||
"k8s.io/kubernetes/pkg/kubelet/cm/cpumanager/topology"
|
"k8s.io/kubernetes/pkg/kubelet/cm/cpumanager/topology"
|
||||||
@ -1364,3 +1365,66 @@ func TestCPUManagerHandlePolicyOptions(t *testing.T) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCPUManagerGetAllocatableCPUs(t *testing.T) {
|
||||||
|
nonePolicy, _ := NewNonePolicy(nil)
|
||||||
|
staticPolicy, _ := NewStaticPolicy(
|
||||||
|
&topology.CPUTopology{
|
||||||
|
NumCPUs: 4,
|
||||||
|
NumSockets: 1,
|
||||||
|
NumCores: 4,
|
||||||
|
CPUDetails: map[int]topology.CPUInfo{
|
||||||
|
0: {CoreID: 0, SocketID: 0},
|
||||||
|
1: {CoreID: 1, SocketID: 0},
|
||||||
|
2: {CoreID: 2, SocketID: 0},
|
||||||
|
3: {CoreID: 3, SocketID: 0},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
1,
|
||||||
|
cpuset.NewCPUSet(0),
|
||||||
|
topologymanager.NewFakeManager(),
|
||||||
|
nil)
|
||||||
|
|
||||||
|
testCases := []struct {
|
||||||
|
description string
|
||||||
|
policy Policy
|
||||||
|
expAllocatableCPUs cpuset.CPUSet
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
description: "None Policy",
|
||||||
|
policy: nonePolicy,
|
||||||
|
expAllocatableCPUs: cpuset.NewCPUSet(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
description: "Static Policy",
|
||||||
|
policy: staticPolicy,
|
||||||
|
expAllocatableCPUs: cpuset.NewCPUSet(1, 2, 3),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
mgr := &manager{
|
||||||
|
policy: testCase.policy,
|
||||||
|
activePods: func() []*v1.Pod { return nil },
|
||||||
|
state: &mockState{
|
||||||
|
assignments: state.ContainerCPUAssignments{},
|
||||||
|
defaultCPUSet: cpuset.NewCPUSet(0, 1, 2, 3),
|
||||||
|
},
|
||||||
|
lastUpdateState: state.NewMemoryState(),
|
||||||
|
containerMap: containermap.NewContainerMap(),
|
||||||
|
podStatusProvider: mockPodStatusProvider{},
|
||||||
|
sourcesReady: &sourcesReadyStub{},
|
||||||
|
}
|
||||||
|
mgr.sourcesReady = &sourcesReadyStub{}
|
||||||
|
mgr.allocatableCPUs = testCase.policy.GetAllocatableCPUs(mgr.state)
|
||||||
|
|
||||||
|
pod := makePod("fakePod", "fakeContainer", "2", "2")
|
||||||
|
container := &pod.Spec.Containers[0]
|
||||||
|
|
||||||
|
_ = mgr.Allocate(pod, container)
|
||||||
|
|
||||||
|
if !mgr.GetAllocatableCPUs().Equals(testCase.expAllocatableCPUs) {
|
||||||
|
t.Errorf("Policy GetAllocatableCPUs() error (%v). expected cpuset %v for container %v but got %v",
|
||||||
|
testCase.description, testCase.expAllocatableCPUs, "fakeContainer", mgr.GetAllocatableCPUs())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user