k8s.io/kubernetes@v1.29.3/pkg/kubelet/cm/internal_container_lifecycle.go (about) 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 cm 18 19 import ( 20 "k8s.io/api/core/v1" 21 runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1" 22 "k8s.io/kubernetes/pkg/kubelet/cm/cpumanager" 23 "k8s.io/kubernetes/pkg/kubelet/cm/memorymanager" 24 "k8s.io/kubernetes/pkg/kubelet/cm/topologymanager" 25 ) 26 27 type InternalContainerLifecycle interface { 28 PreCreateContainer(pod *v1.Pod, container *v1.Container, containerConfig *runtimeapi.ContainerConfig) error 29 PreStartContainer(pod *v1.Pod, container *v1.Container, containerID string) error 30 PostStopContainer(containerID string) error 31 } 32 33 // Implements InternalContainerLifecycle interface. 34 type internalContainerLifecycleImpl struct { 35 cpuManager cpumanager.Manager 36 memoryManager memorymanager.Manager 37 topologyManager topologymanager.Manager 38 } 39 40 func (i *internalContainerLifecycleImpl) PreStartContainer(pod *v1.Pod, container *v1.Container, containerID string) error { 41 if i.cpuManager != nil { 42 i.cpuManager.AddContainer(pod, container, containerID) 43 } 44 45 if i.memoryManager != nil { 46 i.memoryManager.AddContainer(pod, container, containerID) 47 } 48 49 i.topologyManager.AddContainer(pod, container, containerID) 50 51 return nil 52 } 53 54 func (i *internalContainerLifecycleImpl) PostStopContainer(containerID string) error { 55 return i.topologyManager.RemoveContainer(containerID) 56 }