mirror of
				https://github.com/k3s-io/kubernetes.git
				synced 2025-10-31 13:50:01 +00:00 
			
		
		
		
	This patch makes the CRI `v1` API the new project-wide default version. To allow backwards compatibility, a fallback to `v1alpha2` has been added as well. This fallback can either used by automatically determined by the kubelet. Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
		
			
				
	
	
		
			59 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			59 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| //go:build linux
 | |
| // +build linux
 | |
| 
 | |
| /*
 | |
| Copyright 2021 The Kubernetes Authors.
 | |
| 
 | |
| Licensed under the Apache License, Version 2.0 (the "License");
 | |
| you may not use this file except in compliance with the License.
 | |
| You may obtain a copy of the License at
 | |
| 
 | |
|     http://www.apache.org/licenses/LICENSE-2.0
 | |
| 
 | |
| Unless required by applicable law or agreed to in writing, software
 | |
| distributed under the License is distributed on an "AS IS" BASIS,
 | |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | |
| See the License for the specific language governing permissions and
 | |
| limitations under the License.
 | |
| */
 | |
| 
 | |
| package kuberuntime
 | |
| 
 | |
| import (
 | |
| 	v1 "k8s.io/api/core/v1"
 | |
| 	utilfeature "k8s.io/apiserver/pkg/util/feature"
 | |
| 	runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
 | |
| 	resourcehelper "k8s.io/kubernetes/pkg/api/v1/resource"
 | |
| 	"k8s.io/kubernetes/pkg/features"
 | |
| )
 | |
| 
 | |
| func (m *kubeGenericRuntimeManager) convertOverheadToLinuxResources(pod *v1.Pod) *runtimeapi.LinuxContainerResources {
 | |
| 	resources := &runtimeapi.LinuxContainerResources{}
 | |
| 	if pod.Spec.Overhead != nil && utilfeature.DefaultFeatureGate.Enabled(features.PodOverhead) {
 | |
| 		cpu := pod.Spec.Overhead.Cpu()
 | |
| 		memory := pod.Spec.Overhead.Memory()
 | |
| 
 | |
| 		// For overhead, we do not differentiate between requests and limits. Treat this overhead
 | |
| 		// as "guaranteed", with requests == limits
 | |
| 		resources = m.calculateLinuxResources(cpu, cpu, memory)
 | |
| 	}
 | |
| 
 | |
| 	return resources
 | |
| }
 | |
| 
 | |
| func (m *kubeGenericRuntimeManager) calculateSandboxResources(pod *v1.Pod) *runtimeapi.LinuxContainerResources {
 | |
| 	req, lim := resourcehelper.PodRequestsAndLimitsWithoutOverhead(pod)
 | |
| 	return m.calculateLinuxResources(req.Cpu(), lim.Cpu(), lim.Memory())
 | |
| }
 | |
| 
 | |
| func (m *kubeGenericRuntimeManager) applySandboxResources(pod *v1.Pod, config *runtimeapi.PodSandboxConfig) error {
 | |
| 
 | |
| 	if config.Linux == nil {
 | |
| 		return nil
 | |
| 	}
 | |
| 	config.Linux.Resources = m.calculateSandboxResources(pod)
 | |
| 	config.Linux.Overhead = m.convertOverheadToLinuxResources(pod)
 | |
| 
 | |
| 	return nil
 | |
| }
 |