Skip to content

Commit da5f0a8

Browse files
saintubeFillZpp
authored andcommitted
koordlet: fix batch resource plugin for empty label pods (#952)
Signed-off-by: saintube <saintube@foxmail.com>
1 parent 80c1f87 commit da5f0a8

File tree

3 files changed

+37
-6
lines changed

3 files changed

+37
-6
lines changed

pkg/koordlet/runtimehooks/hooks/batchresource/batch_resource.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,5 @@ func (p *plugin) SetContainerMemoryLimit(proto protocol.HooksProtocol) error {
360360
}
361361

362362
func isPodQoSBEByAttr(labels map[string]string, annotations map[string]string) bool {
363-
if labels == nil || annotations == nil {
364-
return false
365-
}
366363
return apiext.GetQoSClassByAttrs(labels, annotations) == apiext.QoSBE
367364
}

pkg/koordlet/runtimehooks/hooks/batchresource/batch_resource_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,3 +595,37 @@ func Test_plugin_SetContainerResources(t *testing.T) {
595595
})
596596
}
597597
}
598+
599+
func Test_isPodQoSBEByAttr(t *testing.T) {
600+
tests := []struct {
601+
name string
602+
arg map[string]string
603+
arg1 map[string]string
604+
want bool
605+
}{
606+
{
607+
name: "qos is BE",
608+
arg: map[string]string{
609+
apiext.LabelPodQoS: string(apiext.QoSBE),
610+
},
611+
want: true,
612+
},
613+
{
614+
name: "qos is not BE",
615+
arg: map[string]string{
616+
apiext.LabelPodQoS: string(apiext.QoSLS),
617+
},
618+
want: false,
619+
},
620+
{
621+
name: "qos is not BE 1",
622+
want: false,
623+
},
624+
}
625+
for _, tt := range tests {
626+
t.Run(tt.name, func(t *testing.T) {
627+
got := isPodQoSBEByAttr(tt.arg, tt.arg1)
628+
assert.Equal(t, tt.want, got)
629+
})
630+
}
631+
}

pkg/koordlet/runtimehooks/protocol/pod_context.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func (p *PodContext) injectForExt() {
158158
klog.Infof("set pod %v/%v cpu shares %v on cgroup parent %v failed, error %v", p.Request.PodMeta.Namespace,
159159
p.Request.PodMeta.Name, *p.Response.Resources.CPUShares, p.Request.CgroupParent, err)
160160
} else {
161-
klog.V(5).Infof("set pod %v/%v/%v cpu shares %v on cgroup parent %v",
161+
klog.V(5).Infof("set pod %v/%v cpu shares %v on cgroup parent %v",
162162
p.Request.PodMeta.Namespace, p.Request.PodMeta.Name, *p.Response.Resources.CPUShares, p.Request.CgroupParent)
163163
audit.V(2).Pod(p.Request.PodMeta.Namespace, p.Request.PodMeta.Name).Reason("runtime-hooks").Message(
164164
"set pod cpu shares to %v", *p.Response.Resources.CPUShares).Do()
@@ -169,7 +169,7 @@ func (p *PodContext) injectForExt() {
169169
klog.Infof("set pod %v/%v cfs quota %v on cgroup parent %v failed, error %v", p.Request.PodMeta.Namespace,
170170
p.Request.PodMeta.Name, *p.Response.Resources.CFSQuota, p.Request.CgroupParent, err)
171171
} else {
172-
klog.V(5).Infof("set pod %v/%v/%v cfs quota %v on cgroup parent %v",
172+
klog.V(5).Infof("set pod %v/%v cfs quota %v on cgroup parent %v",
173173
p.Request.PodMeta.Namespace, p.Request.PodMeta.Name, *p.Response.Resources.CFSQuota, p.Request.CgroupParent)
174174
audit.V(2).Pod(p.Request.PodMeta.Namespace, p.Request.PodMeta.Name).Reason("runtime-hooks").Message(
175175
"set pod cfs quota to %v", *p.Response.Resources.CFSQuota).Do()
@@ -180,7 +180,7 @@ func (p *PodContext) injectForExt() {
180180
klog.Infof("set pod %v/%v memory limit %v on cgroup parent %v failed, error %v", p.Request.PodMeta.Namespace,
181181
p.Request.PodMeta.Name, *p.Response.Resources.MemoryLimit, p.Request.CgroupParent, err)
182182
} else {
183-
klog.V(5).Infof("set pod %v/%v/%v memory limit %v on cgroup parent %v",
183+
klog.V(5).Infof("set pod %v/%v memory limit %v on cgroup parent %v",
184184
p.Request.PodMeta.Namespace, p.Request.PodMeta.Name, *p.Response.Resources.MemoryLimit, p.Request.CgroupParent)
185185
audit.V(2).Pod(p.Request.PodMeta.Namespace, p.Request.PodMeta.Name).Reason("runtime-hooks").Message(
186186
"set pod memory limit to %v", *p.Response.Resources.MemoryLimit).Do()

0 commit comments

Comments
 (0)