summaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2021-03-22 13:29:25 -0500
committerbaude <bbaude@redhat.com>2021-03-25 11:02:33 -0500
commit4ab8a6f67eb9de0de40d478cb0cbec05b1b725c0 (patch)
tree00743bf608cc5700fe8a7fca1bb3b0f3a4457b7d /pkg
parente7661137373b5f87bf6ec45e32326821b172ce7b (diff)
downloadpodman-4ab8a6f67eb9de0de40d478cb0cbec05b1b725c0.tar.gz
podman-4ab8a6f67eb9de0de40d478cb0cbec05b1b725c0.tar.bz2
podman-4ab8a6f67eb9de0de40d478cb0cbec05b1b725c0.zip
Improvements for machine
clean up ci failures and add appropriate arch,os exclusion tags Signed-off-by: baude <bbaude@redhat.com>
Diffstat (limited to 'pkg')
-rw-r--r--pkg/bindings/connection.go12
-rw-r--r--pkg/machine/config.go37
-rw-r--r--pkg/machine/fcos.go4
-rw-r--r--pkg/machine/qemu/machine.go20
-rw-r--r--pkg/machine/qemu/options_darwin.go15
-rw-r--r--pkg/machine/qemu/options_darwin_amd64.go18
-rw-r--r--pkg/machine/qemu/options_darwin_arm64.go (renamed from pkg/machine/qemu/options_arm64.go)4
-rw-r--r--pkg/machine/qemu/options_linux.go7
-rw-r--r--pkg/machine/qemu/options_linux_amd64.go (renamed from pkg/machine/qemu/options_amd64.go)8
-rw-r--r--pkg/specgen/generate/ports.go6
-rw-r--r--pkg/specgen/ports.go26
11 files changed, 71 insertions, 86 deletions
diff --git a/pkg/bindings/connection.go b/pkg/bindings/connection.go
index 148b592e9..21a8e7a8b 100644
--- a/pkg/bindings/connection.go
+++ b/pkg/bindings/connection.go
@@ -22,21 +22,11 @@ import (
"golang.org/x/crypto/ssh/agent"
)
-/*
- WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
- WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
-
- DO NOT MERGE WITHOUT REVERTING THE HACK BELOW
-
- WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
- WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
-*/
var (
BasePath = &url.URL{
Scheme: "http",
Host: "d",
- //Path: "/v" + version.APIVersion[version.Libpod][version.CurrentAPI].String() + "/libpod",
- Path: "/v3.0.0/libpod",
+ Path: "/v" + version.APIVersion[version.Libpod][version.CurrentAPI].String() + "/libpod",
}
)
diff --git a/pkg/machine/config.go b/pkg/machine/config.go
index 2a70b8ff7..242401ab4 100644
--- a/pkg/machine/config.go
+++ b/pkg/machine/config.go
@@ -50,7 +50,7 @@ type StartOptions struct{}
type StopOptions struct{}
-type DestroyOptions struct {
+type RemoveOptions struct {
Force bool
SaveKeys bool
SaveImage bool
@@ -59,7 +59,7 @@ type DestroyOptions struct {
type VM interface {
Create(opts CreateOptions) error
- Destroy(name string, opts DestroyOptions) (string, func() error, error)
+ Remove(name string, opts RemoveOptions) (string, func() error, error)
SSH(name string, opts SSHOptions) error
Start(name string, opts StartOptions) error
Stop(name string, opts StopOptions) error
@@ -70,33 +70,18 @@ type DistributionDownload interface {
Get() *Download
}
-// TODO is this even needed?
-type TestVM struct{}
-
-func (vm *TestVM) Create(opts CreateOptions) error {
- return nil
-}
-
-func (vm *TestVM) Start(name string, opts StartOptions) error {
- return nil
-}
-func (vm *TestVM) Stop(name string, opts StopOptions) error {
- return nil
-}
-
func (rc RemoteConnectionType) MakeSSHURL(host, path, port, userName string) url.URL {
userInfo := url.User(userName)
uri := url.URL{
- Scheme: "ssh",
- Opaque: "",
- User: userInfo,
- Host: host,
- Path: path,
- RawPath: "",
- ForceQuery: false,
- RawQuery: "",
- Fragment: "",
- RawFragment: "",
+ Scheme: "ssh",
+ Opaque: "",
+ User: userInfo,
+ Host: host,
+ Path: path,
+ RawPath: "",
+ ForceQuery: false,
+ RawQuery: "",
+ Fragment: "",
}
if len(port) > 0 {
uri.Host = net.JoinHostPort(uri.Hostname(), port)
diff --git a/pkg/machine/fcos.go b/pkg/machine/fcos.go
index 8bbad458f..0c6a2485e 100644
--- a/pkg/machine/fcos.go
+++ b/pkg/machine/fcos.go
@@ -11,10 +11,8 @@ import (
"strings"
"github.com/containers/storage/pkg/archive"
-
- "github.com/sirupsen/logrus"
-
digest "github.com/opencontainers/go-digest"
+ "github.com/sirupsen/logrus"
)
// These should eventually be moved into machine/qemu as
diff --git a/pkg/machine/qemu/machine.go b/pkg/machine/qemu/machine.go
index 30d96ce08..504b64bd5 100644
--- a/pkg/machine/qemu/machine.go
+++ b/pkg/machine/qemu/machine.go
@@ -10,8 +10,9 @@ import (
"strconv"
"time"
+ "github.com/containers/podman/v3/utils"
+
"github.com/containers/podman/v3/pkg/machine"
- "github.com/containers/podman/v3/pkg/specgen"
"github.com/containers/storage/pkg/homedir"
"github.com/digitalocean/go-qemu/qmp"
"github.com/pkg/errors"
@@ -56,7 +57,7 @@ func NewMachine(opts machine.CreateOptions) (machine.VM, error) {
}
// Add a random port for ssh
- port, err := specgen.GetRandomPort()
+ port, err := utils.GetRandomPort()
if err != nil {
return nil, err
}
@@ -170,7 +171,7 @@ func (v *MachineVM) Start(name string, _ machine.StartOptions) error {
attr := new(os.ProcAttr)
files := []*os.File{os.Stdin, os.Stdout, os.Stderr}
attr.Files = files
- fmt.Print(v.CmdLine)
+ logrus.Debug(v.CmdLine)
_, err = os.StartProcess(v.CmdLine[0], v.CmdLine, attr)
return err
}
@@ -211,22 +212,29 @@ func (v *MachineVM) Stop(name string, _ machine.StopOptions) error {
// NewQMPMonitor creates the monitor subsection of our vm
func NewQMPMonitor(network, name string, timeout time.Duration) (Monitor, error) {
- rtDir, err := getDataDir()
+ rtDir, err := getSocketDir()
if err != nil {
return Monitor{}, err
}
+ rtDir = filepath.Join(rtDir, "podman")
+ if _, err := os.Stat(filepath.Join(rtDir)); os.IsNotExist(err) {
+ // TODO 0644 is fine on linux but macos is weird
+ if err := os.MkdirAll(rtDir, 0755); err != nil {
+ return Monitor{}, err
+ }
+ }
if timeout == 0 {
timeout = defaultQMPTimeout
}
monitor := Monitor{
Network: network,
- Address: filepath.Join(rtDir, "podman", "qmp_"+name+".sock"),
+ Address: filepath.Join(rtDir, "qmp_"+name+".sock"),
Timeout: timeout,
}
return monitor, nil
}
-func (v *MachineVM) Destroy(name string, opts machine.DestroyOptions) (string, func() error, error) {
+func (v *MachineVM) Remove(name string, opts machine.RemoveOptions) (string, func() error, error) {
var (
files []string
)
diff --git a/pkg/machine/qemu/options_darwin.go b/pkg/machine/qemu/options_darwin.go
new file mode 100644
index 000000000..46ccf24cb
--- /dev/null
+++ b/pkg/machine/qemu/options_darwin.go
@@ -0,0 +1,15 @@
+package qemu
+
+import (
+ "os"
+
+ "github.com/pkg/errors"
+)
+
+func getSocketDir() (string, error) {
+ tmpDir, ok := os.LookupEnv("TMPDIR")
+ if !ok {
+ return "", errors.New("unable to resolve TMPDIR")
+ }
+ return tmpDir, nil
+}
diff --git a/pkg/machine/qemu/options_darwin_amd64.go b/pkg/machine/qemu/options_darwin_amd64.go
new file mode 100644
index 000000000..69f7982b2
--- /dev/null
+++ b/pkg/machine/qemu/options_darwin_amd64.go
@@ -0,0 +1,18 @@
+package qemu
+
+var (
+ QemuCommand = "qemu-system-x86_64"
+)
+
+func (v *MachineVM) addArchOptions() []string {
+ opts := []string{"-cpu", "host"}
+ return opts
+}
+
+func (v *MachineVM) prepare() error {
+ return nil
+}
+
+func (v *MachineVM) archRemovalFiles() []string {
+ return []string{}
+}
diff --git a/pkg/machine/qemu/options_arm64.go b/pkg/machine/qemu/options_darwin_arm64.go
index c5b0ea16b..7513b3048 100644
--- a/pkg/machine/qemu/options_arm64.go
+++ b/pkg/machine/qemu/options_darwin_arm64.go
@@ -31,10 +31,6 @@ func (v *MachineVM) archRemovalFiles() []string {
return []string{ovmDir}
}
-func getDataDir() (string, error) {
- return "/tmp", nil
-}
-
func getOvmfDir(imagePath, vmName string) string {
return filepath.Join(filepath.Dir(imagePath), vmName+"_ovmf_vars.fd")
}
diff --git a/pkg/machine/qemu/options_linux.go b/pkg/machine/qemu/options_linux.go
new file mode 100644
index 000000000..0a2e40d8f
--- /dev/null
+++ b/pkg/machine/qemu/options_linux.go
@@ -0,0 +1,7 @@
+package qemu
+
+import "github.com/containers/podman/v3/pkg/util"
+
+func getSocketDir() (string, error) {
+ return util.GetRuntimeDir()
+}
diff --git a/pkg/machine/qemu/options_amd64.go b/pkg/machine/qemu/options_linux_amd64.go
index 85a2c4b3e..cc0a4bab2 100644
--- a/pkg/machine/qemu/options_amd64.go
+++ b/pkg/machine/qemu/options_linux_amd64.go
@@ -1,9 +1,5 @@
package qemu
-import (
- "github.com/containers/podman/v3/pkg/util"
-)
-
var (
QemuCommand = "qemu-kvm"
)
@@ -20,7 +16,3 @@ func (v *MachineVM) prepare() error {
func (v *MachineVM) archRemovalFiles() []string {
return []string{}
}
-
-func getDataDir() (string, error) {
- return util.GetRuntimeDir()
-}
diff --git a/pkg/specgen/generate/ports.go b/pkg/specgen/generate/ports.go
index d5d779c8f..678e36a70 100644
--- a/pkg/specgen/generate/ports.go
+++ b/pkg/specgen/generate/ports.go
@@ -6,6 +6,8 @@ import (
"strconv"
"strings"
+ "github.com/containers/podman/v3/utils"
+
"github.com/containers/podman/v3/libpod/image"
"github.com/containers/podman/v3/pkg/specgen"
"github.com/cri-o/ocicni/pkg/ocicni"
@@ -218,7 +220,7 @@ func parsePortMapping(portMappings []specgen.PortMapping) ([]ocicni.PortMapping,
// Only get a random candidate for single entries or the start
// of a range. Otherwise we just increment the candidate.
if !tmp.isInRange || tmp.startOfRange {
- candidate, err = specgen.GetRandomPort()
+ candidate, err = utils.GetRandomPort()
if err != nil {
return nil, nil, nil, errors.Wrapf(err, "error getting candidate host port for container port %d", p.ContainerPort)
}
@@ -344,7 +346,7 @@ func createPortMappings(ctx context.Context, s *specgen.SpecGenerator, img *imag
for hostPort == 0 && tries > 0 {
// We can't select a specific protocol, which is
// unfortunate for the UDP case.
- candidate, err := specgen.GetRandomPort()
+ candidate, err := utils.GetRandomPort()
if err != nil {
return nil, err
}
diff --git a/pkg/specgen/ports.go b/pkg/specgen/ports.go
deleted file mode 100644
index 940b2a564..000000000
--- a/pkg/specgen/ports.go
+++ /dev/null
@@ -1,26 +0,0 @@
-package specgen
-
-import (
- "net"
- "strconv"
-
- "github.com/pkg/errors"
-)
-
-// Find a random, open port on the host
-func GetRandomPort() (int, error) {
- l, err := net.Listen("tcp", ":0")
- if err != nil {
- return 0, errors.Wrapf(err, "unable to get free TCP port")
- }
- defer l.Close()
- _, randomPort, err := net.SplitHostPort(l.Addr().String())
- if err != nil {
- return 0, errors.Wrapf(err, "unable to determine free port")
- }
- rp, err := strconv.Atoi(randomPort)
- if err != nil {
- return 0, errors.Wrapf(err, "unable to convert random port to int")
- }
- return rp, nil
-}