Skip to content

Commit

Permalink
Merge pull request #17303 from arixmkii/config-pipe
Browse files Browse the repository at this point in the history
Expose Podman named pipe in Inspect output
  • Loading branch information
openshift-merge-robot authored Feb 3, 2023
2 parents 5925baa + a909e2f commit e0cd18f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 27 deletions.
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

0 comments on commit e0cd18f

Please sign in to comment.