k8s.io/kubernetes@v1.29.3/pkg/kubelet/status/state/state.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 state 18 19 import ( 20 "k8s.io/api/core/v1" 21 ) 22 23 // PodResourceAllocation type is used in tracking resources allocated to pod's containers 24 type PodResourceAllocation map[string]map[string]v1.ResourceList 25 26 // PodResizeStatus type is used in tracking the last resize decision for pod 27 type PodResizeStatus map[string]v1.PodResizeStatus 28 29 // Clone returns a copy of PodResourceAllocation 30 func (pr PodResourceAllocation) Clone() PodResourceAllocation { 31 prCopy := make(PodResourceAllocation) 32 for pod := range pr { 33 prCopy[pod] = make(map[string]v1.ResourceList) 34 for container, alloc := range pr[pod] { 35 prCopy[pod][container] = alloc.DeepCopy() 36 } 37 } 38 return prCopy 39 } 40 41 // Reader interface used to read current pod resource allocation state 42 type Reader interface { 43 GetContainerResourceAllocation(podUID string, containerName string) (v1.ResourceList, bool) 44 GetPodResourceAllocation() PodResourceAllocation 45 GetPodResizeStatus(podUID string) (v1.PodResizeStatus, bool) 46 GetResizeStatus() PodResizeStatus 47 } 48 49 type writer interface { 50 SetContainerResourceAllocation(podUID string, containerName string, alloc v1.ResourceList) error 51 SetPodResourceAllocation(PodResourceAllocation) error 52 SetPodResizeStatus(podUID string, resizeStatus v1.PodResizeStatus) error 53 SetResizeStatus(PodResizeStatus) error 54 Delete(podUID string, containerName string) error 55 ClearState() error 56 } 57 58 // State interface provides methods for tracking and setting pod resource allocation 59 type State interface { 60 Reader 61 writer 62 }