mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-21 17:48:01 +00:00
Minor hygiene in scheduler.
- Unified lazy opaque resource caching. - Deleted a commented-out line of code.
This commit is contained in:
parent
6d19340d95
commit
94b9c0e20c
@ -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())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user