Skip to content

Commit

Permalink
[YUNIKORN-2271] Incorrect handling of GPU only resources (#749)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuqi-lucas authored Dec 19, 2023
1 parent a118ba6 commit 24c699f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
6 changes: 0 additions & 6 deletions pkg/common/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
43 changes: 42 additions & 1 deletion pkg/common/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 24c699f

Please sign in to comment.