github.com/jingruilea/kubeedge@v1.2.0-beta.0.0.20200410162146-4bb8902b3879/edge/pkg/edged/clcm/internal_life_cycle.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 @CHANGELOG 17 KubeEdge Authors: To create mini-kubelet for edge deployment scenario, 18 This file is derived from K8S Kubelet code with reduced set of methods 19 */ 20 21 package clcm 22 23 import ( 24 "k8s.io/api/core/v1" 25 utilfeature "k8s.io/apiserver/pkg/util/feature" 26 kubefeatures "k8s.io/kubernetes/pkg/features" 27 "k8s.io/kubernetes/pkg/kubelet/cm/cpumanager" 28 ) 29 30 // InternalContainerLifecycle interface. 31 type InternalContainerLifecycle interface { 32 PreStartContainer(pod *v1.Pod, container *v1.Container, containerID string) error 33 PreStopContainer(containerID string) error 34 PostStopContainer(containerID string) error 35 } 36 37 // Implements InternalContainerLifecycle interface. 38 type internalContainerLifecycleImpl struct { 39 cpuManager cpumanager.Manager 40 } 41 42 // Implements PreStartContainer 43 func (i *internalContainerLifecycleImpl) PreStartContainer(pod *v1.Pod, container *v1.Container, containerID string) error { 44 if utilfeature.DefaultFeatureGate.Enabled(kubefeatures.CPUManager) { 45 return i.cpuManager.AddContainer(pod, container, containerID) 46 } 47 return nil 48 } 49 50 // Implements PreStopContainer 51 func (i *internalContainerLifecycleImpl) PreStopContainer(containerID string) error { 52 if utilfeature.DefaultFeatureGate.Enabled(kubefeatures.CPUManager) { 53 return i.cpuManager.RemoveContainer(containerID) 54 } 55 return nil 56 } 57 58 // Implements PostStopContainer 59 func (i *internalContainerLifecycleImpl) PostStopContainer(containerID string) error { 60 if utilfeature.DefaultFeatureGate.Enabled(kubefeatures.CPUManager) { 61 return i.cpuManager.RemoveContainer(containerID) 62 } 63 return nil 64 }