Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuqi-lucas committed Dec 16, 2023
1 parent 5027eb8 commit 934f3ac
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 22 deletions.
23 changes: 3 additions & 20 deletions pkg/common/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@
package common

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"
"github.com/apache/yunikorn-scheduler-interface/lib/go/si"
"go.uber.org/zap"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
)

// resource builder is a helper struct to construct si resources
Expand Down Expand Up @@ -69,21 +67,6 @@ func GetPodResource(pod *v1.Pod) (resource *si.Resource) {
checkInitContainerRequest(pod, podResource)
}

// iterate the pod resources when resource is zero, remove it from the pod resource
for k, v := range podResource.Resources {
if v.Value == 0 {
delete(podResource.Resources, k)
}
}

// A QosBestEffort pod does not request any cpu/mem resources, just a single pod
// But with other resources requested, it is not the best effort pod
if qos.GetPodQOS(pod) == v1.PodQOSBestEffort && (len(podResource.Resources) == 1) {
return &si.Resource{
Resources: map[string]*si.Quantity{"pods": {Value: 1}},
}
}

// K8s pod EnableOverHead from:
// alpha: v1.16
// beta: v1.18
Expand Down
7 changes: 5 additions & 2 deletions pkg/common/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,10 @@ 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) {
Expand Down Expand Up @@ -363,8 +365,9 @@ func TestGPUOnlyResources(t *testing.T) {

c1Resources[v1.ResourceName("nvidia.com/gpu")] = resource.MustParse("0")
res = GetPodResource(pod)
assert.Equal(t, len(res.Resources), 1)
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 934f3ac

Please sign in to comment.