...

Source file src/k8s.io/kubernetes/pkg/kubelet/cm/cpumanager/fake_cpu_manager.go

Documentation: k8s.io/kubernetes/pkg/kubelet/cm/cpumanager

     1  /*
     2  Copyright 2017 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 cpumanager
    18  
    19  import (
    20  	"k8s.io/api/core/v1"
    21  	"k8s.io/klog/v2"
    22  	"k8s.io/kubernetes/pkg/kubelet/cm/containermap"
    23  	"k8s.io/kubernetes/pkg/kubelet/cm/cpumanager/state"
    24  	"k8s.io/kubernetes/pkg/kubelet/cm/topologymanager"
    25  	"k8s.io/kubernetes/pkg/kubelet/config"
    26  	"k8s.io/kubernetes/pkg/kubelet/status"
    27  	"k8s.io/utils/cpuset"
    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  	pol, _ := NewNonePolicy(nil)
    42  	return pol
    43  }
    44  
    45  func (m *fakeManager) Allocate(pod *v1.Pod, container *v1.Container) error {
    46  	klog.InfoS("Allocate", "pod", klog.KObj(pod), "containerName", container.Name)
    47  	return nil
    48  }
    49  
    50  func (m *fakeManager) AddContainer(pod *v1.Pod, container *v1.Container, containerID string) {
    51  	klog.InfoS("AddContainer", "pod", klog.KObj(pod), "containerName", container.Name, "containerID", containerID)
    52  }
    53  
    54  func (m *fakeManager) RemoveContainer(containerID string) error {
    55  	klog.InfoS("RemoveContainer", "containerID", containerID)
    56  	return nil
    57  }
    58  
    59  func (m *fakeManager) GetTopologyHints(pod *v1.Pod, container *v1.Container) map[string][]topologymanager.TopologyHint {
    60  	klog.InfoS("Get container topology hints")
    61  	return map[string][]topologymanager.TopologyHint{}
    62  }
    63  
    64  func (m *fakeManager) GetPodTopologyHints(pod *v1.Pod) map[string][]topologymanager.TopologyHint {
    65  	klog.InfoS("Get pod topology hints")
    66  	return map[string][]topologymanager.TopologyHint{}
    67  }
    68  
    69  func (m *fakeManager) State() state.Reader {
    70  	return m.state
    71  }
    72  
    73  func (m *fakeManager) GetExclusiveCPUs(podUID, containerName string) cpuset.CPUSet {
    74  	klog.InfoS("GetExclusiveCPUs", "podUID", podUID, "containerName", containerName)
    75  	return cpuset.CPUSet{}
    76  }
    77  
    78  func (m *fakeManager) GetAllocatableCPUs() cpuset.CPUSet {
    79  	klog.InfoS("Get Allocatable CPUs")
    80  	return cpuset.CPUSet{}
    81  }
    82  
    83  func (m *fakeManager) GetCPUAffinity(podUID, containerName string) cpuset.CPUSet {
    84  	klog.InfoS("GetCPUAffinity", "podUID", podUID, "containerName", containerName)
    85  	return cpuset.CPUSet{}
    86  }
    87  
    88  // NewFakeManager creates empty/fake cpu manager
    89  func NewFakeManager() Manager {
    90  	return &fakeManager{
    91  		state: state.NewMemoryState(),
    92  	}
    93  }
    94  

View as plain text