Skip to content

Commit 19dae85

Browse files
klihubaskervin
authored andcommitted
cache: prefer annotated resources if present.
Signed-off-by: Krisztian Litkey <krisztian.litkey@intel.com>
1 parent ae5a70b commit 19dae85

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

pkg/resmgr/cache/cache.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ const (
6868
// UnlimitedBurstabileKey defines the preferred topology level for containers
6969
// with unlimited burstability.
7070
UnlimitedBurstableKey = "unlimited-burstable." + kubernetes.ResmgrKeyNamespace
71+
72+
// AnnotatedResourcesKey can be used to annotate resource requirements of
73+
// containers and init containers on the pod.
74+
AnnotatedResourcesKey = kubernetes.AnnotatedResourcesKey
7175
)
7276

7377
// PodState is the pod state in the runtime.

pkg/resmgr/cache/container.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,36 @@ func isReadOnlyDevice(rules []*nri.LinuxDeviceCgroup, d *nri.LinuxDevice) bool {
306306
return readOnly
307307
}
308308

309+
func (c *container) GetAnnotatedResources() (v1.ResourceRequirements, bool) {
310+
pod, ok := c.GetPod()
311+
if !ok {
312+
return v1.ResourceRequirements{}, false
313+
}
314+
315+
data, ok := pod.GetAnnotation(AnnotatedResourcesKey)
316+
if !ok {
317+
return v1.ResourceRequirements{}, false
318+
}
319+
320+
annotated := &kubernetes.AnnotatedResources{}
321+
if err := annotated.Unmarshal([]byte(data)); err != nil {
322+
log.Error("failed to unmarshal annotated resources for pod %s: %v",
323+
pod.PrettyName(), err)
324+
return v1.ResourceRequirements{}, false
325+
}
326+
327+
resources, ok := annotated.Containers[c.GetName()]
328+
return resources, ok
329+
}
330+
309331
// Estimate resource requirements using the containers cgroup parameters and QoS class.
310332
func (c *container) estimateResourceRequirements() {
333+
if annotated, ok := c.GetAnnotatedResources(); ok {
334+
log.Info("%s: using annotated resources %+v", c.PrettyName(), annotated)
335+
c.Requirements = annotated
336+
return
337+
}
338+
311339
r := c.Ctr.GetLinux().GetResources()
312340
qosClass := c.GetQOSClass()
313341
oomAdj := c.Ctr.GetLinux().GetOomScoreAdj().GetValue()

0 commit comments

Comments
 (0)