Skip to content

Commit

Permalink
Fix overwriting of LinuxResources structure in the database
Browse files Browse the repository at this point in the history
with defaults values when changes configuration with podman update.

The new LinuxResource structure does not represent the current unchanged configuration, which was not affected by the change.

Fixes: https://issues.redhat.com/browse/RUN-2375

Signed-off-by: Jan Rodák <[email protected]>
  • Loading branch information
Honny1 committed Dec 4, 2024
1 parent bf1661c commit 8a017fb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
17 changes: 15 additions & 2 deletions libpod/container_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -2674,7 +2674,12 @@ func (c *Container) update(resources *spec.LinuxResources, restartPolicy *string
return fmt.Errorf("must provide restart policy if updating restart retries: %w", define.ErrInvalidArg)
}

oldResources := c.config.Spec.Linux.Resources
oldResources := new(spec.LinuxResources)
if c.config.Spec.Linux.Resources != nil {
if err := JSONDeepCopy(c.config.Spec.Linux.Resources, oldResources); err != nil {
return err
}
}
oldRestart := c.config.RestartPolicy
oldRetries := c.config.RestartRetries

Expand All @@ -2701,7 +2706,15 @@ func (c *Container) update(resources *spec.LinuxResources, restartPolicy *string
if c.config.Spec.Linux == nil {
c.config.Spec.Linux = new(spec.Linux)
}
c.config.Spec.Linux.Resources = resources

resourcesToUpdate, err := json.Marshal(resources)
if err != nil {
return err
}
if err := json.Unmarshal(resourcesToUpdate, c.config.Spec.Linux.Resources); err != nil {
return err
}
resources = c.config.Spec.Linux.Resources
}

if err := c.runtime.state.SafeRewriteContainerConfig(c, "", "", c.config); err != nil {
Expand Down
17 changes: 17 additions & 0 deletions test/system/280-update.bats
Original file line number Diff line number Diff line change
Expand Up @@ -309,4 +309,21 @@ function nrand() {

run_podman rm -t 0 -f $ctrname
}

# bats test_tags=ci:parallel
@test "podman update - resources on update are not changed unless requested" {
local ctrname="c-h-$(safename)"
run_podman run -d --name $ctrname \
--pids-limit 1024 \
$IMAGE /home/podman/pause

run_podman update $ctrname --memory 100M

# A Pid check is performed to ensure that other resource settings are not unset. https://github.com/containers/podman/issues/24610
run_podman inspect $ctrname --format "{{.HostConfig.Memory}}\n{{.HostConfig.PidsLimit}}"
assert ${lines[0]%"${lines[0]##*[![:space:]]}"} == "104857600" ".HostConfig.Memory"
assert ${lines[1]%"${lines[1]##*[![:space:]]}"} == "1024" ".HostConfig.PidsLimit"

run_podman rm -t 0 -f $ctrname
}
# vim: filetype=sh

0 comments on commit 8a017fb

Please sign in to comment.