k8s.io/kubernetes@v1.29.3/pkg/kubelet/cm/memorymanager/fake_memory_manager.go (about) 1 /* 2 Copyright 2020 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package memorymanager 18 19 import ( 20 v1 "k8s.io/api/core/v1" 21 "k8s.io/apimachinery/pkg/util/sets" 22 "k8s.io/klog/v2" 23 "k8s.io/kubernetes/pkg/kubelet/cm/containermap" 24 "k8s.io/kubernetes/pkg/kubelet/cm/memorymanager/state" 25 "k8s.io/kubernetes/pkg/kubelet/cm/topologymanager" 26 "k8s.io/kubernetes/pkg/kubelet/config" 27 "k8s.io/kubernetes/pkg/kubelet/status" 28 ) 29 30 type fakeManager struct { 31 state state.State 32 } 33 34 func (m *fakeManager) Start(activePods ActivePodsFunc, sourcesReady config.SourcesReady, podStatusProvider status.PodStatusProvider, containerRuntime runtimeService, initialContainers containermap.ContainerMap) error { 35 klog.InfoS("Start()") 36 return nil 37 } 38 39 func (m *fakeManager) Policy() Policy { 40 klog.InfoS("Policy()") 41 return NewPolicyNone() 42 } 43 44 func (m *fakeManager) Allocate(pod *v1.Pod, container *v1.Container) error { 45 klog.InfoS("Allocate", "pod", klog.KObj(pod), "containerName", container.Name) 46 return nil 47 } 48 49 func (m *fakeManager) AddContainer(pod *v1.Pod, container *v1.Container, containerID string) { 50 klog.InfoS("Add container", "pod", klog.KObj(pod), "containerName", container.Name, "containerID", containerID) 51 } 52 53 func (m *fakeManager) GetMemoryNUMANodes(pod *v1.Pod, container *v1.Container) sets.Set[int] { 54 klog.InfoS("Get MemoryNUMANodes", "pod", klog.KObj(pod), "containerName", container.Name) 55 return nil 56 } 57 58 func (m *fakeManager) RemoveContainer(containerID string) error { 59 klog.InfoS("RemoveContainer", "containerID", containerID) 60 return nil 61 } 62 63 func (m *fakeManager) GetTopologyHints(pod *v1.Pod, container *v1.Container) map[string][]topologymanager.TopologyHint { 64 klog.InfoS("Get Topology Hints", "pod", klog.KObj(pod), "containerName", container.Name) 65 return map[string][]topologymanager.TopologyHint{} 66 } 67 68 func (m *fakeManager) GetPodTopologyHints(pod *v1.Pod) map[string][]topologymanager.TopologyHint { 69 klog.InfoS("Get Pod Topology Hints", "pod", klog.KObj(pod)) 70 return map[string][]topologymanager.TopologyHint{} 71 } 72 73 func (m *fakeManager) State() state.Reader { 74 return m.state 75 } 76 77 // GetAllocatableMemory returns the amount of allocatable memory for each NUMA node 78 func (m *fakeManager) GetAllocatableMemory() []state.Block { 79 klog.InfoS("Get Allocatable Memory") 80 return []state.Block{} 81 } 82 83 // GetMemory returns the memory allocated by a container from NUMA nodes 84 func (m *fakeManager) GetMemory(podUID, containerName string) []state.Block { 85 klog.InfoS("Get Memory", "podUID", podUID, "containerName", containerName) 86 return []state.Block{} 87 } 88 89 // NewFakeManager creates empty/fake memory manager 90 func NewFakeManager() Manager { 91 return &fakeManager{ 92 state: state.NewMemoryState(), 93 } 94 }