Commit b2e134a7 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #36693 from ConnorDoyle/oir-cleanup

Automatic merge from submit-queue (batch tested with PRs 36693, 40154, 40170, 39033) Minor hygiene in scheduler. **What this PR does / why we need it**: Minor cleanups in scheduler, related to PR #31652. - Unified lazy opaque resource caching. - Deleted a commented-out line of code. **Release note**: ```release-note N/A ```
parents 53b43d6f 94b9c0e2
......@@ -463,11 +463,7 @@ func GetResourceRequest(pod *v1.Pod) *schedulercache.Resource {
result.NvidiaGPU += rQuantity.Value()
default:
if v1.IsOpaqueIntResourceName(rName) {
// Lazily allocate this map only if required.
if result.OpaqueIntResources == nil {
result.OpaqueIntResources = map[v1.ResourceName]int64{}
}
result.OpaqueIntResources[rName] += rQuantity.Value()
result.AddOpaque(rName, rQuantity.Value())
}
}
}
......@@ -490,11 +486,9 @@ func GetResourceRequest(pod *v1.Pod) *schedulercache.Resource {
}
default:
if v1.IsOpaqueIntResourceName(rName) {
// Lazily allocate this map only if required.
if result.OpaqueIntResources == nil {
result.OpaqueIntResources = map[v1.ResourceName]int64{}
}
value := rQuantity.Value()
// Ensure the opaque resource map is initialized in the result.
result.AddOpaque(rName, int64(0))
if value > result.OpaqueIntResources[rName] {
result.OpaqueIntResources[rName] = value
}
......
......@@ -82,6 +82,14 @@ func (r *Resource) ResourceList() v1.ResourceList {
return result
}
func (r *Resource) AddOpaque(name v1.ResourceName, quantity int64) {
// Lazily allocate opaque integer resource map.
if r.OpaqueIntResources == nil {
r.OpaqueIntResources = map[v1.ResourceName]int64{}
}
r.OpaqueIntResources[name] += quantity
}
// NewNodeInfo returns a ready to use empty NodeInfo object.
// If any pods are given in arguments, their information will be aggregated in
// the returned object.
......@@ -215,7 +223,6 @@ func hasPodAffinityConstraints(pod *v1.Pod) bool {
// addPod adds pod information to this NodeInfo.
func (n *NodeInfo) addPod(pod *v1.Pod) {
// cpu, mem, nvidia_gpu, non0_cpu, non0_mem := calculateResource(pod)
res, non0_cpu, non0_mem := calculateResource(pod)
n.requestedResource.MilliCPU += res.MilliCPU
n.requestedResource.Memory += res.Memory
......@@ -298,11 +305,7 @@ func calculateResource(pod *v1.Pod) (res Resource, non0_cpu int64, non0_mem int6
res.NvidiaGPU += rQuant.Value()
default:
if v1.IsOpaqueIntResourceName(rName) {
// Lazily allocate opaque resource map.
if res.OpaqueIntResources == nil {
res.OpaqueIntResources = map[v1.ResourceName]int64{}
}
res.OpaqueIntResources[rName] += rQuant.Value()
res.AddOpaque(rName, rQuant.Value())
}
}
}
......@@ -330,11 +333,7 @@ func (n *NodeInfo) SetNode(node *v1.Node) error {
n.allowedPodNumber = int(rQuant.Value())
default:
if v1.IsOpaqueIntResourceName(rName) {
// Lazily allocate opaque resource map.
if n.allocatableResource.OpaqueIntResources == nil {
n.allocatableResource.OpaqueIntResources = map[v1.ResourceName]int64{}
}
n.allocatableResource.OpaqueIntResources[rName] = rQuant.Value()
n.allocatableResource.AddOpaque(rName, rQuant.Value())
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment