diff --git a/pkg/kubelet/cm/devicemanager/manager_test.go b/pkg/kubelet/cm/devicemanager/manager_test.go index 61031c728e1..0f74dd5a488 100644 --- a/pkg/kubelet/cm/devicemanager/manager_test.go +++ b/pkg/kubelet/cm/devicemanager/manager_test.go @@ -44,7 +44,6 @@ import ( "k8s.io/kubernetes/pkg/kubelet/config" "k8s.io/kubernetes/pkg/kubelet/lifecycle" "k8s.io/kubernetes/pkg/kubelet/pluginmanager" - "k8s.io/kubernetes/pkg/kubelet/util/format" schedulerframework "k8s.io/kubernetes/pkg/scheduler/framework" ) @@ -727,7 +726,7 @@ func TestFilterByAffinity(t *testing.T) { Preferred: true, } testManager := ManagerImpl{ - topologyAffinityStore: NewFakeTopologyManagerWithHint(t, &fakeHint), + topologyAffinityStore: topologymanager.NewFakeManagerWithHint(&fakeHint), 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) { res1 := TestResource{ resourceName: "domain1.com/resource1", diff --git a/pkg/kubelet/cm/memorymanager/policy_static_test.go b/pkg/kubelet/cm/memorymanager/policy_static_test.go index ef30457215c..d583437be65 100644 --- a/pkg/kubelet/cm/memorymanager/policy_static_test.go +++ b/pkg/kubelet/cm/memorymanager/policy_static_test.go @@ -28,8 +28,6 @@ import ( "k8s.io/kubernetes/pkg/kubelet/cm/memorymanager/state" "k8s.io/kubernetes/pkg/kubelet/cm/topologymanager" "k8s.io/kubernetes/pkg/kubelet/cm/topologymanager/bitmask" - "k8s.io/kubernetes/pkg/kubelet/lifecycle" - "k8s.io/kubernetes/pkg/kubelet/util/format" ) 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 { if len(mb1) != len(mb2) { return false @@ -171,7 +131,7 @@ type testStaticPolicy struct { func initTests(t *testing.T, testCase *testStaticPolicy, hint *topologymanager.TopologyHint) (Policy, state.State, error) { manager := topologymanager.NewFakeManager() if hint != nil { - manager = NewFakeTopologyManagerWithHint(t, hint) + manager = topologymanager.NewFakeManagerWithHint(hint) } p, err := NewPolicyStatic(testCase.machineInfo, testCase.systemReserved, manager) diff --git a/pkg/kubelet/cm/topologymanager/fake_topology_manager.go b/pkg/kubelet/cm/topologymanager/fake_topology_manager.go index 1e7a831108d..407691e98f0 100644 --- a/pkg/kubelet/cm/topologymanager/fake_topology_manager.go +++ b/pkg/kubelet/cm/topologymanager/fake_topology_manager.go @@ -22,7 +22,9 @@ import ( "k8s.io/kubernetes/pkg/kubelet/lifecycle" ) -type fakeManager struct{} +type fakeManager struct { + hint *TopologyHint +} //NewFakeManager returns an instance of FakeManager func NewFakeManager() Manager { @@ -30,9 +32,21 @@ func NewFakeManager() Manager { 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 { klog.InfoS("GetAffinity", "podUID", podUID, "containerName", containerName) - return TopologyHint{} + if m.hint == nil { + return TopologyHint{} + } + + return *m.hint } func (m *fakeManager) AddHintProvider(h HintProvider) {