remote: fix incorrect CONTAINER_CONNECTION parsing

When a user specifies a invalid connection in CONTAINER_CONNECTION then
podman should return a proper error saying so. Currently it ignored the
error and in rootFlags() just exited early with defining any flags. This
caused a panic then when trying to use the flags later.

In order to address this first store the connection error in the
PodmanConfig struct and not abort right away during flag setup. This is
important as the user might have specified a flag with a valid remote
connection. As such we check all flags and only when none were given we
return the connection error.

Also while at it I noticed that the default connection reported via
podman --help was wrong as it only used the old containers.conf field
for it and did not consider the podman-connections.json default.

New regression tests have been added to make sure it behaves correctly.

This fixes the problem reported in the PR #22997.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
Paul Holzinger
2024-06-21 13:34:59 +02:00
parent 79f0f7707a
commit 4b3890ccac
3 changed files with 30 additions and 9 deletions

View File

@@ -48,6 +48,7 @@ type PodmanConfig struct {
Trace bool // Hidden: Trace execution
URI string // URI to RESTful API Service
FarmNodeName string // Name of farm node
ConnectionError error // Error when looking up the connection in setupRemoteConnection()
Runroot string
ImageStore string