From a909e2f2d53fa5adb1dfe33fb348702103084688 Mon Sep 17 00:00:00 2001 From: Arthur Sengileyev Date: Tue, 31 Jan 2023 00:11:04 +0200 Subject: [PATCH] Expose Podman named pipe in Inspect output Signed-off-by: Arthur Sengileyev --- pkg/machine/config.go | 2 ++ pkg/machine/machine_windows.go | 23 +++++++++++++++++++++ pkg/machine/wsl/machine.go | 37 +++++++++------------------------- 3 files changed, 35 insertions(+), 27 deletions(-) diff --git a/pkg/machine/config.go b/pkg/machine/config.go index 09c7dd73c4..3045fdd625 100644 --- a/pkg/machine/config.go +++ b/pkg/machine/config.go @@ -373,4 +373,6 @@ type SSHConfig struct { type ConnectionConfig struct { // PodmanSocket is the exported podman service socket PodmanSocket *VMFile `json:"PodmanSocket"` + // PodmanPipe is the exported podman service named pipe (Windows hosts only) + PodmanPipe *VMFile `json:"PodmanPipe"` } diff --git a/pkg/machine/machine_windows.go b/pkg/machine/machine_windows.go index c414986cf5..2372644483 100644 --- a/pkg/machine/machine_windows.go +++ b/pkg/machine/machine_windows.go @@ -4,7 +4,9 @@ package machine import ( + "os" "syscall" + "time" ) func GetProcessState(pid int) (active bool, exitCode int) { @@ -18,3 +20,24 @@ func GetProcessState(pid int) (active bool, exitCode int) { syscall.GetExitCodeProcess(handle, &code) return code == 259, int(code) } + +func PipeNameAvailable(pipeName string) bool { + _, err := os.Stat(`\\.\pipe\` + pipeName) + return os.IsNotExist(err) +} + +func WaitPipeExists(pipeName string, retries int, checkFailure func() error) error { + var err error + for i := 0; i < retries; i++ { + _, err = os.Stat(`\\.\pipe\` + pipeName) + if err == nil { + break + } + if fail := checkFailure(); fail != nil { + return fail + } + time.Sleep(250 * time.Millisecond) + } + + return err +} diff --git a/pkg/machine/wsl/machine.go b/pkg/machine/wsl/machine.go index cf24443f7c..9eb9fd740b 100644 --- a/pkg/machine/wsl/machine.go +++ b/pkg/machine/wsl/machine.go @@ -1053,12 +1053,12 @@ func (v *MachineVM) Start(name string, opts machine.StartOptions) error { func launchWinProxy(v *MachineVM) (bool, string, error) { machinePipe := toDist(v.Name) - if !pipeAvailable(machinePipe) { + if !machine.PipeNameAvailable(machinePipe) { return false, "", fmt.Errorf("could not start api proxy since expected pipe is not available: %s", machinePipe) } globalName := false - if pipeAvailable(globalPipe) { + if machine.PipeNameAvailable(globalPipe) { globalName = true } @@ -1099,7 +1099,7 @@ func launchWinProxy(v *MachineVM) (bool, string, error) { return globalName, "", err } - return globalName, pipePrefix + waitPipe, waitPipeExists(waitPipe, 80, func() error { + return globalName, pipePrefix + waitPipe, machine.WaitPipeExists(waitPipe, 80, func() error { active, exitCode := machine.GetProcessState(cmd.Process.Pid) if !active { return fmt.Errorf("win-sshproxy.exe failed to start, exit code: %d (see windows event logs)", exitCode) @@ -1122,27 +1122,6 @@ func getWinProxyStateDir(v *MachineVM) (string, error) { return stateDir, nil } -func pipeAvailable(pipeName string) bool { - _, err := os.Stat(`\\.\pipe\` + pipeName) - return os.IsNotExist(err) -} - -func waitPipeExists(pipeName string, retries int, checkFailure func() error) error { - var err error - for i := 0; i < retries; i++ { - _, err = os.Stat(`\\.\pipe\` + pipeName) - if err == nil { - break - } - if fail := checkFailure(); fail != nil { - return fail - } - time.Sleep(250 * time.Millisecond) - } - - return err -} - func IsWSLInstalled() bool { cmd := SilentExecCmd("wsl", "--status") out, err := cmd.StdoutPipe() @@ -1611,11 +1590,15 @@ func (v *MachineVM) Inspect() (*machine.InspectInfo, error) { return nil, err } - created, lastUp, _ := v.updateTimeStamps(state == machine.Running) + connInfo := new(machine.ConnectionConfig) + machinePipe := toDist(v.Name) + connInfo.PodmanPipe = &machine.VMFile{Path: `\\.\pipe\` + machinePipe} + created, lastUp, _ := v.updateTimeStamps(state == machine.Running) return &machine.InspectInfo{ - ConfigPath: machine.VMFile{Path: v.ConfigPath}, - Created: created, + ConfigPath: machine.VMFile{Path: v.ConfigPath}, + ConnectionInfo: *connInfo, + Created: created, Image: machine.ImageConfig{ ImagePath: machine.VMFile{Path: v.ImagePath}, ImageStream: v.ImageStream,