Skip to content

Commit

Permalink
koordlet: fix batch resource plugin for empty label pods (#952)
Browse files Browse the repository at this point in the history
Signed-off-by: saintube <[email protected]>
  • Loading branch information
saintube authored and FillZpp committed Jan 16, 2023
1 parent 80c1f87 commit da5f0a8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
}
6 changes: 3 additions & 3 deletions pkg/koordlet/runtimehooks/protocol/pod_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down

0 comments on commit da5f0a8

Please sign in to comment.