mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
memory manager: move the fakeTopologyManagerWithHint
Move the fakeTopologyManagerWithHint and all related methods from the topology manager package to the memory manager static policy unittests. Signed-off-by: Artyom Lukianov <alukiano@redhat.com>
This commit is contained in:
parent
d0089db2ec
commit
0fa5dd5532
@ -41,7 +41,9 @@ go_test(
|
|||||||
"//pkg/kubelet/cm/memorymanager/state:go_default_library",
|
"//pkg/kubelet/cm/memorymanager/state:go_default_library",
|
||||||
"//pkg/kubelet/cm/topologymanager:go_default_library",
|
"//pkg/kubelet/cm/topologymanager:go_default_library",
|
||||||
"//pkg/kubelet/cm/topologymanager/bitmask:go_default_library",
|
"//pkg/kubelet/cm/topologymanager/bitmask:go_default_library",
|
||||||
|
"//pkg/kubelet/lifecycle:go_default_library",
|
||||||
"//pkg/kubelet/types:go_default_library",
|
"//pkg/kubelet/types:go_default_library",
|
||||||
|
"//pkg/kubelet/util/format:go_default_library",
|
||||||
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/api/resource:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/api/resource:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||||
|
@ -29,6 +29,8 @@ 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 (
|
||||||
@ -65,6 +67,43 @@ var (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type fakeTopologyManagerWithHint struct {
|
||||||
|
hint *topologymanager.TopologyHint
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewFakeTopologyManagerWithHint returns an instance of fake topology manager with specified topology hints
|
||||||
|
func NewFakeTopologyManagerWithHint(hint *topologymanager.TopologyHint) topologymanager.Manager {
|
||||||
|
return &fakeTopologyManagerWithHint{
|
||||||
|
hint: hint,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *fakeTopologyManagerWithHint) AddHintProvider(h topologymanager.HintProvider) {
|
||||||
|
klog.Infof("[fake topologymanager] AddHintProvider HintProvider: %v", h)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *fakeTopologyManagerWithHint) AddContainer(pod *v1.Pod, containerID string) error {
|
||||||
|
klog.Infof("[fake topologymanager] AddContainer pod: %v container id: %v", format.Pod(pod), containerID)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *fakeTopologyManagerWithHint) RemoveContainer(containerID string) error {
|
||||||
|
klog.Infof("[fake topologymanager] RemoveContainer container id: %v", containerID)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *fakeTopologyManagerWithHint) Admit(attrs *lifecycle.PodAdmitAttributes) lifecycle.PodAdmitResult {
|
||||||
|
klog.Infof("[fake topologymanager] Topology Admit Handler")
|
||||||
|
return lifecycle.PodAdmitResult{
|
||||||
|
Admit: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *fakeTopologyManagerWithHint) GetAffinity(podUID string, containerName string) topologymanager.TopologyHint {
|
||||||
|
klog.Infof("[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
|
||||||
@ -132,7 +171,7 @@ type testStaticPolicy struct {
|
|||||||
func initTests(testCase *testStaticPolicy, hint *topologymanager.TopologyHint) (Policy, state.State, error) {
|
func initTests(testCase *testStaticPolicy, hint *topologymanager.TopologyHint) (Policy, state.State, error) {
|
||||||
manager := topologymanager.NewFakeManager()
|
manager := topologymanager.NewFakeManager()
|
||||||
if hint != nil {
|
if hint != nil {
|
||||||
manager = topologymanager.NewFakeManagerWithHint(hint)
|
manager = NewFakeTopologyManagerWithHint(hint)
|
||||||
}
|
}
|
||||||
|
|
||||||
p, err := NewPolicyStatic(testCase.machineInfo, testCase.systemReserved, manager)
|
p, err := NewPolicyStatic(testCase.machineInfo, testCase.systemReserved, manager)
|
||||||
|
@ -17,7 +17,7 @@ limitations under the License.
|
|||||||
package topologymanager
|
package topologymanager
|
||||||
|
|
||||||
import (
|
import (
|
||||||
v1 "k8s.io/api/core/v1"
|
"k8s.io/api/core/v1"
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
"k8s.io/kubernetes/pkg/kubelet/lifecycle"
|
"k8s.io/kubernetes/pkg/kubelet/lifecycle"
|
||||||
"k8s.io/kubernetes/pkg/kubelet/util/format"
|
"k8s.io/kubernetes/pkg/kubelet/util/format"
|
||||||
@ -56,21 +56,3 @@ func (m *fakeManager) Admit(attrs *lifecycle.PodAdmitAttributes) lifecycle.PodAd
|
|||||||
Admit: true,
|
Admit: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type fakeManagerWithHint struct {
|
|
||||||
fakeManager
|
|
||||||
hint *TopologyHint
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewFakeManagerWithHint returns an instance of FakeManager with specified topology hints
|
|
||||||
func NewFakeManagerWithHint(hint *TopologyHint) Manager {
|
|
||||||
return &fakeManagerWithHint{
|
|
||||||
fakeManager: fakeManager{},
|
|
||||||
hint: hint,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *fakeManagerWithHint) GetAffinity(podUID string, containerName string) TopologyHint {
|
|
||||||
klog.Infof("[fake topologymanager] GetAffinity podUID: %v container name: %v", podUID, containerName)
|
|
||||||
return *m.hint
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user