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 { ...@@ -463,11 +463,7 @@ func GetResourceRequest(pod *v1.Pod) *schedulercache.Resource {
result.NvidiaGPU += rQuantity.Value() result.NvidiaGPU += rQuantity.Value()
default: default:
if v1.IsOpaqueIntResourceName(rName) { if v1.IsOpaqueIntResourceName(rName) {
// Lazily allocate this map only if required. result.AddOpaque(rName, rQuantity.Value())
if result.OpaqueIntResources == nil {
result.OpaqueIntResources = map[v1.ResourceName]int64{}
}
result.OpaqueIntResources[rName] += rQuantity.Value()
} }
} }
} }
...@@ -490,11 +486,9 @@ func GetResourceRequest(pod *v1.Pod) *schedulercache.Resource { ...@@ -490,11 +486,9 @@ func GetResourceRequest(pod *v1.Pod) *schedulercache.Resource {
} }
default: default:
if v1.IsOpaqueIntResourceName(rName) { if v1.IsOpaqueIntResourceName(rName) {
// Lazily allocate this map only if required.
if result.OpaqueIntResources == nil {
result.OpaqueIntResources = map[v1.ResourceName]int64{}
}
value := rQuantity.Value() value := rQuantity.Value()
// Ensure the opaque resource map is initialized in the result.
result.AddOpaque(rName, int64(0))
if value > result.OpaqueIntResources[rName] { if value > result.OpaqueIntResources[rName] {
result.OpaqueIntResources[rName] = value result.OpaqueIntResources[rName] = value
} }
......
...@@ -82,6 +82,14 @@ func (r *Resource) ResourceList() v1.ResourceList { ...@@ -82,6 +82,14 @@ func (r *Resource) ResourceList() v1.ResourceList {
return result 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. // NewNodeInfo returns a ready to use empty NodeInfo object.
// If any pods are given in arguments, their information will be aggregated in // If any pods are given in arguments, their information will be aggregated in
// the returned object. // the returned object.
...@@ -215,7 +223,6 @@ func hasPodAffinityConstraints(pod *v1.Pod) bool { ...@@ -215,7 +223,6 @@ func hasPodAffinityConstraints(pod *v1.Pod) bool {
// addPod adds pod information to this NodeInfo. // addPod adds pod information to this NodeInfo.
func (n *NodeInfo) addPod(pod *v1.Pod) { func (n *NodeInfo) addPod(pod *v1.Pod) {
// cpu, mem, nvidia_gpu, non0_cpu, non0_mem := calculateResource(pod)
res, non0_cpu, non0_mem := calculateResource(pod) res, non0_cpu, non0_mem := calculateResource(pod)
n.requestedResource.MilliCPU += res.MilliCPU n.requestedResource.MilliCPU += res.MilliCPU
n.requestedResource.Memory += res.Memory n.requestedResource.Memory += res.Memory
...@@ -298,11 +305,7 @@ func calculateResource(pod *v1.Pod) (res Resource, non0_cpu int64, non0_mem int6 ...@@ -298,11 +305,7 @@ func calculateResource(pod *v1.Pod) (res Resource, non0_cpu int64, non0_mem int6
res.NvidiaGPU += rQuant.Value() res.NvidiaGPU += rQuant.Value()
default: default:
if v1.IsOpaqueIntResourceName(rName) { if v1.IsOpaqueIntResourceName(rName) {
// Lazily allocate opaque resource map. res.AddOpaque(rName, rQuant.Value())
if res.OpaqueIntResources == nil {
res.OpaqueIntResources = map[v1.ResourceName]int64{}
}
res.OpaqueIntResources[rName] += rQuant.Value()
} }
} }
} }
...@@ -330,11 +333,7 @@ func (n *NodeInfo) SetNode(node *v1.Node) error { ...@@ -330,11 +333,7 @@ func (n *NodeInfo) SetNode(node *v1.Node) error {
n.allowedPodNumber = int(rQuant.Value()) n.allowedPodNumber = int(rQuant.Value())
default: default:
if v1.IsOpaqueIntResourceName(rName) { if v1.IsOpaqueIntResourceName(rName) {
// Lazily allocate opaque resource map. n.allocatableResource.AddOpaque(rName, rQuant.Value())
if n.allocatableResource.OpaqueIntResources == nil {
n.allocatableResource.OpaqueIntResources = map[v1.ResourceName]int64{}
}
n.allocatableResource.OpaqueIntResources[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