This is an automated email from the ASF dual-hosted git repository.
zhuqi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/yunikorn-k8shim.git
The following commit(s) were added to refs/heads/master by this push:
new 24c699fa [YUNIKORN-2271] Incorrect handling of GPU only resources
(#749)
24c699fa is described below
commit 24c699fa9485f2c9b06fc8c88b0e279d2e1c5f2a
Author: Qi Zhu <[email protected]>
AuthorDate: Tue Dec 19 12:43:22 2023 +0800
[YUNIKORN-2271] Incorrect handling of GPU only resources (#749)
---
pkg/common/resource.go | 6 ------
pkg/common/resource_test.go | 43 ++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 42 insertions(+), 7 deletions(-)
diff --git a/pkg/common/resource.go b/pkg/common/resource.go
index 96c8c7a9..cad82d0c 100644
--- a/pkg/common/resource.go
+++ b/pkg/common/resource.go
@@ -22,7 +22,6 @@ import (
"go.uber.org/zap"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
- "k8s.io/kubernetes/pkg/apis/core/v1/helper/qos"
"github.com/apache/yunikorn-k8shim/pkg/log"
siCommon "github.com/apache/yunikorn-scheduler-interface/lib/go/common"
@@ -57,11 +56,6 @@ func GetPodResource(pod *v1.Pod) (resource *si.Resource) {
Resources: map[string]*si.Quantity{"pods": {Value: 1}},
}
- // A QosBestEffort pod does not request any resources, just a single pod
- if qos.GetPodQOS(pod) == v1.PodQOSBestEffort {
- return podResource
- }
-
for _, c := range pod.Spec.Containers {
resourceList := c.Resources.Requests
containerResource := getResource(resourceList)
diff --git a/pkg/common/resource_test.go b/pkg/common/resource_test.go
index f1555449..bc4cca75 100644
--- a/pkg/common/resource_test.go
+++ b/pkg/common/resource_test.go
@@ -325,8 +325,49 @@ func TestBestEffortPod(t *testing.T) {
resources[v1.ResourceCPU] = resource.MustParse("0")
res = GetPodResource(pod)
- assert.Equal(t, len(res.Resources), 1)
+ assert.Equal(t, len(res.Resources), 3)
+ assert.Equal(t, res.Resources["pods"].GetValue(), int64(1))
+ assert.Equal(t, res.Resources[siCommon.CPU].GetValue(), int64(0))
+ assert.Equal(t, res.Resources[siCommon.Memory].GetValue(), int64(0))
+}
+
+func TestGPUOnlyResources(t *testing.T) {
+ containers := make([]v1.Container, 0)
+
+ // container 01
+ c1Resources := make(map[v1.ResourceName]resource.Quantity)
+ c1Resources[v1.ResourceName("nvidia.com/gpu")] = resource.MustParse("1")
+ containers = append(containers, v1.Container{
+ Name: "container-01",
+ Resources: v1.ResourceRequirements{
+ Requests: c1Resources,
+ },
+ })
+
+ pod := &v1.Pod{
+ TypeMeta: apis.TypeMeta{
+ Kind: "Pod",
+ APIVersion: "v1",
+ },
+ ObjectMeta: apis.ObjectMeta{
+ Name: "pod-resource-test-00001",
+ UID: "UID-00001",
+ },
+ Spec: v1.PodSpec{
+ Containers: containers,
+ },
+ }
+
+ res := GetPodResource(pod)
+ assert.Equal(t, len(res.Resources), 2)
+ assert.Equal(t, res.Resources["pods"].GetValue(), int64(1))
+ assert.Equal(t, res.Resources["nvidia.com/gpu"].GetValue(), int64(1))
+
+ c1Resources[v1.ResourceName("nvidia.com/gpu")] = resource.MustParse("0")
+ res = GetPodResource(pod)
+ assert.Equal(t, len(res.Resources), 2)
assert.Equal(t, res.Resources["pods"].GetValue(), int64(1))
+ assert.Equal(t, res.Resources["nvidia.com/gpu"].GetValue(), int64(0))
}
func TestNodeResource(t *testing.T) {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]