mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
Merge pull request #102221 from kikimo/add-hint-to-fake-topology-manager
Add hint to fake topology manager.
This commit is contained in:
commit
1795a98eeb
@ -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",
|
||||
|
@ -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)
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user