...

Source file src/k8s.io/kubernetes/pkg/kubelet/cm/topologymanager/fake_topology_manager.go

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

     1  /*
     2  Copyright 2019 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 topologymanager
    18  
    19  import (
    20  	"k8s.io/api/core/v1"
    21  	"k8s.io/klog/v2"
    22  	"k8s.io/kubernetes/pkg/kubelet/cm/admission"
    23  	"k8s.io/kubernetes/pkg/kubelet/lifecycle"
    24  )
    25  
    26  type fakeManager struct {
    27  	hint   *TopologyHint
    28  	policy Policy
    29  }
    30  
    31  // NewFakeManager returns an instance of FakeManager
    32  func NewFakeManager() Manager {
    33  	klog.InfoS("NewFakeManager")
    34  	return &fakeManager{}
    35  }
    36  
    37  // NewFakeManagerWithHint returns an instance of fake topology manager with specified topology hints
    38  func NewFakeManagerWithHint(hint *TopologyHint) Manager {
    39  	klog.InfoS("NewFakeManagerWithHint")
    40  	return &fakeManager{
    41  		hint:   hint,
    42  		policy: NewNonePolicy(),
    43  	}
    44  }
    45  
    46  // NewFakeManagerWithPolicy returns an instance of fake topology manager with specified policy
    47  func NewFakeManagerWithPolicy(policy Policy) Manager {
    48  	klog.InfoS("NewFakeManagerWithPolicy")
    49  	return &fakeManager{
    50  		policy: policy,
    51  	}
    52  }
    53  
    54  func (m *fakeManager) GetAffinity(podUID string, containerName string) TopologyHint {
    55  	klog.InfoS("GetAffinity", "podUID", podUID, "containerName", containerName)
    56  	if m.hint == nil {
    57  		return TopologyHint{}
    58  	}
    59  
    60  	return *m.hint
    61  }
    62  
    63  func (m *fakeManager) GetPolicy() Policy {
    64  	return m.policy
    65  }
    66  
    67  func (m *fakeManager) AddHintProvider(h HintProvider) {
    68  	klog.InfoS("AddHintProvider", "hintProvider", h)
    69  }
    70  
    71  func (m *fakeManager) AddContainer(pod *v1.Pod, container *v1.Container, containerID string) {
    72  	klog.InfoS("AddContainer", "pod", klog.KObj(pod), "containerName", container.Name, "containerID", containerID)
    73  }
    74  
    75  func (m *fakeManager) RemoveContainer(containerID string) error {
    76  	klog.InfoS("RemoveContainer", "containerID", containerID)
    77  	return nil
    78  }
    79  
    80  func (m *fakeManager) Admit(attrs *lifecycle.PodAdmitAttributes) lifecycle.PodAdmitResult {
    81  	klog.InfoS("Topology Admit Handler")
    82  	return admission.GetPodAdmitResult(nil)
    83  }
    84  

View as plain text