From b5fc359973c0e8c599b12c1d118546c267894b3b Mon Sep 17 00:00:00 2001 From: Samuel Karp Date: Wed, 23 Oct 2024 11:40:12 -0700 Subject: [PATCH 1/2] generate: do not set OOMScoreAdj if no adjustment Existing OOMScoreAdj on the incoming spec should not be cleared. Fixes https://github.com/containerd/nri/issues/117 Signed-off-by: Samuel Karp --- pkg/runtime-tools/generate/generate.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/pkg/runtime-tools/generate/generate.go b/pkg/runtime-tools/generate/generate.go index 40ed98f..cd2bc28 100644 --- a/pkg/runtime-tools/generate/generate.go +++ b/pkg/runtime-tools/generate/generate.go @@ -329,9 +329,6 @@ func (g *Generator) AdjustCgroupsPath(path string) { func (g *Generator) AdjustOomScoreAdj(score *nri.OptionalInt) { if score != nil { g.SetProcessOOMScoreAdj(int(score.Value)) - } else { - g.SetProcessOOMScoreAdj(0) - g.Config.Process.OOMScoreAdj = nil } } From 07bfc18129a3cc9c4b44e1aced9972279a50ddb5 Mon Sep 17 00:00:00 2001 From: Samuel Karp Date: Wed, 23 Oct 2024 11:20:42 -0700 Subject: [PATCH 2/2] wip: generate: add test for oom score adj The generator should not clear an existing OOMScoreAdj if no adjustment is performed. Signed-off-by: Samuel Karp --- .../generate/generate_suite_test.go | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pkg/runtime-tools/generate/generate_suite_test.go b/pkg/runtime-tools/generate/generate_suite_test.go index 20158d5..9a665fe 100644 --- a/pkg/runtime-tools/generate/generate_suite_test.go +++ b/pkg/runtime-tools/generate/generate_suite_test.go @@ -158,6 +158,26 @@ var _ = Describe("Adjustment", func() { }) }) + When("existing oom score adj", func() { + It("does not adjust Spec", func() { + var ( + spec = makeSpec() + expectedSpec = makeSpec() + adjust = &api.ContainerAdjustment{} + ) + oomScoreAdj := 123 + spec.Process.OOMScoreAdj = &oomScoreAdj + expectedSpec.Process.OOMScoreAdj = &oomScoreAdj + + rg := &rgen.Generator{Config: spec} + xg := xgen.SpecGenerator(rg) + + Expect(xg).ToNot(BeNil()) + Expect(xg.Adjust(adjust)).To(Succeed()) + Expect(spec).To(Equal(expectedSpec)) + }) + }) + When("has CPU shares", func() { It("adjusts Spec correctly", func() { var (