mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-05 11:12:03 +00:00
add a reusable fakeTopologyManagerWithHint{}
This commit is contained in:
@@ -44,6 +44,7 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/kubelet/config"
|
"k8s.io/kubernetes/pkg/kubelet/config"
|
||||||
"k8s.io/kubernetes/pkg/kubelet/lifecycle"
|
"k8s.io/kubernetes/pkg/kubelet/lifecycle"
|
||||||
"k8s.io/kubernetes/pkg/kubelet/pluginmanager"
|
"k8s.io/kubernetes/pkg/kubelet/pluginmanager"
|
||||||
|
"k8s.io/kubernetes/pkg/kubelet/util/format"
|
||||||
schedulerframework "k8s.io/kubernetes/pkg/scheduler/framework"
|
schedulerframework "k8s.io/kubernetes/pkg/scheduler/framework"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -720,8 +721,13 @@ func TestFilterByAffinity(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fakeAffinity, _ := bitmask.NewBitMask(2)
|
||||||
|
fakeHint := topologymanager.TopologyHint{
|
||||||
|
NUMANodeAffinity: fakeAffinity,
|
||||||
|
Preferred: true,
|
||||||
|
}
|
||||||
testManager := ManagerImpl{
|
testManager := ManagerImpl{
|
||||||
topologyAffinityStore: newFakeTopologyManager(),
|
topologyAffinityStore: NewFakeTopologyManagerWithHint(t, &fakeHint),
|
||||||
allDevices: allDevices,
|
allDevices: allDevices,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -753,23 +759,45 @@ func TestFilterByAffinity(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type fakeTopologyManager struct {
|
type fakeTopologyManagerWithHint struct {
|
||||||
topologymanager.Manager
|
t *testing.T
|
||||||
|
hint *topologymanager.TopologyHint
|
||||||
}
|
}
|
||||||
|
|
||||||
func newFakeTopologyManager() topologymanager.Manager {
|
// NewFakeTopologyManagerWithHint returns an instance of fake topology manager with specified topology hints
|
||||||
return &fakeTopologyManager{}
|
func NewFakeTopologyManagerWithHint(t *testing.T, hint *topologymanager.TopologyHint) topologymanager.Manager {
|
||||||
}
|
return &fakeTopologyManagerWithHint{
|
||||||
|
t: t,
|
||||||
func (m *fakeTopologyManager) GetAffinity(podUID string, containerName string) topologymanager.TopologyHint {
|
hint: hint,
|
||||||
// return hint with numa2 set
|
|
||||||
affinity, _ := bitmask.NewBitMask(2)
|
|
||||||
return topologymanager.TopologyHint{
|
|
||||||
NUMANodeAffinity: affinity,
|
|
||||||
Preferred: true,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *fakeTopologyManagerWithHint) AddHintProvider(h topologymanager.HintProvider) {
|
||||||
|
m.t.Logf("[fake topologymanager] AddHintProvider HintProvider: %v", h)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *fakeTopologyManagerWithHint) AddContainer(pod *v1.Pod, containerID string) error {
|
||||||
|
m.t.Logf("[fake topologymanager] AddContainer pod: %v container id: %v", format.Pod(pod), containerID)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *fakeTopologyManagerWithHint) RemoveContainer(containerID string) error {
|
||||||
|
m.t.Logf("[fake topologymanager] RemoveContainer container id: %v", containerID)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *fakeTopologyManagerWithHint) Admit(attrs *lifecycle.PodAdmitAttributes) lifecycle.PodAdmitResult {
|
||||||
|
m.t.Logf("[fake topologymanager] Topology Admit Handler")
|
||||||
|
return lifecycle.PodAdmitResult{
|
||||||
|
Admit: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *fakeTopologyManagerWithHint) GetAffinity(podUID string, containerName string) topologymanager.TopologyHint {
|
||||||
|
m.t.Logf("[fake topologymanager] GetAffinity podUID: %v container name: %v", podUID, containerName)
|
||||||
|
return *m.hint
|
||||||
|
}
|
||||||
|
|
||||||
func TestPodContainerDeviceAllocation(t *testing.T) {
|
func TestPodContainerDeviceAllocation(t *testing.T) {
|
||||||
res1 := TestResource{
|
res1 := TestResource{
|
||||||
resourceName: "domain1.com/resource1",
|
resourceName: "domain1.com/resource1",
|
||||||
|
Reference in New Issue
Block a user