fix handling of static/volume dir

The processing and setting of the static and volume directories was
scattered across the code base (including c/common) leading to subtle
errors that surfaced in #19938.

There were multiple issues that I try to summarize below:

 - c/common loaded the graphroot from c/storage to set the defaults for
   static and volume dir.  That ignored Podman's --root flag and
   surfaced in #19938 and other bugs.  c/common does not set the
   defaults anymore which gives Podman the ability to detect when the
   user/admin configured a custom directory (not empty value).

 - When parsing the CLI, Podman (ab)uses containers.conf structures to
   set the defaults but also to override them in case the user specified
   a flag.  The --root flag overrode the static dir which is wrong and
   broke a couple of use cases.  Now there is a dedicated field for in
   the "PodmanConfig" which also includes a containers.conf struct.

 - The defaults for static and volume dir and now being set correctly
   and adhere to --root.

 - The CONTAINERS_CONF_OVERRIDE env variable has not been passed to the
   cleanup process.  I believe that _all_ env variables should be passed
   to conmon to avoid such subtle bugs.

Overall I find that the code and logic is scattered and hard to
understand and follow.  I refrained from larger refactorings as I really
just want to get #19938 fixed and then go back to other priorities.

https://github.com/containers/common/pull/1659 broke three pkg/machine
tests.  Those have been commented out until getting fixed.

Fixes: #19938
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
This commit is contained in:
Valentin Rothberg
2023-09-21 11:28:22 +02:00
parent 919564e1ae
commit 6293ec2e2d
13 changed files with 51 additions and 42 deletions

View File

@@ -1216,6 +1216,29 @@ EOF
run_podman rm -f -t0 $ctr
}
@test "podman run - custom static_dir" {
# regression test for #19938 to make sure the cleanup process uses the same
# static_dir and writes the exit code. If not, podman-run will run into
# it's 20 sec timeout waiting for the exit code to be written.
skip_if_remote "CONTAINERS_CONF_OVERRIDE redirect does not work on remote"
containersconf=$PODMAN_TMPDIR/containers.conf
static_dir=$PODMAN_TMPDIR/static_dir
cat >$containersconf <<EOF
[engine]
static_dir="$static_dir"
EOF
ctr=$(random_string)
CONTAINERS_CONF_OVERRIDE=$containersconf PODMAN_TIMEOUT=20 run_podman run --name=$ctr $IMAGE true
CONTAINERS_CONF_OVERRIDE=$containersconf PODMAN_TIMEOUT=20 run_podman inspect --format "{{.ID}}" $ctr
cid="$output"
# Since the container has been run with custom static_dir (where the libpod
# DB is stored), the default podman should not see it.
run_podman 1 container exists $ctr
run_podman 1 container exists $cid
CONTAINERS_CONF_OVERRIDE=$containersconf run_podman rm -f -t0 $ctr
}
@test "podman --authfile=nonexistent-path" {
# List of commands to be tested. These all share a common authfile check.
#