diff --git a/pkg/resmgr/cache/cache.go b/pkg/resmgr/cache/cache.go index 579e6dd89..907fca272 100644 --- a/pkg/resmgr/cache/cache.go +++ b/pkg/resmgr/cache/cache.go @@ -59,6 +59,11 @@ const ( // TopologyHintsKey can be used to opt out from automatic topology hint generation. TopologyHintsKey = "topologyhints" + "." + kubernetes.ResmgrKeyNamespace + + // PreserveCpuKey means that CPU resources should not be touched. + PreserveCpuKey = "cpu.preserve." + kubernetes.ResmgrKeyNamespace + // PreserveMemoryKey means that memory resources should not be touched. + PreserveMemoryKey = "memory.preserve." + kubernetes.ResmgrKeyNamespace ) // PodState is the pod state in the runtime. @@ -245,6 +250,13 @@ type Container interface { // GetMemorySwap gets the swap limit in bytes for the container. GetMemorySwap() int64 + // PreserveCpuResources() returns true if CPU resources of the + // container must not be changed. + PreserveCpuResources() bool + // PreserveMemoryResources() returns true if memory resources + // of the container must not be changed. + PreserveMemoryResources() bool + // GetPendingAdjusmentn clears and returns any pending adjustment for the container. GetPendingAdjustment() *nri.ContainerAdjustment // GetPendingUpdate clears and returns any pending update for the container. diff --git a/pkg/resmgr/cache/container.go b/pkg/resmgr/cache/container.go index 0b9f6b1d9..a0ea6707e 100644 --- a/pkg/resmgr/cache/container.go +++ b/pkg/resmgr/cache/container.go @@ -761,6 +761,16 @@ func (c *container) GetMemorySwap() int64 { return c.Ctr.GetLinux().GetResources().GetMemory().GetSwap().GetValue() } +func (c *container) PreserveCpuResources() bool { + value, ok := c.GetEffectiveAnnotation(PreserveCpuKey) + return ok && value == "true" +} + +func (c *container) PreserveMemoryResources() bool { + value, ok := c.GetEffectiveAnnotation(PreserveMemoryKey) + return ok && value == "true" +} + var ( // More complext rules, for Kubelet secrets and config maps ignoredTopologyPathRegexps = []*regexp.Regexp{