Commit Graph

89 Commits

Author SHA1 Message Date
Jason T. Greene d23dd35dc1 Correct VM existance check on WSL
Replaces GetHyperVisorVMs() with Exists() to better abstract the underlying
use-case and slightly imrpove efficiency.

Signed-off-by: Jason T. Greene <jason.greene@redhat.com>
2024-02-14 15:27:56 -06:00
Jason T. Greene 487219d809 Complete WSL implementation, refactor a few areas
Also addresses a number of issues:
- StopHostNetworking isn't plumbed, win-sshproxy leaks on hyperv
- Wait api and print output doesn't work properly on Windows
- API forwarding doesn't work on WSL
- Terminal corruption with after start/stop on Windows
- Gvproxy is forcefully killed vs gracefully quit
- Switching rootful/rootless does not update /var/run/docker.sock on the guest
- File already closed error on init
- HyperV backend is publishing Unix sockets when it should be named pipes
- User-mode networking doesn't always work
- Stop state outside of lock boundaries
- WSL blocks parallel machined (should be supported)

[NO NEW TESTS NEEDED]

Signed-off-by: Jason T. Greene <jason.greene@redhat.com>
2024-02-11 12:58:11 -06:00
Brent Baude d7cb66492b wsl - wip
Signed-off-by: Brent Baude <bbaude@redhat.com>
2024-02-11 12:58:11 -06:00
Brent Baude 2a61998f07 Fail if vm exists in hyperv already
Fix a bug where if a vm exists, created by some other process/user, and
you attempt to make a podman machine with the same name.

Signed-off-by: Brent Baude <bbaude@redhat.com>
2024-02-10 14:49:34 -06:00
Jake Correnti 7be6cd4b09 machine: USB passthrough
Sets up USB passthrough for machine. Additionally moves `SetOptions` out
from `pkg/machine/config.go` to its own file in
`pkg/machine/define/setopts.go`.

[NO NEW TESTS NEEDED]

Signed-off-by: Jake Correnti <jakecorrenti+github@proton.me>
2024-02-08 20:30:43 -05:00
Matt Heon 72f1617fac Bump Go module to v5
Moving from Go module v4 to v5 prepares us for public releases.

Move done using gomove [1] as with the v3 and v4 moves.

[1] https://github.com/KSubedi/gomove

Signed-off-by: Matt Heon <mheon@redhat.com>
2024-02-08 09:35:39 -05:00
Jake Correnti 90c938737a Add functionality for `podman machine set --rootful`
Adds the functionality for `podman machine set --rootful` for AppleHV,
QEMU, and HyperV. Abstracts the functionality out to a method of
`MachineConfig`. WSL currently uses a function `SetRootful` that is
provided by the `machine` package, which will eventually get changed
when WSL moves to the refactored structure.

Re-enables the "set rootful with docker sock change" test.

[NO NEW TESTS NEEDED]

Signed-off-by: Jake Correnti <jakecorrenti+github@proton.me>
Signed-off-by: Brent Baude <bbaude@redhat.com>
2024-02-07 13:24:18 -06:00
Brent Baude b1ce6ef9a8 podman machine 5 - hyperv
this pr represents the podman 5 maching refactoring for HyperV.  with
the exception of already skipped tests, all local tests pass.

Signed-off-by: Brent Baude <bbaude@redhat.com>
2024-02-07 09:18:51 -06:00
Brent Baude 9bb191df51 [CI:MACHINE]Podman5 QEMU refactor
The following PR is the leading PR for refactoring podman machine with
the following goals:

* less duplication/more re-use
* common configuration file between providers
* more consistentency in how machines are handled by providers

The goal of this PR is the rough refactor.  There are still rough spots
for sure, specifically around the podman socket and pipe.  This
implemention is only for Linux. All other providers are still present
but will not compile or work.  This is why tests for them have been
temporarily suspended.

The ready socket code is another area that needs to be smoothed over.
Right now, the ready socket code is still in QEMU.  Preferably it would
be moved to a generic spot where all three approaches to readiness
socket use can be defined.

It should also be noted:

* all machine related tests pass.
* make validate for Linux passes
* Apple QEMU was largely removed
* More code pruning is possible; will become clearer when other
  providers are complete.

the dir pkg/machine/p5 is not permanent.  i had to seperate this from
machine initially due to circular import problems.  i think when all
providers are done (or nearly done), it can be placed and named
properly.

Signed-off-by: Brent Baude <bbaude@redhat.com>
2024-02-07 09:18:36 -06:00
Brent Baude b9bcfa4749 podman5 machine reconfig 1
this is a logical place to get changes upstream before they grow out of
control.  this pr is the first in an effort to deduplicate machine code
and streamline code flow.

a lot of code is simply moved to eliminate circular imports.  names and
specific paths can ultimately be changed.  i dont like some of the
descriptive interface names, etc.  ultimately, i think once we have the
"old" code sanitized, we can re-use some of those.

clearly some of what is in here is temporary and will either be deleted,
changed, or moved again as this effort comes to a close.

right now, the machine code does not use any of the "new" code.  you
will see in `init` and `rm` some commented out code that hooks it. i'm
afraid things will get worse before they get better (way worse).

[NO NEW TESTS NEEDED]

Signed-off-by: Brent Baude <bbaude@redhat.com>
2024-02-07 08:17:43 -06:00
Paul Holzinger 46fe7ef3bb
use pkg/strongunits from c/common
The code has been moved to c/common so it can be shared with libhvee.

[NO NEW TESTS NEEDED]

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-02-06 16:39:16 +01:00
Brent Baude 1964dbd406 Set up podman machine remote user correctly
The remote user functionality was not quite correct.  This PR breaks out
the accumulation of user descriptions into a separate function.  One
odditiy is ignition must be told to NOT create the core user (or it will
by default) by "adding" the core user with a set bool.

[NO NEW TESTS NEEDED]

Signed-off-by: Brent Baude <bbaude@redhat.com>
2024-01-17 08:57:46 -06:00
openshift-merge-bot[bot] 3b18c77712
Merge pull request #20878 from ashley-cui/winapiforwarding
Add API forwarding support for HyperV
2024-01-08 20:07:23 +00:00
openshift-merge-bot[bot] 1697a8bfcf
Merge pull request #21175 from baude/consolidateIgnitionReadySocket
consolidate ignition ready socket unit
2024-01-06 11:18:57 +00:00
Ashley Cui e3f167f770 Add API forwarding support for HyperV
Provides Docker API client access, allowing compose to work by default
for HyperV. Basically the HyperV equiv of the work done here by #12916.

[NO NEW TESTS NEEDED]

Signed-off-by: Ashley Cui <acui@redhat.com>
2024-01-05 11:45:28 -05:00
Brent Baude a0a541351d consolidate ignition ready socket unit
consolidated ignition ready unit file content into one function.

[NO NEW TESTS NEEDED]

Signed-off-by: Brent Baude <bbaude@redhat.com>
2024-01-05 10:11:43 -06:00
Colin Walters 06064150ea machine: use GlobalDataDir helper
We shouldn't hardcode `~/.local` - we should use the internal
config helper APIs which honor the XDG_DATA_DIR etc. standard
environment variables.

Signed-off-by: Colin Walters <walters@verbum.org>
2024-01-05 10:29:36 -05:00
Jake Correnti 3bfdd79150 Fix init teardown on bad ignition path
Fixes a bug where if a machine failed during init due to a bad ignition path, it would not be properly torn down.

Signed-off-by: Jake Correnti <jakecorrenti+github@proton.me>
2024-01-04 23:47:59 -05:00
Jake Correnti b01a330d37 Use single persistent ssh key for all machines
Changes SSH key behavior such that there is a single persisted key for all
machines across all providers. If there is no key that is located at
`.local/share/containers/podman/machine/` then it is created. The keys are
not deleted when the last machine on the host is removed.

The main motivation for this change is it leads to fewer files created on the
host as a result of vm configuration. Having `n` machines on your system doesn't
result in `2n` machine-related files in `.ssh` on your system anymore.

As a result of ssh keys being persisted by default, the `--save-keys` flag
on `podman machine rm` will no longer be supported.

Signed-off-by: Jake Correnti <jakecorrenti+github@proton.me>
2024-01-04 23:47:49 -05:00
Jake Correnti 98f332d482 Use parser.UnitFile
Uses the systemd unit file parser to build unit files instead of having
them be just blocks of hard-coded strings.

Signed-off-by: Jake Correnti <jakecorrenti+github@proton.me>
2024-01-04 08:51:35 -05:00
Jake Correnti c728eeb39e Create `pkg/machine/ignition` package
Moves all of the ignitionfiles out of the `machine` package and into
its own called `ignition`. This required `VMType` to get moved out of
the `machine` package and into the `define` package in order to prevent
a circular dependency.

Signed-off-by: Jake Correnti <jakecorrenti+github@proton.me>
2024-01-04 08:51:35 -05:00
Oleksandr Redko 2a2d0b0e18 chore: delete obsolete // +build lines
Signed-off-by: Oleksandr Redko <Oleksandr_Redko@epam.com>
2024-01-04 11:53:38 +02:00
Matt Heon 5cc5b43473 Error on HyperV VM start when gvproxy has failed to start
After the VM has successfully started, check that gvproxy is
still running. If it is not, throw an error and refuse to
complete machine start.

[NO NEW TESTS NEEDED] I don't think we can deliberately trigger a
bad gvproxy start without a bad Podman binary. We could try and
kill gvproxy after it starts but before the machine is booted but
that's very prone to races.

Slightly restructure code so that starting shares happens later
and has its own configuration write - so the VM is still recorded
as running if starting shares fails.

Signed-off-by: Matt Heon <mheon@redhat.com>
2023-12-14 13:31:37 -05:00
Brent Baude 3a842027af CheckExclusiveArch should use local JSON too
When performing CheckExclusiveArch, we should get a list of VMs that
exist on disk (JSON).  We should then iterate those and checking if they
are running in HyperV.

[NO NEW TESTS NEEDED]

Signed-off-by: Brent Baude <bbaude@redhat.com>
2023-12-13 14:41:29 -06:00
Brent Baude e5a4f00b7d Podman 5 machine config file - Step 1
The following PR is the very first step in what will a series of steps
to apply a "common" machine configuration file to all providers.
Function names, method names, struct names, and field names are all up
for debate.  The purpose of this PR is to offer a glimpse at the
direction we intend to take.

This PR also contains temporary structs (i.e. aThing) that are not
exported.  These are merely placeholders.

The configuration work in this PR is also unused of yet.  But the code
is compiled.  Once merged, we can begin the next step of development.

[NO NEW TESTS NEEDED]

Signed-off-by: Brent Baude <bbaude@redhat.com>
2023-12-11 16:26:15 -06:00
Christophe Fergeau 6c2a0196a9 machine: usb: Fix 'passtrough' typo
[NO NEW TESTS NEEDED]

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
2023-12-08 12:24:39 +01:00
openshift-merge-bot[bot] 7dd33b307d
Merge pull request #20540 from victortoso/usb-host-passthrough
qemu: add usb host passthrough
2023-11-13 16:03:30 +00:00
openshift-merge-bot[bot] 79eec47f5f
Merge pull request #20626 from jakecorrenti/ignition-builder
Refactor Ignition configuration for virt providers
2023-11-09 19:54:00 +00:00
Jake Correnti 39d647a2f6 Fix socket mapping socket mapping nits
Fixes nits that were suggested in #20420. The caller of
`ListenAndWaitOnSocket` did not use the value returned by the conn
channel, therefore it was better to just close the conn in the
`ListenAndWaitOnSocket` function instead.

[NO NEW TESTS NEEDED]

Signed-off-by: Jake Correnti <jakecorrenti+github@proton.me>
2023-11-09 10:41:50 -05:00
Victor Toso c23963d7a8 machine: qemu: add usb host passthrough
QEMU usb-host driver which is the one for passthrough, supports two
options for selecting an USB devices in the host to provide it to the
VM:
 - Bus and Device number the device is plugged
 - Vendor and Product information of the USB devices

    https://qemu-project.gitlab.io/qemu/system/devices/usb.html

This commit allows a user to configure podman machine with either of
options, with new --usb command line option for podman machine init.

Examples
  podman machine init tosovm4 --usb vendor=13d3,product=5406
  podman machine init tosovm3 --usb bus=1,devnum=4 --usb bus=1,devnum=3

This commit also allows a user to change the USBs configured with
--usb command line option for podman machine set.

Note that this commit does not handle host device permissions nor
verify that the USB devices exists.

Signed-off-by: Victor Toso <victortoso@redhat.com>
2023-11-08 23:38:53 +01:00
Jake Correnti b2c56365b2 Refactor Ignition configuration for virt providers
Creates a common SetIgnitionFile function in pkg/machine/ignition.go which
creates the new VMFile that will represent the machine's ignition file. It
assigns the VMFile to the provided location.

Creates an IgnitionBuilder type to generate the ignition configuration for a
given virt provider.

[NO NEW TESTS NEEDED]

Signed-off-by: Jake Correnti <jakecorrenti+github@proton.me>
2023-11-08 13:39:34 -05:00
Brent Baude a45ba06d02 Refactor key machine objects
In #20538, I was asked to consider refactoring the new OCI pull code
from within the generic machine directory.  This is something I had
tried when originally coding it but it became apparent that a much
larger refactor to prevent circular deps was needed.  Because I did not
want to pollute the initial PR with that refactor, I asked for the PR to
merge first.  This is the refactor that needed to be done.

Signed-off-by: Brent Baude <bbaude@redhat.com>
2023-11-07 08:30:44 -06:00
openshift-ci[bot] 5fc7585334
Merge pull request #20420 from jakecorrenti/refactor-socket-mapping
Refactor machine socket mapping
2023-11-03 18:33:54 +00:00
Jake Correnti ce9c1b9b86 Refactor machine socket mapping
Refactors machine socket mapping to prevent using similar/the same code
paths. Moves the shared code to `pkg/machine/sockets.go`.

[NO NEW TESTS NEEDED]

Signed-off-by: Jake Correnti <jakecorrenti+github@proton.me>
2023-11-01 23:09:17 -04:00
Matt Heon 7153124f97 Log gvproxy and server9 to file on log-level=debug
Logging to os.Stdout and os.Stderr does not seem to work in
Powershell. I am not entirely certain why.

Logfiles are the best alternative I can think of.

Signed-off-by: Matt Heon <mheon@redhat.com>
2023-10-31 10:14:06 -04:00
Matthew Heon 642fa98976 Initial addition of 9p code to Podman
This includes two new hidden commands: a 9p server,
`podman machine server9p`, and a 9p client,
`podman machine client9p` with `server9p` currently only
configured to run on Windows and serve 9p via HyperV vsock, and
`client9p` only configured to run on Linux. The server is run by
`podman machine start` and has the same lifespan as gvproxy
(waits for the gvproxy PID to die before shutting down). The
client is run inside the VM, also by `podman machine start`, and
mounts uses kernel 9p mount code to complete the mount. It's
unfortunately not possible to use mount directly without the
wrapper; we need to set up the vsock and pass it to mount as an
FD.

In theory this can be generalized so that the server can run
anywhere and over almost any transport, but I haven't done this
here as I don't think we have a usecase other than HyperV right
now.

[NO NEW TESTS NEEDED] This requires changes to Podman in the VM,
so we need to wait until a build with this lands in FCOS to test.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2023-10-31 10:14:02 -04:00
Ashley Cui d6f44d956d hyperV: Update lastUp time
LastUp now correctly reports the lastUp time for podman machine on
hyperv, for both inspect and list.

Signed-off-by: Ashley Cui <acui@redhat.com>
2023-10-20 15:00:48 -04:00
openshift-ci[bot] aa0e96e781
Merge pull request #20274 from ashley-cui/cleanup
Machine: Teardown on init failure
2023-10-13 14:22:46 +00:00
Jake Correnti 987dc2b8bb SetLock for all virt providers
Implements a shared `GetLock` function for virtualization providers. Returns
a pointer to a lockfile used for serializing write operations.

[NO NEW TESTS NEEDED]

Signed-off-by: Jake Correnti <jakecorrenti+github@proton.me>
2023-10-12 12:06:31 -04:00
Ashley Cui 61e0b64b91 Machine: Teardown on init failure
If init fails, or if a SIGINT is sent during init, podman machine should remove all files and configs
created during the init. This includes config jsons, image files, ssh
id's, and system connections. On Windows, the VM instances are also
unregistered.

Signed-off-by: Ashley Cui <acui@redhat.com>
2023-10-12 09:26:06 -04:00
Ashley Cui 995a6a8ac4 Add podman socket info to machine inspect
HyperV and appleHV machine inspect commands were missing podman socket
info. This also fixes machine inspect tests on hyperV

Signed-off-by: Ashley Cui <acui@redhat.com>
2023-09-26 15:50:00 -04:00
Ashley Cui 65ce034863 hyperV: Respect rootful option on machine init
Fixed a bug where the rootful option to the podman machine init command
would not be written to to the machine config, and the rootful docker
sock would not be set.

Signed-off-by: Ashley Cui <acui@redhat.com>
2023-09-25 16:13:55 -04:00
OpenShift Merge Robot 9ba0022905
Merge pull request #20115 from baude/hypervstarting
hyperv: set more realistic starting state
2023-09-24 19:24:50 -04:00
Brent Baude 08936db354 hyperv: set more realistic starting state
the window for hyperv's "Starting" state is very narrow; so to more
mimic qemu, we follow suit.  starting bools are set when the vm boots
and when it communicates back on the read socket.

this allows pkg/machine/init_test.go to pass

[NO NEW TESTS NEEDED]

Signed-off-by: Brent Baude <bbaude@redhat.com>
2023-09-24 10:13:43 -05:00
Brent Baude 2bef573f34 hyperv: use StopWithForce with remove
When doing a machine rm -f (force removal of a machine) or a machine
reset (force removal of all machines), there is no need to use a
"polite/soft" stop.

this will also speed up pkg/machine/e2e tests.

[NO NEW TESTS NEEDED]

Signed-off-by: Brent Baude <bbaude@redhat.com>
2023-09-24 09:49:40 -05:00
Brent Baude c66aa3b7bb fixes for pkg/machine/e2e on hyperv
some problems were found in machine tests on hyperv.

in the case of rootful, it is currently not implemented.  an issue #20092 has been
created for that problem.

there also seems to be a timezone issue between ignition and fcos right
now.  inquiries are in for that but no issue generated for that.  this
problem is not exclusive to hyperv by any means.

both of the above have been skipped or commented out.

otherwise, this fixes machine state reporting for consistency.

Signed-off-by: Brent Baude <bbaude@redhat.com>
2023-09-21 16:14:57 -05:00
Brent Baude 5b3801776b Various updates for hyperv and machine e2e tests
This PR is a mishmash of updates needed so that the hyperv provider can
begin to passd the machine e2e tests.

Summary as follows:
* Added custom error handling for machine errors so that all providers
  can generate the same formatted error messages.  The ones implemented
  thus far are needed for the basic and init tests.  More will come as
  they are identified.
* Vendored new libhvee for better memory inspection.  The memory type
  changed from uint32 to uint64.
* Some machine e2e tests used linux-specific utilities to check various
  error conditions and messages (like pgrep).  Those were made into
  functions and implemented on an operating system level.

[NO NEW TESTS NEEDED]

Signed-off-by: Brent Baude <bbaude@redhat.com>
2023-09-21 08:52:02 -05:00
Brent Baude f3e9a6369c windows cannot "do" extra files
if you use the extra files function on exec commands, windows loses it's
mind.

[NO NEW TESTS NEEDED]

Signed-off-by: Brent Baude <bbaude@redhat.com>
2023-09-20 15:14:08 -05:00
Jake Correnti 289e59ee1f Implement gvproxy networking using cmdline wrapper
Converts the host networking code in `podman machine` to use the
`GvproxyCommand` type introduced in containers/gvisor-tap-vsock#258

[NO NEW TESTS NEEDED]

Signed-off-by: Jake Correnti <jakecorrenti+github@proton.me>
2023-09-19 09:20:26 -04:00
Brent Baude a62abfe3d6 Tweaks and cleanups to prepare hyperv for CI
Small fixes for bugs in the hyperv code that were made obvious when
manually preparing to run pkg/machine/e2e with windows and hyperv.

Also includes vendoring a new libhvee and solves bug where json config
was not being removed.

[NO NEW TESTS NEEDED]

Signed-off-by: Brent Baude <bbaude@redhat.com>
2023-08-30 12:44:50 -05:00