From da5f0a81cafcdb56b869e81b1c66732148603c06 Mon Sep 17 00:00:00 2001 From: Frame Date: Thu, 12 Jan 2023 13:17:21 +0800 Subject: [PATCH] koordlet: fix batch resource plugin for empty label pods (#952) Signed-off-by: saintube --- .../hooks/batchresource/batch_resource.go | 3 -- .../batchresource/batch_resource_test.go | 34 +++++++++++++++++++ .../runtimehooks/protocol/pod_context.go | 6 ++-- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/pkg/koordlet/runtimehooks/hooks/batchresource/batch_resource.go b/pkg/koordlet/runtimehooks/hooks/batchresource/batch_resource.go index b671daa0a..e5771d72a 100644 --- a/pkg/koordlet/runtimehooks/hooks/batchresource/batch_resource.go +++ b/pkg/koordlet/runtimehooks/hooks/batchresource/batch_resource.go @@ -360,8 +360,5 @@ func (p *plugin) SetContainerMemoryLimit(proto protocol.HooksProtocol) error { } func isPodQoSBEByAttr(labels map[string]string, annotations map[string]string) bool { - if labels == nil || annotations == nil { - return false - } return apiext.GetQoSClassByAttrs(labels, annotations) == apiext.QoSBE } diff --git a/pkg/koordlet/runtimehooks/hooks/batchresource/batch_resource_test.go b/pkg/koordlet/runtimehooks/hooks/batchresource/batch_resource_test.go index 33e7dbf7e..ff8610cbb 100644 --- a/pkg/koordlet/runtimehooks/hooks/batchresource/batch_resource_test.go +++ b/pkg/koordlet/runtimehooks/hooks/batchresource/batch_resource_test.go @@ -595,3 +595,37 @@ func Test_plugin_SetContainerResources(t *testing.T) { }) } } + +func Test_isPodQoSBEByAttr(t *testing.T) { + tests := []struct { + name string + arg map[string]string + arg1 map[string]string + want bool + }{ + { + name: "qos is BE", + arg: map[string]string{ + apiext.LabelPodQoS: string(apiext.QoSBE), + }, + want: true, + }, + { + name: "qos is not BE", + arg: map[string]string{ + apiext.LabelPodQoS: string(apiext.QoSLS), + }, + want: false, + }, + { + name: "qos is not BE 1", + want: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := isPodQoSBEByAttr(tt.arg, tt.arg1) + assert.Equal(t, tt.want, got) + }) + } +} diff --git a/pkg/koordlet/runtimehooks/protocol/pod_context.go b/pkg/koordlet/runtimehooks/protocol/pod_context.go index 9ce3f9584..6339de313 100644 --- a/pkg/koordlet/runtimehooks/protocol/pod_context.go +++ b/pkg/koordlet/runtimehooks/protocol/pod_context.go @@ -158,7 +158,7 @@ func (p *PodContext) injectForExt() { klog.Infof("set pod %v/%v cpu shares %v on cgroup parent %v failed, error %v", p.Request.PodMeta.Namespace, p.Request.PodMeta.Name, *p.Response.Resources.CPUShares, p.Request.CgroupParent, err) } else { - klog.V(5).Infof("set pod %v/%v/%v cpu shares %v on cgroup parent %v", + klog.V(5).Infof("set pod %v/%v cpu shares %v on cgroup parent %v", p.Request.PodMeta.Namespace, p.Request.PodMeta.Name, *p.Response.Resources.CPUShares, p.Request.CgroupParent) audit.V(2).Pod(p.Request.PodMeta.Namespace, p.Request.PodMeta.Name).Reason("runtime-hooks").Message( "set pod cpu shares to %v", *p.Response.Resources.CPUShares).Do() @@ -169,7 +169,7 @@ func (p *PodContext) injectForExt() { klog.Infof("set pod %v/%v cfs quota %v on cgroup parent %v failed, error %v", p.Request.PodMeta.Namespace, p.Request.PodMeta.Name, *p.Response.Resources.CFSQuota, p.Request.CgroupParent, err) } else { - klog.V(5).Infof("set pod %v/%v/%v cfs quota %v on cgroup parent %v", + klog.V(5).Infof("set pod %v/%v cfs quota %v on cgroup parent %v", p.Request.PodMeta.Namespace, p.Request.PodMeta.Name, *p.Response.Resources.CFSQuota, p.Request.CgroupParent) audit.V(2).Pod(p.Request.PodMeta.Namespace, p.Request.PodMeta.Name).Reason("runtime-hooks").Message( "set pod cfs quota to %v", *p.Response.Resources.CFSQuota).Do() @@ -180,7 +180,7 @@ func (p *PodContext) injectForExt() { klog.Infof("set pod %v/%v memory limit %v on cgroup parent %v failed, error %v", p.Request.PodMeta.Namespace, p.Request.PodMeta.Name, *p.Response.Resources.MemoryLimit, p.Request.CgroupParent, err) } else { - klog.V(5).Infof("set pod %v/%v/%v memory limit %v on cgroup parent %v", + klog.V(5).Infof("set pod %v/%v memory limit %v on cgroup parent %v", p.Request.PodMeta.Namespace, p.Request.PodMeta.Name, *p.Response.Resources.MemoryLimit, p.Request.CgroupParent) audit.V(2).Pod(p.Request.PodMeta.Namespace, p.Request.PodMeta.Name).Reason("runtime-hooks").Message( "set pod memory limit to %v", *p.Response.Resources.MemoryLimit).Do()