Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

podman update: Fix overwriting of LinuxResources structure #24749

Merged
merged 1 commit into from
Dec 4, 2024

Conversation

Honny1
Copy link
Member

@Honny1 Honny1 commented Dec 3, 2024

This PR fixes overwriting the LinuxResources structure in the database with default values when configuring container with podman update.

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

Reproducer:
podman run -dt --pids-limit 1024 --name hc1 quay.io/libpod/alpine:latest top

podman inspect hc1 --format {{.HostConfig.PidsLimit}}
# 1024
podman update hc1 --memory 100Mb (You can change any other resource of your choice)

podman inspect hc1 --format {{.HostConfig.Memory}}
# 104857600

podman inspect hc1 --format {{.HostConfig.PidsLimit}}
# 0 <- This should print the value 1024

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

Does this PR introduce a user-facing change?

Fix the overwriting of the `LinuxResources` structure in the database with default values when `podman update` changes resource configuration. 

@@ -309,4 +309,22 @@ function nrand() {

run_podman rm -t 0 -f $ctrname
}

# bats test_tags=ci:parallel
@test "podman update - check resources over write Resources configuration" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the name it is not clear what you are testing. Maybe resources on update are not changed unless requested

Comment on lines 322 to 326
run_podman inspect $ctrname --format {{.HostConfig.Memory}}
assert "$output" == "104857600" ".HostConfig.Memory"

run_podman inspect $ctrname --format {{.HostConfig.PidsLimit}}
assert "$output" == "1024" ".HostConfig.PidsLimit"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can combine these in one podman command
--format "{{.HostConfig.Memory}}\n{{.HostConfig.PidsLimit}}" then match assert "${lines[0]}" ... and "${lines[1]}" respectively. This safes us one inspect command so it is a bit faster.

Comment on lines 2677 to 2682
var oldResources *spec.LinuxResources
if c.config.Spec.Linux.Resources != nil {
if err := JSONDeepCopy(oldResources, c.config.Spec.Linux.Resources); err != nil {
return err
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get that, you are copying a nil pointer on that which mean this makes no sense and nothing is copied AFIACT.
If think you want to copy the current settings to oldResources in that case you must change the JSONDeepCopy argument order unless I am missing something.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I missed it.

run_podman inspect $ctrname --format {{.HostConfig.Memory}}
assert "$output" == "104857600" ".HostConfig.Memory"

run_podman inspect $ctrname --format {{.HostConfig.PidsLimit}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a link to the bug #24610 here and add a sentence to explain this pid check is done to ensure other resource setting are not unset.

Comment on lines 324 to 325
assert ${lines[0]%"${lines[0]##*[![:space:]]}"} == "104857600" ".HostConfig.Memory"
assert ${lines[1]%"${lines[1]##*[![:space:]]}"} == "1024" ".HostConfig.PidsLimit"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I not sure what you are trying to do there, this can just be

    assert "${lines[0]}" == "104857600" ".HostConfig.Memory"
    assert "${lines[1]}" == "1024" ".HostConfig.PidsLimit"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I used $lines[0] and got 104857600\[0\]. I thought \[0\] were some weird characters for newlines. So I tried to trim string.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$lines is a bash array so the index must be accessed via ${lines[X]} where X is the index or @ if you want to get all elements
$output is basically the full command output as simple string while $lines is the $output split at newlines. It makes matching certain lines easier for us. There is no strict reason to use $lines.

We could have also done {{.HostConfig.Memory}}--{{.HostConfig.PidsLimit}} and then match $output == 104857600--1024 ... as another example. But that has the downside of using one assert which means if it fails you manually need to compare which of the two values are wrong. This is a tiny bit more work when reading a failed log so using the newline split and matching then using $lines just makes it a bit easier.

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]>
Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
@mheon PTAL

Copy link
Contributor

openshift-ci bot commented Dec 4, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Honny1, Luap99

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 4, 2024
@mheon
Copy link
Member

mheon commented Dec 4, 2024

I like the use of JSONDeepCopy here, nice and simple.
/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Dec 4, 2024
@openshift-merge-bot openshift-merge-bot bot merged commit c707cbe into containers:main Dec 4, 2024
80 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. release-note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

podman update resets the configuration of other container resources
3 participants