k8s.io/kubernetes@v1.29.3/pkg/kubelet/status/fake_status_manager.go (about)

     1  /*
     2  Copyright 2021 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 status
    18  
    19  import (
    20  	v1 "k8s.io/api/core/v1"
    21  	"k8s.io/apimachinery/pkg/types"
    22  	"k8s.io/klog/v2"
    23  	kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
    24  	"k8s.io/kubernetes/pkg/kubelet/status/state"
    25  )
    26  
    27  type fakeManager struct {
    28  	state state.State
    29  }
    30  
    31  func (m *fakeManager) Start() {
    32  	klog.InfoS("Start()")
    33  	return
    34  }
    35  
    36  func (m *fakeManager) GetPodStatus(uid types.UID) (v1.PodStatus, bool) {
    37  	klog.InfoS("GetPodStatus()")
    38  	return v1.PodStatus{}, false
    39  }
    40  
    41  func (m *fakeManager) SetPodStatus(pod *v1.Pod, status v1.PodStatus) {
    42  	klog.InfoS("SetPodStatus()")
    43  	return
    44  }
    45  
    46  func (m *fakeManager) SetContainerReadiness(podUID types.UID, containerID kubecontainer.ContainerID, ready bool) {
    47  	klog.InfoS("SetContainerReadiness()")
    48  	return
    49  }
    50  
    51  func (m *fakeManager) SetContainerStartup(podUID types.UID, containerID kubecontainer.ContainerID, started bool) {
    52  	klog.InfoS("SetContainerStartup()")
    53  	return
    54  }
    55  
    56  func (m *fakeManager) TerminatePod(pod *v1.Pod) {
    57  	klog.InfoS("TerminatePod()")
    58  	return
    59  }
    60  
    61  func (m *fakeManager) RemoveOrphanedStatuses(podUIDs map[types.UID]bool) {
    62  	klog.InfoS("RemoveOrphanedStatuses()")
    63  	return
    64  }
    65  
    66  func (m *fakeManager) GetContainerResourceAllocation(podUID string, containerName string) (v1.ResourceList, bool) {
    67  	klog.InfoS("GetContainerResourceAllocation()")
    68  	return m.state.GetContainerResourceAllocation(podUID, containerName)
    69  }
    70  
    71  func (m *fakeManager) GetPodResizeStatus(podUID string) (v1.PodResizeStatus, bool) {
    72  	klog.InfoS("GetPodResizeStatus()")
    73  	return "", false
    74  }
    75  
    76  func (m *fakeManager) SetPodAllocation(pod *v1.Pod) error {
    77  	klog.InfoS("SetPodAllocation()")
    78  	for _, container := range pod.Spec.Containers {
    79  		var alloc v1.ResourceList
    80  		if container.Resources.Requests != nil {
    81  			alloc = container.Resources.Requests.DeepCopy()
    82  		}
    83  		m.state.SetContainerResourceAllocation(string(pod.UID), container.Name, alloc)
    84  	}
    85  	return nil
    86  }
    87  
    88  func (m *fakeManager) SetPodResizeStatus(podUID types.UID, resizeStatus v1.PodResizeStatus) error {
    89  	klog.InfoS("SetPodResizeStatus()")
    90  	return nil
    91  }
    92  
    93  // NewFakeManager creates empty/fake memory manager
    94  func NewFakeManager() Manager {
    95  	return &fakeManager{
    96  		state: state.NewStateMemory(),
    97  	}
    98  }