expose podman.sock in machine inspect

For consumers of the podman.sock who want a predictable way to find the
podman sock, we now include it under 'ConnectionConfig' in podman
machine inspect.

Fixes: #14231

Signed-off-by: Brent Baude <bbaude@redhat.com>
This commit is contained in:
Brent Baude
2022-06-01 10:45:30 -05:00
parent 2039445763
commit 8291b51ceb
3 changed files with 34 additions and 19 deletions

View File

@ -138,14 +138,15 @@ type DistributionDownload interface {
Get() *Download Get() *Download
} }
type InspectInfo struct { type InspectInfo struct {
ConfigPath VMFile ConfigPath VMFile
Created time.Time ConnectionInfo ConnectionConfig
Image ImageConfig Created time.Time
LastUp time.Time Image ImageConfig
Name string LastUp time.Time
Resources ResourceConfig Name string
SSHConfig SSHConfig Resources ResourceConfig
State Status SSHConfig SSHConfig
State Status
} }
func (rc RemoteConnectionType) MakeSSHURL(host, path, port, userName string) url.URL { func (rc RemoteConnectionType) MakeSSHURL(host, path, port, userName string) url.URL {
@ -286,11 +287,11 @@ func NewMachineFile(path string, symlink *string) (*VMFile, error) {
// makeSymlink for macOS creates a symlink in $HOME/.podman/ // makeSymlink for macOS creates a symlink in $HOME/.podman/
// for a machinefile like a socket // for a machinefile like a socket
func (m *VMFile) makeSymlink(symlink *string) error { func (m *VMFile) makeSymlink(symlink *string) error {
homedir, err := os.UserHomeDir() homeDir, err := os.UserHomeDir()
if err != nil { if err != nil {
return err return err
} }
sl := filepath.Join(homedir, ".podman", *symlink) sl := filepath.Join(homeDir, ".podman", *symlink)
// make the symlink dir and throw away if it already exists // make the symlink dir and throw away if it already exists
if err := os.MkdirAll(filepath.Dir(sl), 0700); err != nil && !errors2.Is(err, os.ErrNotExist) { if err := os.MkdirAll(filepath.Dir(sl), 0700); err != nil && !errors2.Is(err, os.ErrNotExist) {
return err return err
@ -335,3 +336,9 @@ type SSHConfig struct {
// RemoteUsername of the vm user // RemoteUsername of the vm user
RemoteUsername string RemoteUsername string
} }
// ConnectionConfig contains connections like sockets, etc.
type ConnectionConfig struct {
// PodmanSocket is the exported podman service socket
PodmanSocket *VMFile `json:"PodmanSocket"`
}

View File

@ -2,6 +2,7 @@ package e2e
import ( import (
"encoding/json" "encoding/json"
"strings"
"github.com/containers/podman/v4/pkg/machine" "github.com/containers/podman/v4/pkg/machine"
"github.com/containers/podman/v4/pkg/machine/qemu" "github.com/containers/podman/v4/pkg/machine/qemu"
@ -86,6 +87,7 @@ var _ = Describe("podman machine stop", func() {
var inspectInfo []machine.InspectInfo var inspectInfo []machine.InspectInfo
err = jsoniter.Unmarshal(inspectSession.Bytes(), &inspectInfo) err = jsoniter.Unmarshal(inspectSession.Bytes(), &inspectInfo)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
Expect(strings.HasSuffix(inspectInfo[0].ConnectionInfo.PodmanSocket.GetPath(), "podman.sock"))
inspect := new(inspectMachine) inspect := new(inspectMachine)
inspect = inspect.withFormat("{{.Name}}") inspect = inspect.withFormat("{{.Name}}")

View File

@ -1471,16 +1471,22 @@ func (v *MachineVM) Inspect() (*machine.InspectInfo, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
connInfo := new(machine.ConnectionConfig)
podmanSocket, err := v.forwardSocketPath()
if err != nil {
return nil, err
}
connInfo.PodmanSocket = podmanSocket
return &machine.InspectInfo{ return &machine.InspectInfo{
ConfigPath: v.ConfigPath, ConfigPath: v.ConfigPath,
Created: v.Created, ConnectionInfo: *connInfo,
Image: v.ImageConfig, Created: v.Created,
LastUp: v.LastUp, Image: v.ImageConfig,
Name: v.Name, LastUp: v.LastUp,
Resources: v.ResourceConfig, Name: v.Name,
SSHConfig: v.SSHConfig, Resources: v.ResourceConfig,
State: state, SSHConfig: v.SSHConfig,
State: state,
}, nil }, nil
} }