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

Move CONTAINER_HOST and _CONNECTION to IsRemote Function #11990

Merged
merged 1 commit into from
Oct 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion cmd/podman/registry/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,17 @@ var remoteFromCLI = struct {
// Use in init() functions as an initialization check
func IsRemote() bool {
remoteFromCLI.sync.Do(func() {
remote := false
if _, ok := os.LookupEnv("CONTAINER_HOST"); ok {
remote = true
} else if _, ok := os.LookupEnv("CONTAINER_CONNECTION"); ok {
remote = true
}
fs := pflag.NewFlagSet("remote", pflag.ContinueOnError)
fs.ParseErrorsWhitelist.UnknownFlags = true
fs.Usage = func() {}
fs.SetInterspersed(false)
fs.BoolVarP(&remoteFromCLI.Value, "remote", "r", false, "")
fs.BoolVarP(&remoteFromCLI.Value, "remote", "r", remote, "")

// The shell completion logic will call a command called "__complete" or "__completeNoDesc"
// This command will always be the second argument
Expand Down
10 changes: 1 addition & 9 deletions cmd/podman/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,15 +314,7 @@ func rootFlags(cmd *cobra.Command, opts *entities.PodmanConfig) {
lFlags.StringVar(&opts.Identity, identityFlagName, ident, "path to SSH identity file, (CONTAINER_SSHKEY)")
_ = cmd.RegisterFlagCompletionFunc(identityFlagName, completion.AutocompleteDefault)

remote := false
if env, ok := os.LookupEnv("CONTAINER_HOST"); ok {
logrus.Infof("CONTAINER_HOST==%q, defaulting to '--remote=true'", env)
remote = true
} else if env, ok := os.LookupEnv("CONTAINER_CONNECTION"); ok {
logrus.Infof("CONTAINER_CONNECTION==%q, defaulting to '--remote=true'", env)
remote = true
}
lFlags.BoolVarP(&opts.Remote, "remote", "r", remote, "Access remote Podman service")
lFlags.BoolVarP(&opts.Remote, "remote", "r", registry.IsRemote(), "Access remote Podman service")
pFlags := cmd.PersistentFlags()
if registry.IsRemote() {
if err := lFlags.MarkHidden("remote"); err != nil {
Expand Down
15 changes: 13 additions & 2 deletions test/system/001-basic.bats
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,19 @@ function setup() {
skip "only applicable on a local run"
fi

CONTAINER_HOST=foobar run_podman --log-level=info --help
is "$output" ".*defaulting to '--remote=true'" "CONTAINER_HOST sets --remote true"
CONTAINER_HOST=foobar run_podman --help
# Should not have --remote flag
echo $output | grep -v -qw -- "--remote"
rhatdan marked this conversation as resolved.
Show resolved Hide resolved
if [ $? -ne 0 ]; then
die "Should not have --remote flag"
fi

CONTAINER_CONNECTION=foobar run_podman --help
# Should not have --remote flag
echo $output | grep -v -qw -- "--remote"
rhatdan marked this conversation as resolved.
Show resolved Hide resolved
if [ $? -ne 0 ]; then
die "Should not have --remote flag"
fi
}

# Check that just calling "podman-remote" prints the usage message even
Expand Down