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

Expose Podman named pipe in Inspect output #17303

Merged
merged 1 commit into from
Feb 3, 2023
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
2 changes: 2 additions & 0 deletions pkg/machine/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
23 changes: 23 additions & 0 deletions pkg/machine/machine_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
package machine

import (
"os"
"syscall"
"time"
)

func GetProcessState(pid int) (active bool, exitCode int) {
Expand All @@ -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
}
37 changes: 10 additions & 27 deletions pkg/machine/wsl/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -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,
Expand Down