Skip to content

Commit

Permalink
Merge pull request #21982 from Luap99/machine-compose
Browse files Browse the repository at this point in the history
podman compose: enable machine socket connection
  • Loading branch information
openshift-merge-bot[bot] authored Mar 7, 2024
2 parents 9a888de + 5d3a19f commit 2e52b4f
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions cmd/podman/compose_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
package main

import (
"errors"
"fmt"
"net/url"
"strconv"
"strings"

"github.com/containers/podman/v5/pkg/machine/define"
"github.com/containers/podman/v5/pkg/machine/env"
Expand Down Expand Up @@ -35,33 +37,34 @@ func getMachineConn(connectionURI string, parsedConnection *url.URL) (string, er
if err != nil {
return "", fmt.Errorf("parsing connection port: %w", err)
}
for _, item := range machineList {
if connectionPort != item.SSH.Port {
for _, mc := range machineList {
if connectionPort != mc.SSH.Port {
continue
}

state, err := machineProvider.State(item, false)
state, err := machineProvider.State(mc, false)
if err != nil {
return "", err
}

if state != define.Running {
return "", fmt.Errorf("machine %s is not running but in state %s", item.Name, state)
return "", fmt.Errorf("machine %s is not running but in state %s", mc.Name, state)
}

// TODO This needs to be wired back in when all providers are complete
// TODO Need someoone to plumb in the connection information below
// if machineProvider.VMType() == define.WSLVirt || machineProvider.VMType() == define.HyperVVirt {
// if info.ConnectionInfo.PodmanPipe == nil {
// return "", errors.New("pipe of machine is not set")
// }
// return strings.Replace(info.ConnectionInfo.PodmanPipe.Path, `\\.\pipe\`, "npipe:////./pipe/", 1), nil
// }
// if info.ConnectionInfo.PodmanSocket == nil {
// return "", errors.New("socket of machine is not set")
// }
// return "unix://" + info.ConnectionInfo.PodmanSocket.Path, nil
return "", nil
podmanSocket, podmanPipe, err := mc.ConnectionInfo(machineProvider.VMType())
if err != nil {
return "", err
}
if machineProvider.VMType() == define.WSLVirt || machineProvider.VMType() == define.HyperVVirt {
if podmanPipe == nil {
return "", errors.New("pipe of machine is not set")
}
return strings.Replace(podmanPipe.Path, `\\.\pipe\`, "npipe:////./pipe/", 1), nil
}
if podmanSocket == nil {
return "", errors.New("socket of machine is not set")
}
return "unix://" + podmanSocket.Path, nil
}
return "", fmt.Errorf("could not find a matching machine for connection %q", connectionURI)
}

1 comment on commit 2e52b4f

@packit-as-a-service
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

podman-next COPR build failed. @containers/packit-build please check.

Please sign in to comment.