Skip to content

Commit 553e53d

Browse files
committed
Fix default handling of pids-limit
Add test to verify that updates without a pids-limit specified no longer overwrite the previous value. Also fixes erroneous warning generated by remote clients: "Resource limits are not supported and ignored on cgroups V1 rootless systems" Signed-off-by: Jason T. Greene <[email protected]>
1 parent 986a3a6 commit 553e53d

File tree

5 files changed

+54
-14
lines changed

5 files changed

+54
-14
lines changed

cmd/podman/common/create.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -893,8 +893,7 @@ func DefineCreateFlags(cmd *cobra.Command, cf *entities.ContainerCreateOptions,
893893
_ = cmd.RegisterFlagCompletionFunc(deviceWriteIopsFlagName, completion.AutocompleteDefault)
894894

895895
pidsLimitFlagName := "pids-limit"
896-
createFlags.Int64Var(
897-
cf.PIDsLimit,
896+
createFlags.Int64(
898897
pidsLimitFlagName, pidsLimit(),
899898
"Tune container pids limit (set -1 for unlimited)",
900899
)

cmd/podman/common/create_opts.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,4 @@ func DefineCreateDefaults(opts *entities.ContainerCreateOptions) {
9292
opts.Ulimit = ulimits()
9393
opts.SeccompPolicy = "default"
9494
opts.Volume = volumes()
95-
opts.PIDsLimit = &podmanConfig.ContainersConf.Containers.PidsLimit
9695
}

cmd/podman/containers/create.go

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,23 @@ func replaceContainer(name string) error {
196196
return removeContainers([]string{name}, rmOptions, false)
197197
}
198198

199+
func createOrUpdateFlags(cmd *cobra.Command, vals *entities.ContainerCreateOptions) error {
200+
if cmd.Flags().Changed("pids-limit") {
201+
val := cmd.Flag("pids-limit").Value.String()
202+
// Convert -1 to 0, so that -1 maps to unlimited pids limit
203+
if val == "-1" {
204+
val = "0"
205+
}
206+
pidsLimit, err := strconv.ParseInt(val, 10, 32)
207+
if err != nil {
208+
return err
209+
}
210+
vals.PIDsLimit = &pidsLimit
211+
}
212+
213+
return nil
214+
}
215+
199216
func CreateInit(c *cobra.Command, vals entities.ContainerCreateOptions, isInfra bool) (entities.ContainerCreateOptions, error) {
200217
if len(vals.UIDMap) > 0 || len(vals.GIDMap) > 0 || vals.SubUIDName != "" || vals.SubGIDName != "" {
201218
if c.Flag("userns").Changed {
@@ -255,18 +272,11 @@ func CreateInit(c *cobra.Command, vals entities.ContainerCreateOptions, isInfra
255272
}
256273
vals.OOMScoreAdj = &val
257274
}
258-
if c.Flags().Changed("pids-limit") {
259-
val := c.Flag("pids-limit").Value.String()
260-
// Convert -1 to 0, so that -1 maps to unlimited pids limit
261-
if val == "-1" {
262-
val = "0"
263-
}
264-
pidsLimit, err := strconv.ParseInt(val, 10, 32)
265-
if err != nil {
266-
return vals, err
267-
}
268-
vals.PIDsLimit = &pidsLimit
275+
276+
if err := createOrUpdateFlags(c, &vals); err != nil {
277+
return vals, err
269278
}
279+
270280
if c.Flags().Changed("env") {
271281
env, err := c.Flags().GetStringArray("env")
272282
if err != nil {

cmd/podman/containers/update.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ func update(cmd *cobra.Command, args []string) error {
6565
s := &specgen.SpecGenerator{}
6666
s.ResourceLimits = &specs.LinuxResources{}
6767

68+
err = createOrUpdateFlags(cmd, &updateOpts)
69+
if err != nil {
70+
return err
71+
}
72+
6873
// we need to pass the whole specgen since throttle devices are parsed later due to cross compat.
6974
s.ResourceLimits, err = specgenutil.GetResources(s, &updateOpts)
7075
if err != nil {

test/e2e/update_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,33 @@ var _ = Describe("Podman update", func() {
9898

9999
})
100100

101+
It("podman update container unspecified pid limit", func() {
102+
SkipIfCgroupV1("testing flags that only work in cgroup v2")
103+
SkipIfRootless("many of these handlers are not enabled while rootless in CI")
104+
session := podmanTest.Podman([]string{"run", "-dt", "--pids-limit", "-1", ALPINE})
105+
session.WaitWithDefaultTimeout()
106+
Expect(session).Should(Exit(0))
107+
108+
ctrID := session.OutputToString()
109+
110+
commonArgs := []string{
111+
"update",
112+
"--cpus", "5",
113+
ctrID}
114+
115+
session = podmanTest.Podman(commonArgs)
116+
session.WaitWithDefaultTimeout()
117+
Expect(session).Should(Exit(0))
118+
119+
ctrID = session.OutputToString()
120+
121+
// checking pids-limit was not changed after update when not specified as an option
122+
session = podmanTest.Podman([]string{"exec", "-it", ctrID, "cat", "/sys/fs/cgroup/pids.max"})
123+
session.WaitWithDefaultTimeout()
124+
Expect(session).Should(Exit(0))
125+
Expect(session.OutputToString()).Should(ContainSubstring("max"))
126+
})
127+
101128
It("podman update container all options v2", func() {
102129
SkipIfCgroupV1("testing flags that only work in cgroup v2")
103130
SkipIfRootless("many of these handlers are not enabled while rootless in CI")

0 commit comments

Comments
 (0)