k8s.io/kubernetes@v1.29.3/pkg/kubelet/cm/types.go (about) 1 /* 2 Copyright 2016 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 v1 "k8s.io/api/core/v1" 21 "k8s.io/apimachinery/pkg/types" 22 ) 23 24 // ResourceConfig holds information about all the supported cgroup resource parameters. 25 type ResourceConfig struct { 26 // Memory limit (in bytes). 27 Memory *int64 28 // CPU shares (relative weight vs. other containers). 29 CPUShares *uint64 30 // CPU hardcap limit (in usecs). Allowed cpu time in a given period. 31 CPUQuota *int64 32 // CPU quota period. 33 CPUPeriod *uint64 34 // HugePageLimit map from page size (in bytes) to limit (in bytes) 35 HugePageLimit map[int64]int64 36 // Maximum number of pids 37 PidsLimit *int64 38 // Unified for cgroup v2 39 Unified map[string]string 40 } 41 42 // CgroupName is the abstract name of a cgroup prior to any driver specific conversion. 43 // It is specified as a list of strings from its individual components, such as: 44 // {"kubepods", "burstable", "pod1234-abcd-5678-efgh"} 45 type CgroupName []string 46 47 // CgroupConfig holds the cgroup configuration information. 48 // This is common object which is used to specify 49 // cgroup information to both systemd and raw cgroup fs 50 // implementation of the Cgroup Manager interface. 51 type CgroupConfig struct { 52 // Fully qualified name prior to any driver specific conversions. 53 Name CgroupName 54 // ResourceParameters contains various cgroups settings to apply. 55 ResourceParameters *ResourceConfig 56 } 57 58 // CgroupManager allows for cgroup management. 59 // Supports Cgroup Creation ,Deletion and Updates. 60 type CgroupManager interface { 61 // Create creates and applies the cgroup configurations on the cgroup. 62 // It just creates the leaf cgroups. 63 // It expects the parent cgroup to already exist. 64 Create(*CgroupConfig) error 65 // Destroy the cgroup. 66 Destroy(*CgroupConfig) error 67 // Update cgroup configuration. 68 Update(*CgroupConfig) error 69 // Validate checks if the cgroup is valid 70 Validate(name CgroupName) error 71 // Exists checks if the cgroup already exists 72 Exists(name CgroupName) bool 73 // Name returns the literal cgroupfs name on the host after any driver specific conversions. 74 // We would expect systemd implementation to make appropriate name conversion. 75 // For example, if we pass {"foo", "bar"} 76 // then systemd should convert the name to something like 77 // foo.slice/foo-bar.slice 78 Name(name CgroupName) string 79 // CgroupName converts the literal cgroupfs name on the host to an internal identifier. 80 CgroupName(name string) CgroupName 81 // Pids scans through all subsystems to find pids associated with specified cgroup. 82 Pids(name CgroupName) []int 83 // ReduceCPULimits reduces the CPU CFS values to the minimum amount of shares. 84 ReduceCPULimits(cgroupName CgroupName) error 85 // MemoryUsage returns current memory usage of the specified cgroup, as read from the cgroupfs. 86 MemoryUsage(name CgroupName) (int64, error) 87 // Get the resource config values applied to the cgroup for specified resource type 88 GetCgroupConfig(name CgroupName, resource v1.ResourceName) (*ResourceConfig, error) 89 // Set resource config for the specified resource type on the cgroup 90 SetCgroupConfig(name CgroupName, resource v1.ResourceName, resourceConfig *ResourceConfig) error 91 } 92 93 // QOSContainersInfo stores the names of containers per qos 94 type QOSContainersInfo struct { 95 Guaranteed CgroupName 96 BestEffort CgroupName 97 Burstable CgroupName 98 } 99 100 // PodContainerManager stores and manages pod level containers 101 // The Pod workers interact with the PodContainerManager to create and destroy 102 // containers for the pod. 103 type PodContainerManager interface { 104 // GetPodContainerName returns the CgroupName identifier, and its literal cgroupfs form on the host. 105 GetPodContainerName(*v1.Pod) (CgroupName, string) 106 107 // EnsureExists takes a pod as argument and makes sure that 108 // pod cgroup exists if qos cgroup hierarchy flag is enabled. 109 // If the pod cgroup doesn't already exist this method creates it. 110 EnsureExists(*v1.Pod) error 111 112 // Exists returns true if the pod cgroup exists. 113 Exists(*v1.Pod) bool 114 115 // Destroy takes a pod Cgroup name as argument and destroys the pod's container. 116 Destroy(name CgroupName) error 117 118 // ReduceCPULimits reduces the CPU CFS values to the minimum amount of shares. 119 ReduceCPULimits(name CgroupName) error 120 121 // GetAllPodsFromCgroups enumerates the set of pod uids to their associated cgroup based on state of cgroupfs system. 122 GetAllPodsFromCgroups() (map[types.UID]CgroupName, error) 123 124 // IsPodCgroup returns true if the literal cgroupfs name corresponds to a pod 125 IsPodCgroup(cgroupfs string) (bool, types.UID) 126 127 // Get value of memory usage for the pod Cgroup 128 GetPodCgroupMemoryUsage(pod *v1.Pod) (uint64, error) 129 130 // Get the resource config values applied to the pod cgroup for specified resource type 131 GetPodCgroupConfig(pod *v1.Pod, resource v1.ResourceName) (*ResourceConfig, error) 132 133 // Set resource config values for the specified resource type on the pod cgroup 134 SetPodCgroupConfig(pod *v1.Pod, resource v1.ResourceName, resourceConfig *ResourceConfig) error 135 }