Merge pull request #102221 from kikimo/add-hint-to-fake-topology-manager

Add hint to fake topology manager.
This commit is contained in:
Kubernetes Prow Robot 2021-06-02 03:40:05 -07:00 committed by GitHub
commit 1795a98eeb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 83 deletions

View File

@ -44,7 +44,6 @@ 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"
) )
@ -727,7 +726,7 @@ func TestFilterByAffinity(t *testing.T) {
Preferred: true, Preferred: true,
} }
testManager := ManagerImpl{ testManager := ManagerImpl{
topologyAffinityStore: NewFakeTopologyManagerWithHint(t, &fakeHint), topologyAffinityStore: topologymanager.NewFakeManagerWithHint(&fakeHint),
allDevices: allDevices, allDevices: allDevices,
} }
@ -759,44 +758,6 @@ func TestFilterByAffinity(t *testing.T) {
} }
} }
type fakeTopologyManagerWithHint struct {
t *testing.T
hint *topologymanager.TopologyHint
}
// NewFakeTopologyManagerWithHint returns an instance of fake topology manager with specified topology hints
func NewFakeTopologyManagerWithHint(t *testing.T, hint *topologymanager.TopologyHint) topologymanager.Manager {
return &fakeTopologyManagerWithHint{
t: t,
hint: hint,
}
}
func (m *fakeTopologyManagerWithHint) AddHintProvider(h topologymanager.HintProvider) {
m.t.Logf("[fake topologymanager] AddHintProvider HintProvider: %v", h)
}
func (m *fakeTopologyManagerWithHint) AddContainer(pod *v1.Pod, container *v1.Container, containerID string) {
m.t.Logf("[fake topologymanager] AddContainer pod: %v container name: %v container id: %v", format.Pod(pod), container.Name, containerID)
}
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",

View File

@ -28,8 +28,6 @@ import (
"k8s.io/kubernetes/pkg/kubelet/cm/memorymanager/state" "k8s.io/kubernetes/pkg/kubelet/cm/memorymanager/state"
"k8s.io/kubernetes/pkg/kubelet/cm/topologymanager" "k8s.io/kubernetes/pkg/kubelet/cm/topologymanager"
"k8s.io/kubernetes/pkg/kubelet/cm/topologymanager/bitmask" "k8s.io/kubernetes/pkg/kubelet/cm/topologymanager/bitmask"
"k8s.io/kubernetes/pkg/kubelet/lifecycle"
"k8s.io/kubernetes/pkg/kubelet/util/format"
) )
const ( const (
@ -66,44 +64,6 @@ var (
} }
) )
type fakeTopologyManagerWithHint struct {
t *testing.T
hint *topologymanager.TopologyHint
}
// NewFakeTopologyManagerWithHint returns an instance of fake topology manager with specified topology hints
func NewFakeTopologyManagerWithHint(t *testing.T, hint *topologymanager.TopologyHint) topologymanager.Manager {
return &fakeTopologyManagerWithHint{
t: t,
hint: hint,
}
}
func (m *fakeTopologyManagerWithHint) AddHintProvider(h topologymanager.HintProvider) {
m.t.Logf("[fake topologymanager] AddHintProvider HintProvider: %v", h)
}
func (m *fakeTopologyManagerWithHint) AddContainer(pod *v1.Pod, container *v1.Container, containerID string) {
m.t.Logf("[fake topologymanager] AddContainer pod: %v container name: %v container id: %v", format.Pod(pod), container.Name, containerID)
}
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 areMemoryBlocksEqual(mb1, mb2 []state.Block) bool { func areMemoryBlocksEqual(mb1, mb2 []state.Block) bool {
if len(mb1) != len(mb2) { if len(mb1) != len(mb2) {
return false return false
@ -171,7 +131,7 @@ type testStaticPolicy struct {
func initTests(t *testing.T, testCase *testStaticPolicy, hint *topologymanager.TopologyHint) (Policy, state.State, error) { func initTests(t *testing.T, testCase *testStaticPolicy, hint *topologymanager.TopologyHint) (Policy, state.State, error) {
manager := topologymanager.NewFakeManager() manager := topologymanager.NewFakeManager()
if hint != nil { if hint != nil {
manager = NewFakeTopologyManagerWithHint(t, hint) manager = topologymanager.NewFakeManagerWithHint(hint)
} }
p, err := NewPolicyStatic(testCase.machineInfo, testCase.systemReserved, manager) p, err := NewPolicyStatic(testCase.machineInfo, testCase.systemReserved, manager)

View File

@ -22,7 +22,9 @@ import (
"k8s.io/kubernetes/pkg/kubelet/lifecycle" "k8s.io/kubernetes/pkg/kubelet/lifecycle"
) )
type fakeManager struct{} type fakeManager struct {
hint *TopologyHint
}
//NewFakeManager returns an instance of FakeManager //NewFakeManager returns an instance of FakeManager
func NewFakeManager() Manager { func NewFakeManager() Manager {
@ -30,9 +32,21 @@ func NewFakeManager() Manager {
return &fakeManager{} return &fakeManager{}
} }
// NewFakeManagerWithHint returns an instance of fake topology manager with specified topology hints
func NewFakeManagerWithHint(hint *TopologyHint) Manager {
klog.InfoS("NewFakeManagerWithHint")
return &fakeManager{
hint: hint,
}
}
func (m *fakeManager) GetAffinity(podUID string, containerName string) TopologyHint { func (m *fakeManager) GetAffinity(podUID string, containerName string) TopologyHint {
klog.InfoS("GetAffinity", "podUID", podUID, "containerName", containerName) klog.InfoS("GetAffinity", "podUID", podUID, "containerName", containerName)
return TopologyHint{} if m.hint == nil {
return TopologyHint{}
}
return *m.hint
} }
func (m *fakeManager) AddHintProvider(h HintProvider) { func (m *fakeManager) AddHintProvider(h HintProvider) {