k8s.io/kubernetes@v1.31.0-alpha.0.0.20240520171757-56147500dadc/pkg/kubelet/cm/container_manager_windows.go (about) 1 //go:build windows 2 // +build windows 3 4 /* 5 Copyright 2015 The Kubernetes Authors. 6 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18 */ 19 20 // containerManagerImpl implements container manager on Windows. 21 // Only GetNodeAllocatableReservation() and GetCapacity() are implemented now. 22 23 package cm 24 25 import ( 26 "context" 27 "fmt" 28 29 "k8s.io/klog/v2" 30 "k8s.io/mount-utils" 31 32 v1 "k8s.io/api/core/v1" 33 "k8s.io/apimachinery/pkg/api/resource" 34 "k8s.io/apimachinery/pkg/types" 35 clientset "k8s.io/client-go/kubernetes" 36 "k8s.io/client-go/tools/record" 37 internalapi "k8s.io/cri-api/pkg/apis" 38 podresourcesapi "k8s.io/kubelet/pkg/apis/podresources/v1" 39 "k8s.io/kubernetes/pkg/kubelet/cadvisor" 40 "k8s.io/kubernetes/pkg/kubelet/cm/admission" 41 "k8s.io/kubernetes/pkg/kubelet/cm/cpumanager" 42 "k8s.io/kubernetes/pkg/kubelet/cm/devicemanager" 43 "k8s.io/kubernetes/pkg/kubelet/cm/memorymanager" 44 "k8s.io/kubernetes/pkg/kubelet/cm/topologymanager" 45 "k8s.io/kubernetes/pkg/kubelet/config" 46 kubecontainer "k8s.io/kubernetes/pkg/kubelet/container" 47 "k8s.io/kubernetes/pkg/kubelet/lifecycle" 48 "k8s.io/kubernetes/pkg/kubelet/pluginmanager/cache" 49 "k8s.io/kubernetes/pkg/kubelet/status" 50 schedulerframework "k8s.io/kubernetes/pkg/scheduler/framework" 51 ) 52 53 type containerManagerImpl struct { 54 // Capacity of this node. 55 capacity v1.ResourceList 56 // Interface for cadvisor. 57 cadvisorInterface cadvisor.Interface 58 // Config of this node. 59 nodeConfig NodeConfig 60 // Interface for exporting and allocating devices reported by device plugins. 61 deviceManager devicemanager.Manager 62 // Interface for Topology resource co-ordination 63 topologyManager topologymanager.Manager 64 } 65 66 type noopWindowsResourceAllocator struct{} 67 68 func (ra *noopWindowsResourceAllocator) Admit(attrs *lifecycle.PodAdmitAttributes) lifecycle.PodAdmitResult { 69 return admission.GetPodAdmitResult(nil) 70 } 71 72 func (cm *containerManagerImpl) Start(node *v1.Node, 73 activePods ActivePodsFunc, 74 sourcesReady config.SourcesReady, 75 podStatusProvider status.PodStatusProvider, 76 runtimeService internalapi.RuntimeService, 77 localStorageCapacityIsolation bool) error { 78 klog.V(2).InfoS("Starting Windows container manager") 79 80 if localStorageCapacityIsolation { 81 rootfs, err := cm.cadvisorInterface.RootFsInfo() 82 if err != nil { 83 return fmt.Errorf("failed to get rootfs info: %v", err) 84 } 85 for rName, rCap := range cadvisor.EphemeralStorageCapacityFromFsInfo(rootfs) { 86 cm.capacity[rName] = rCap 87 } 88 } 89 90 ctx := context.Background() 91 containerMap, containerRunningSet := buildContainerMapAndRunningSetFromRuntime(ctx, runtimeService) 92 93 // Starts device manager. 94 if err := cm.deviceManager.Start(devicemanager.ActivePodsFunc(activePods), sourcesReady, containerMap, containerRunningSet); err != nil { 95 return err 96 } 97 98 return nil 99 } 100 101 // NewContainerManager creates windows container manager. 102 func NewContainerManager(mountUtil mount.Interface, cadvisorInterface cadvisor.Interface, nodeConfig NodeConfig, failSwapOn bool, recorder record.EventRecorder, kubeClient clientset.Interface) (ContainerManager, error) { 103 // It is safe to invoke `MachineInfo` on cAdvisor before logically initializing cAdvisor here because 104 // machine info is computed and cached once as part of cAdvisor object creation. 105 // But `RootFsInfo` and `ImagesFsInfo` are not available at this moment so they will be called later during manager starts 106 machineInfo, err := cadvisorInterface.MachineInfo() 107 if err != nil { 108 return nil, err 109 } 110 capacity := cadvisor.CapacityFromMachineInfo(machineInfo) 111 112 cm := &containerManagerImpl{ 113 capacity: capacity, 114 nodeConfig: nodeConfig, 115 cadvisorInterface: cadvisorInterface, 116 } 117 118 cm.topologyManager = topologymanager.NewFakeManager() 119 120 klog.InfoS("Creating device plugin manager") 121 cm.deviceManager, err = devicemanager.NewManagerImpl(nil, cm.topologyManager) 122 if err != nil { 123 return nil, err 124 } 125 cm.topologyManager.AddHintProvider(cm.deviceManager) 126 127 return cm, nil 128 } 129 130 func (cm *containerManagerImpl) SystemCgroupsLimit() v1.ResourceList { 131 return v1.ResourceList{} 132 } 133 134 func (cm *containerManagerImpl) GetNodeConfig() NodeConfig { 135 return NodeConfig{} 136 } 137 138 func (cm *containerManagerImpl) GetMountedSubsystems() *CgroupSubsystems { 139 return &CgroupSubsystems{} 140 } 141 142 func (cm *containerManagerImpl) GetQOSContainersInfo() QOSContainersInfo { 143 return QOSContainersInfo{} 144 } 145 146 func (cm *containerManagerImpl) UpdateQOSCgroups() error { 147 return nil 148 } 149 150 func (cm *containerManagerImpl) Status() Status { 151 return Status{} 152 } 153 154 func (cm *containerManagerImpl) GetNodeAllocatableReservation() v1.ResourceList { 155 evictionReservation := hardEvictionReservation(cm.nodeConfig.HardEvictionThresholds, cm.capacity) 156 result := make(v1.ResourceList) 157 for k := range cm.capacity { 158 value := resource.NewQuantity(0, resource.DecimalSI) 159 if cm.nodeConfig.SystemReserved != nil { 160 value.Add(cm.nodeConfig.SystemReserved[k]) 161 } 162 if cm.nodeConfig.KubeReserved != nil { 163 value.Add(cm.nodeConfig.KubeReserved[k]) 164 } 165 if evictionReservation != nil { 166 value.Add(evictionReservation[k]) 167 } 168 if !value.IsZero() { 169 result[k] = *value 170 } 171 } 172 return result 173 } 174 175 func (cm *containerManagerImpl) GetCapacity(localStorageCapacityIsolation bool) v1.ResourceList { 176 return cm.capacity 177 } 178 179 func (cm *containerManagerImpl) GetPluginRegistrationHandler() cache.PluginHandler { 180 return cm.deviceManager.GetWatcherHandler() 181 } 182 183 func (cm *containerManagerImpl) GetDevicePluginResourceCapacity() (v1.ResourceList, v1.ResourceList, []string) { 184 return cm.deviceManager.GetCapacity() 185 } 186 187 func (cm *containerManagerImpl) NewPodContainerManager() PodContainerManager { 188 return &podContainerManagerStub{} 189 } 190 191 func (cm *containerManagerImpl) GetResources(pod *v1.Pod, container *v1.Container) (*kubecontainer.RunContainerOptions, error) { 192 opts := &kubecontainer.RunContainerOptions{} 193 // Allocate should already be called during predicateAdmitHandler.Admit(), 194 // just try to fetch device runtime information from cached state here 195 devOpts, err := cm.deviceManager.GetDeviceRunContainerOptions(pod, container) 196 if err != nil { 197 return nil, err 198 } else if devOpts == nil { 199 return opts, nil 200 } 201 opts.Devices = append(opts.Devices, devOpts.Devices...) 202 opts.Mounts = append(opts.Mounts, devOpts.Mounts...) 203 opts.Envs = append(opts.Envs, devOpts.Envs...) 204 opts.Annotations = append(opts.Annotations, devOpts.Annotations...) 205 return opts, nil 206 } 207 208 func (cm *containerManagerImpl) UpdatePluginResources(node *schedulerframework.NodeInfo, attrs *lifecycle.PodAdmitAttributes) error { 209 return cm.deviceManager.UpdatePluginResources(node, attrs) 210 } 211 212 func (cm *containerManagerImpl) InternalContainerLifecycle() InternalContainerLifecycle { 213 return &internalContainerLifecycleImpl{cpumanager.NewFakeManager(), memorymanager.NewFakeManager(), topologymanager.NewFakeManager()} 214 } 215 216 func (cm *containerManagerImpl) GetPodCgroupRoot() string { 217 return "" 218 } 219 220 func (cm *containerManagerImpl) GetDevices(podUID, containerName string) []*podresourcesapi.ContainerDevices { 221 return containerDevicesFromResourceDeviceInstances(cm.deviceManager.GetDevices(podUID, containerName)) 222 } 223 224 func (cm *containerManagerImpl) GetAllocatableDevices() []*podresourcesapi.ContainerDevices { 225 return nil 226 } 227 228 func (cm *containerManagerImpl) ShouldResetExtendedResourceCapacity() bool { 229 return cm.deviceManager.ShouldResetExtendedResourceCapacity() 230 } 231 232 func (cm *containerManagerImpl) GetAllocateResourcesPodAdmitHandler() lifecycle.PodAdmitHandler { 233 return &noopWindowsResourceAllocator{} 234 } 235 236 func (cm *containerManagerImpl) UpdateAllocatedDevices() { 237 return 238 } 239 240 func (cm *containerManagerImpl) GetCPUs(_, _ string) []int64 { 241 return nil 242 } 243 244 func (cm *containerManagerImpl) GetAllocatableCPUs() []int64 { 245 return nil 246 } 247 248 func (cm *containerManagerImpl) GetMemory(_, _ string) []*podresourcesapi.ContainerMemory { 249 return nil 250 } 251 252 func (cm *containerManagerImpl) GetAllocatableMemory() []*podresourcesapi.ContainerMemory { 253 return nil 254 } 255 256 func (cm *containerManagerImpl) GetNodeAllocatableAbsolute() v1.ResourceList { 257 return nil 258 } 259 260 func (cm *containerManagerImpl) GetDynamicResources(pod *v1.Pod, container *v1.Container) []*podresourcesapi.DynamicResource { 261 return nil 262 } 263 264 func (cm *containerManagerImpl) PrepareDynamicResources(pod *v1.Pod) error { 265 return nil 266 } 267 268 func (cm *containerManagerImpl) UnprepareDynamicResources(*v1.Pod) error { 269 return nil 270 } 271 272 func (cm *containerManagerImpl) PodMightNeedToUnprepareResources(UID types.UID) bool { 273 return false 274 }