mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-21 01:26:28 +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()
|
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 {
|
|||||||
}
|
}
|
||||||
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 {
|
|||||||
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 {
|
|||||||
|
|
||||||
// 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
|
|||||||
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 {
|
|||||||
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()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user