Skip to content

Commit

Permalink
keeping the qos code as-is for the existing case when pod-level resou…
Browse files Browse the repository at this point in the history
…rces are not set

Signed-off-by: ndixita <[email protected]>
  • Loading branch information
ndixita committed Nov 8, 2024
1 parent b78f6e2 commit b30e6c8
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 8 deletions.
36 changes: 32 additions & 4 deletions pkg/apis/core/helper/qos/qos.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,39 @@ func ComputePodQOS(pod *core.Pod) core.PodQOSClass {
allContainers = append(allContainers, pod.Spec.InitContainers...)
for _, container := range allContainers {
// process requests
processResourceList(requests, container.Resources.Requests)
for name, quantity := range container.Resources.Requests {
if !isSupportedQoSComputeResource(name) {
continue
}
if quantity.Cmp(zeroQuantity) == 1 {
delta := quantity.DeepCopy()
if _, exists := requests[name]; !exists {
requests[name] = delta
} else {
delta.Add(requests[name])
requests[name] = delta
}
}
}
// process limits
processResourceList(limits, container.Resources.Limits)
qosLimitResources := getQOSResources(container.Resources.Limits)
if !qosLimitResources.HasAll(string(core.ResourceMemory), string(core.ResourceCPU)) {
qosLimitsFound := sets.NewString()
for name, quantity := range container.Resources.Limits {
if !isSupportedQoSComputeResource(name) {
continue
}
if quantity.Cmp(zeroQuantity) == 1 {
qosLimitsFound.Insert(string(name))
delta := quantity.DeepCopy()
if _, exists := limits[name]; !exists {
limits[name] = delta
} else {
delta.Add(limits[name])
limits[name] = delta
}
}
}

if !qosLimitsFound.HasAll(string(core.ResourceMemory), string(core.ResourceCPU)) {
isGuaranteed = false
}
}
Expand Down
36 changes: 32 additions & 4 deletions pkg/apis/core/v1/helper/qos/qos.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,39 @@ func ComputePodQOS(pod *v1.Pod) v1.PodQOSClass {
allContainers = append(allContainers, pod.Spec.InitContainers...)
for _, container := range allContainers {
// process requests
processResourceList(requests, container.Resources.Requests)
for name, quantity := range container.Resources.Requests {
if !isSupportedQoSComputeResource(name) {
continue
}
if quantity.Cmp(zeroQuantity) == 1 {
delta := quantity.DeepCopy()
if _, exists := requests[name]; !exists {
requests[name] = delta
} else {
delta.Add(requests[name])
requests[name] = delta
}
}
}
// process limits
processResourceList(limits, container.Resources.Limits)
qosLimitResources := getQOSResources(container.Resources.Limits)
if !qosLimitResources.HasAll(string(v1.ResourceMemory), string(v1.ResourceCPU)) {
qosLimitsFound := sets.NewString()
for name, quantity := range container.Resources.Limits {
if !isSupportedQoSComputeResource(name) {
continue
}
if quantity.Cmp(zeroQuantity) == 1 {
qosLimitsFound.Insert(string(name))
delta := quantity.DeepCopy()
if _, exists := limits[name]; !exists {
limits[name] = delta
} else {
delta.Add(limits[name])
limits[name] = delta
}
}
}

if !qosLimitsFound.HasAll(string(v1.ResourceMemory), string(v1.ResourceCPU)) {
isGuaranteed = false
}
}
Expand Down

0 comments on commit b30e6c8

Please sign in to comment.