mirror of
https://github.com/containers/podman.git
synced 2025-05-20 08:36:23 +08:00
Add support for --connection
* override --url and/or --identity fields from containers.conf * --connection flag has higher precedence than ActiveService from containers.conf. Which is set via podman system connection default * Add newline to error message printed on stderr * Added --connection to bash completion and documentation * Updated bindings to query server in case of no path or / Closes #jira-991 Fixes #7276 Signed-off-by: Daniel J Walsh <dwalsh@redhat.com> Signed-off-by: Jhon Honce <jhonce@redhat.com> Squashed commits to work around CI issue
This commit is contained in:

committed by
Jhon Honce

parent
dd4e0da424
commit
eb9e8fc558
@ -32,7 +32,7 @@ func setUMask() {
|
|||||||
|
|
||||||
func earlyInitHook() {
|
func earlyInitHook() {
|
||||||
if err := setRLimits(); err != nil {
|
if err := setRLimits(); err != nil {
|
||||||
fmt.Fprint(os.Stderr, "Failed to set rlimits: "+err.Error())
|
fmt.Fprintf(os.Stderr, "Failed to set rlimits: %s\n", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
setUMask()
|
setUMask()
|
||||||
|
@ -111,6 +111,30 @@ func persistentPreRunE(cmd *cobra.Command, args []string) error {
|
|||||||
|
|
||||||
cfg := registry.PodmanConfig()
|
cfg := registry.PodmanConfig()
|
||||||
|
|
||||||
|
// --connection is not as "special" as --remote so we can wait and process it here
|
||||||
|
var connErr error
|
||||||
|
conn := cmd.Root().LocalFlags().Lookup("connection")
|
||||||
|
if conn != nil && conn.Changed {
|
||||||
|
cfg.Engine.ActiveService = conn.Value.String()
|
||||||
|
|
||||||
|
var err error
|
||||||
|
cfg.URI, cfg.Identity, err = cfg.ActiveDestination()
|
||||||
|
if err != nil {
|
||||||
|
connErr = errors.Wrap(err, "failed to resolve active destination")
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := cmd.Root().LocalFlags().Set("url", cfg.URI); err != nil {
|
||||||
|
connErr = errors.Wrap(err, "failed to override --url flag")
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := cmd.Root().LocalFlags().Set("identity", cfg.Identity); err != nil {
|
||||||
|
connErr = errors.Wrap(err, "failed to override --identity flag")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if connErr != nil {
|
||||||
|
return connErr
|
||||||
|
}
|
||||||
|
|
||||||
// Prep the engines
|
// Prep the engines
|
||||||
if _, err := registry.NewImageEngine(cmd, args); err != nil {
|
if _, err := registry.NewImageEngine(cmd, args); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -226,10 +250,11 @@ func loggingHook() {
|
|||||||
|
|
||||||
func rootFlags(cmd *cobra.Command, opts *entities.PodmanConfig) {
|
func rootFlags(cmd *cobra.Command, opts *entities.PodmanConfig) {
|
||||||
cfg := opts.Config
|
cfg := opts.Config
|
||||||
uri, ident := resolveDestination()
|
srv, uri, ident := resolveDestination()
|
||||||
|
|
||||||
lFlags := cmd.Flags()
|
lFlags := cmd.Flags()
|
||||||
lFlags.BoolVarP(&opts.Remote, "remote", "r", false, "Access remote Podman service (default false)")
|
lFlags.BoolVarP(&opts.Remote, "remote", "r", false, "Access remote Podman service (default false)")
|
||||||
|
lFlags.StringVarP(&opts.Engine.ActiveService, "connection", "c", srv, "Connection to use for remote Podman service")
|
||||||
lFlags.StringVar(&opts.URI, "url", uri, "URL to access Podman service (CONTAINER_HOST)")
|
lFlags.StringVar(&opts.URI, "url", uri, "URL to access Podman service (CONTAINER_HOST)")
|
||||||
lFlags.StringVar(&opts.Identity, "identity", ident, "path to SSH identity file, (CONTAINER_SSHKEY)")
|
lFlags.StringVar(&opts.Identity, "identity", ident, "path to SSH identity file, (CONTAINER_SSHKEY)")
|
||||||
|
|
||||||
@ -279,24 +304,24 @@ func rootFlags(cmd *cobra.Command, opts *entities.PodmanConfig) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func resolveDestination() (string, string) {
|
func resolveDestination() (string, string, string) {
|
||||||
if uri, found := os.LookupEnv("CONTAINER_HOST"); found {
|
if uri, found := os.LookupEnv("CONTAINER_HOST"); found {
|
||||||
var ident string
|
var ident string
|
||||||
if v, found := os.LookupEnv("CONTAINER_SSHKEY"); found {
|
if v, found := os.LookupEnv("CONTAINER_SSHKEY"); found {
|
||||||
ident = v
|
ident = v
|
||||||
}
|
}
|
||||||
return uri, ident
|
return "", uri, ident
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg, err := config.ReadCustomConfig()
|
cfg, err := config.ReadCustomConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Warning(errors.Wrap(err, "unable to read local containers.conf"))
|
logrus.Warning(errors.Wrap(err, "unable to read local containers.conf"))
|
||||||
return registry.DefaultAPIAddress(), ""
|
return "", registry.DefaultAPIAddress(), ""
|
||||||
}
|
}
|
||||||
|
|
||||||
uri, ident, err := cfg.ActiveDestination()
|
uri, ident, err := cfg.ActiveDestination()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return registry.DefaultAPIAddress(), ""
|
return "", registry.DefaultAPIAddress(), ""
|
||||||
}
|
}
|
||||||
return uri, ident
|
return cfg.Engine.ActiveService, uri, ident
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ func add(cmd *cobra.Command, args []string) error {
|
|||||||
uri.Host = net.JoinHostPort(uri.Hostname(), cmd.Flag("port").DefValue)
|
uri.Host = net.JoinHostPort(uri.Hostname(), cmd.Flag("port").DefValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
if uri.Path == "" {
|
if uri.Path == "" || uri.Path == "/" {
|
||||||
if uri.Path, err = getUDS(cmd, uri); err != nil {
|
if uri.Path, err = getUDS(cmd, uri); err != nil {
|
||||||
return errors.Wrapf(err, "failed to connect to %q", uri.String())
|
return errors.Wrapf(err, "failed to connect to %q", uri.String())
|
||||||
}
|
}
|
||||||
|
@ -3602,22 +3602,32 @@ _podman_volume() {
|
|||||||
|
|
||||||
_podman_podman() {
|
_podman_podman() {
|
||||||
local options_with_args="
|
local options_with_args="
|
||||||
--config -c
|
--cni-config-dir
|
||||||
|
--conmon
|
||||||
|
--connection -c
|
||||||
|
--events-backend
|
||||||
|
--hooks-dir
|
||||||
|
--identity
|
||||||
|
--log-level
|
||||||
|
--namespace
|
||||||
|
--network-cmd-path
|
||||||
--root
|
--root
|
||||||
--runroot
|
--runroot
|
||||||
--storage-driver
|
--storage-driver
|
||||||
--storage-opt
|
--storage-opt
|
||||||
--log-level
|
--tmpdir
|
||||||
--namespace
|
--runtime
|
||||||
"
|
--url
|
||||||
|
"
|
||||||
local boolean_options="
|
local boolean_options="
|
||||||
--help
|
--help
|
||||||
-h
|
|
||||||
--version
|
|
||||||
-v
|
|
||||||
--syslog
|
--syslog
|
||||||
|
--version
|
||||||
|
-h
|
||||||
|
-r, --remote
|
||||||
|
-v
|
||||||
"
|
"
|
||||||
commands="
|
commands="
|
||||||
attach
|
attach
|
||||||
auto-update
|
auto-update
|
||||||
build
|
build
|
||||||
|
@ -23,7 +23,7 @@ Podman-remote provides a local client interacting with a Podman backend node thr
|
|||||||
|
|
||||||
## GLOBAL OPTIONS
|
## GLOBAL OPTIONS
|
||||||
|
|
||||||
**--connection**=*name*
|
**--connection**=*name*, **-c**
|
||||||
|
|
||||||
Remote connection name
|
Remote connection name
|
||||||
|
|
||||||
|
@ -31,6 +31,9 @@ Note: CGroup manager is not supported in rootless mode when using CGroups Versio
|
|||||||
**--cni-config-dir**
|
**--cni-config-dir**
|
||||||
Path of the configuration directory for CNI networks. (Default: `/etc/cni/net.d`)
|
Path of the configuration directory for CNI networks. (Default: `/etc/cni/net.d`)
|
||||||
|
|
||||||
|
**--connection**, **-c**
|
||||||
|
Connection to use for remote podman (Default connection is configured in `containers.conf`)
|
||||||
|
|
||||||
**--conmon**
|
**--conmon**
|
||||||
Path of the conmon binary (Default path is configured in `containers.conf`)
|
Path of the conmon binary (Default path is configured in `containers.conf`)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user