Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[YUNIKORN-1526] support K8s pod overhead #520

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions pkg/common/resource.go
Expand Up @@ -79,6 +79,22 @@ func GetPodResource(pod *v1.Pod) (resource *si.Resource) {
checkInitContainerRequest(pod, podResource)
}

// K8s pod EnableOverHead from:
// alpha: v1.16
// beta: v1.18
// Enables PodOverhead, for accounting pod overheads which are specific to a given RuntimeClass

// If Overhead is being utilized, add to the total requests for the pod
craigcondit marked this conversation as resolved.
Show resolved Hide resolved
if pod.Spec.Overhead != nil {
podOverHeadResource := getResource(pod.Spec.Overhead)
podResource = Add(podResource, podOverHeadResource)
// Logging the overall pod size and pod overhead
log.Logger().Debug("Pod overhead specified, overall pod size adjusted",
craigcondit marked this conversation as resolved.
Show resolved Hide resolved
zap.String("taskID", string(pod.UID)),
zap.Stringer("overallSize", podResource),
zap.Stringer("overheadSize", podOverHeadResource))
}

return podResource
}

Expand Down
14 changes: 14 additions & 0 deletions pkg/common/resource_test.go
Expand Up @@ -191,6 +191,20 @@ func TestParsePodResource(t *testing.T) {
assert.Equal(t, res.Resources[siCommon.CPU].GetValue(), int64(3000))
assert.Equal(t, res.Resources["nvidia.com/gpu"].GetValue(), int64(5))

// Add pod OverHead
overHeadResources := make(map[v1.ResourceName]resource.Quantity)
overHeadResources[v1.ResourceMemory] = resource.MustParse("500M")
overHeadResources[v1.ResourceCPU] = resource.MustParse("1")
overHeadResources[v1.ResourceName("nvidia.com/gpu")] = resource.MustParse("1")
// Set pod OverHead
pod.Spec.Overhead = overHeadResources

// verify we get aggregated resource from containers
res = GetPodResource(pod)
assert.Equal(t, res.Resources[siCommon.Memory].GetValue(), int64(2024*1000*1000))
assert.Equal(t, res.Resources[siCommon.CPU].GetValue(), int64(4000))
assert.Equal(t, res.Resources["nvidia.com/gpu"].GetValue(), int64(6))

// test initcontainer and container resouce compare
initContainers := make([]v1.Container, 0)
initc1Resources := make(map[v1.ResourceName]resource.Quantity)
Expand Down