mirror of
https://github.com/optim-enterprises-bv/kubernetes.git
synced 2025-11-03 11:48:15 +00:00
Merge pull request #46926 from k82cn/k8s_46924
Automatic merge from submit-queue (batch tested with PRs 46926, 48468) Added helper funcs to schedulercache.Resource. **What this PR does / why we need it**: Avoid duplicated code slice by helper funcs. **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #46924 **Release note**: ```release-note-none ```
This commit is contained in:
@@ -499,30 +499,15 @@ func (c *VolumeZoneChecker) predicate(pod *v1.Pod, meta interface{}, nodeInfo *s
|
||||
//
|
||||
// Result: CPU: 3, Memory: 3G
|
||||
func GetResourceRequest(pod *v1.Pod) *schedulercache.Resource {
|
||||
result := schedulercache.Resource{}
|
||||
result := &schedulercache.Resource{}
|
||||
for _, container := range pod.Spec.Containers {
|
||||
for rName, rQuantity := range container.Resources.Requests {
|
||||
switch rName {
|
||||
case v1.ResourceMemory:
|
||||
result.Memory += rQuantity.Value()
|
||||
case v1.ResourceCPU:
|
||||
result.MilliCPU += rQuantity.MilliValue()
|
||||
case v1.ResourceNvidiaGPU:
|
||||
result.NvidiaGPU += rQuantity.Value()
|
||||
case v1.ResourceStorageOverlay:
|
||||
result.StorageOverlay += rQuantity.Value()
|
||||
default:
|
||||
if v1helper.IsOpaqueIntResourceName(rName) {
|
||||
result.AddOpaque(rName, rQuantity.Value())
|
||||
}
|
||||
}
|
||||
}
|
||||
result.Add(container.Resources.Requests)
|
||||
}
|
||||
|
||||
// Account for storage requested by emptydir volumes
|
||||
// If the storage medium is memory, should exclude the size
|
||||
for _, vol := range pod.Spec.Volumes {
|
||||
if vol.EmptyDir != nil && vol.EmptyDir.Medium != v1.StorageMediumMemory {
|
||||
|
||||
result.StorageScratch += vol.EmptyDir.SizeLimit.Value()
|
||||
}
|
||||
}
|
||||
@@ -557,7 +542,8 @@ func GetResourceRequest(pod *v1.Pod) *schedulercache.Resource {
|
||||
}
|
||||
}
|
||||
}
|
||||
return &result
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func podName(pod *v1.Pod) string {
|
||||
|
||||
Reference in New Issue
Block a user