Skip to content

Commit

Permalink
Merge pull request #20333 from baude/showinfo
Browse files Browse the repository at this point in the history
Show client info even if remote connection fails
  • Loading branch information
openshift-ci[bot] authored Oct 13, 2023
2 parents aa0e96e + 29f5c56 commit b5fec41
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 1 deletion.
25 changes: 25 additions & 0 deletions cmd/podman/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package main

import "github.com/containers/podman/v4/libpod/define"

type clientInfo struct {
OSArch string `json:"OS"`
Provider string `json:"provider"`
Version string `json:"version"`
}

func getClientInfo() (*clientInfo, error) {
p, err := getProvider()
if err != nil {
return nil, err
}
vinfo, err := define.GetVersion()
if err != nil {
return nil, err
}
return &clientInfo{
OSArch: vinfo.OsArch,
Provider: p,
Version: vinfo.Version,
}, nil
}
16 changes: 16 additions & 0 deletions cmd/podman/client_supported.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//go:build amd64 || arm64
// +build amd64 arm64

package main

import (
"github.com/containers/podman/v4/pkg/machine/provider"
)

func getProvider() (string, error) {
p, err := provider.Get()
if err != nil {
return "", err
}
return p.VMType().String(), nil
}
7 changes: 7 additions & 0 deletions cmd/podman/client_unsupported.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//go:build !amd64 && !arm64

package main

func getProvider() (string, error) {
return "", nil
}
10 changes: 10 additions & 0 deletions cmd/podman/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"sigs.k8s.io/yaml"
)

// HelpTemplate is the help template for podman commands
Expand Down Expand Up @@ -296,6 +297,15 @@ func persistentPreRunE(cmd *cobra.Command, args []string) error {

// Prep the engines
if _, err := registry.NewImageEngine(cmd, args); err != nil {
// Note: this is gross, but it is the hand we are dealt
if registry.IsRemote() && errors.As(err, &bindings.ConnectError{}) && cmd.Name() == "info" && cmd.Parent() == cmd.Root() {
clientDesc, err := getClientInfo()
// we eat the error here. if this fails, they just don't any client info
if err == nil {
b, _ := yaml.Marshal(clientDesc)
fmt.Println(string(b))
}
}
return err
}
if _, err := registry.NewContainerEngine(cmd, args); err != nil {
Expand Down
13 changes: 13 additions & 0 deletions test/e2e/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os/exec"
"os/user"
"path/filepath"
"runtime"
"strconv"

. "github.com/containers/podman/v4/test/utils"
Expand Down Expand Up @@ -240,4 +241,16 @@ var _ = Describe("Podman Info", func() {
// Don't check absolute numbers because there is a decent chance of contamination, containers that were never removed properly, etc.
Expect(free1).To(Equal(free2 + 1))
})

It("Podman info: check for client information when no system service", func() {
// the output for this information is not really something we can marshall
want := runtime.GOOS + "/" + runtime.GOARCH
podmanTest.StopRemoteService()
SkipIfNotRemote("Specifically testing a failed remote connection")
info := podmanTest.Podman([]string{"info"})
info.WaitWithDefaultTimeout()
Expect(info.OutputToString()).To(ContainSubstring(want))
Expect(info).ToNot(ExitCleanly())
podmanTest.StartRemoteService() // Start service again so teardown runs clean
})
})
2 changes: 1 addition & 1 deletion test/system/272-system-connection.bats
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ $c2[ ]\+tcp://localhost:54321[ ]\+true" \
# when invoking podman.
_run_podman_remote 125 info
is "$output" \
"Cannot connect to Podman. Please verify.*dial tcp.*connection refused" \
"OS: .*provider:.*Cannot connect to Podman. Please verify.*dial tcp.*connection refused" \
"podman info, without active service"

# Start service. Now podman info should work fine. The %%-remote*
Expand Down

0 comments on commit b5fec41

Please sign in to comment.