diff --git a/cmd/plugins/balloons/policy/balloons-policy.go b/cmd/plugins/balloons/policy/balloons-policy.go index cd1eb220b..a9dd0c8ec 100644 --- a/cmd/plugins/balloons/policy/balloons-policy.go +++ b/cmd/plugins/balloons/policy/balloons-policy.go @@ -206,6 +206,10 @@ func (p *balloons) Sync(add []cache.Container, del []cache.Container) error { // AllocateResources is a resource allocation request for this policy. func (p *balloons) AllocateResources(c cache.Container) error { + if c.PreserveCpuResources() { + log.Infof("not handling resources of container %s, preserving CPUs %q and memory %q", c.PrettyName(), c.GetCpusetCpus(), c.GetCpusetMems()) + return nil + } log.Debug("allocating resources for container %s (request %d mCPU, limit %d mCPU)...", c.PrettyName(), p.containerRequestedMilliCpus(c.GetID()), @@ -1367,8 +1371,12 @@ func (p *balloons) pinCpuMem(c cache.Container, cpus cpuset.CPUSet, mems idset.I } } if p.bpoptions.PinMemory == nil || *p.bpoptions.PinMemory { - log.Debug(" - pinning %s to memory %s", c.PrettyName(), mems) - c.SetCpusetMems(mems.String()) + if c.PreserveMemoryResources() { + log.Debug(" - preserving %s pinning to memory %q", c.PrettyName, c.GetCpusetMems()) + } else { + log.Debug(" - pinning %s to memory %s", c.PrettyName(), mems) + c.SetCpusetMems(mems.String()) + } } } diff --git a/docs/resource-policy/policy/balloons.md b/docs/resource-policy/policy/balloons.md index 9bfcc350a..d38c844d6 100644 --- a/docs/resource-policy/policy/balloons.md +++ b/docs/resource-policy/policy/balloons.md @@ -274,6 +274,22 @@ defined explicitly among other balloon types. If not defined, a built-in `default` balloon type is implicitly appended at the end of the balloon types list. +## Disabling CPU or Memory Pinning of a Container + +Some containers may need to run on all CPUs or access all memories +without restrictions. Annotate these pods and containers to prevent +the resource policy from touching their CPU or memory pinning. + +```yaml +cpu.preserve.resource-policy.nri.io/container.CONTAINER_NAME: "true" +cpu.preserve.resource-policy.nri.io/pod: "true" +cpu.preserve.resource-policy.nri.io: "true" + +memory.preserve.resource-policy.nri.io/container.CONTAINER_NAME: "true" +memory.preserve.resource-policy.nri.io/pod: "true" +memory.preserve.resource-policy.nri.io: "true" +``` + ## Metrics and Debugging In order to enable more verbose logging and metrics exporting from the diff --git a/test/e2e/policies.test-suite/balloons/n4c16/test05-namespace/code.var.sh b/test/e2e/policies.test-suite/balloons/n4c16/test05-namespace/code.var.sh index e74de2152..12305eff2 100644 --- a/test/e2e/policies.test-suite/balloons/n4c16/test05-namespace/code.var.sh +++ b/test/e2e/policies.test-suite/balloons/n4c16/test05-namespace/code.var.sh @@ -84,5 +84,17 @@ namespace="e2e-d" CONTCOUNT=2 create balloons-busybox report allowed verify 'cpus["pod6c0"] == cpus["pod6c1"]' + +# pod7: preserve annotation should skip placing a container into any +# balloon even if namespace wildcard in a balloon type matches. +CPUREQ="100m" MEMREQ="100M" CPULIM="100m" MEMLIM="100M" +POD_ANNOTATION='cpu.preserve.resource-policy.nri.io/container.pod7c1: "true" + memory.preserve.resource-policy.nri.io: "true"' +namespace="e2e-d" CONTCOUNT=3 create balloons-busybox +report allowed +verify 'cpus["pod6c0"] == cpus["pod7c0"]' \ + 'len(cpus["pod7c1"]) > len(cpus["pod7c0"])' \ + 'len(cpus["pod7c1"]) == 16' + cleanup helm-terminate