Commit Graph

192 Commits

Author SHA1 Message Date
Brent Baude 521b2451c7 Correct units in init error message
When trying to initialize a machine with more memory that the system has
we were outputting an error message in the wrong unit.  It should have
been in MB and B. This was found as part of  but is not the
solution for that issue.

Signed-off-by: Brent Baude <bbaude@redhat.com>
2025-04-09 09:50:26 -05:00
Jake Correnti f166f1503c
Honor rootfulness when SSH-ing into named Machine
Fix a bug where SSH-ing into a named Podman Machine (not podman-machine-default)
results in the user being put in the rootless shell if the default system
connection is rootless.

Resolves: https://github.com/containers/podman/issues/25332

Signed-off-by: Jake Correnti <jakecorrenti+github@proton.me>
2025-03-14 13:48:49 -04:00
Jake Correnti 42fb942a6f
Introduce `podman machine cp` command
Add a new `podman machine cp` subcommand to allow users to copy files or
directories between a running Podman Machine and their host.

Tests cover the following cases:
- Copy a file from the host machine to the VM
- Copy a directory from the host machine to the VM
- Copy a file from the VM to the host machine
- Copy a directory from the VM to the host machine
- Copy a file to a directory
- Copy a directory to a file

Signed-off-by: Jake Correnti <jakecorrenti+github@proton.me>
2025-02-28 09:56:46 -05:00
Jake Correnti 297e8a3476 Add `machine init --playbook`
Allow the user to provide an Ansible playbook file on init which will
then be run on boot.

Signed-off-by: Jake Correnti <jakecorrenti+github@proton.me>
Signed-off-by: Brent Baude <bbaude@redhat.com>
2025-02-03 16:43:04 -05:00
openshift-merge-bot[bot] 48f8742278
Merge pull request from baude/movedetect
Move detection of libkrun and intel
2025-01-30 15:37:07 +00:00
Brent Baude 398377fd97 Move detection of libkrun and intel
A review comment post merge suggested I move the detection of libkrun and intel into the provider.Get()

Signed-off-by: Brent Baude <bbaude@redhat.com>
2025-01-29 13:26:45 -06:00
Brent Baude e893747cf3 Remove unnecessary error handling
A function in the reset code does not return an error.  Simply removing the error variable and check for the condition (which was always false or nil)

Signed-off-by: Brent Baude <bbaude@redhat.com>
2025-01-29 12:12:17 -06:00
Brent Baude 357f76daae error with libkrun on intel-based machines
libkrun is not supported on Intel.  We should error.

Signed-off-by: Brent Baude <bbaude@redhat.com>
2025-01-28 14:12:44 -06:00
Jake Correnti 9febd2c27a Move `DefaultMachineName` to `pkg/machine/define`
Moves the `DefaultMachineName` constant out of `pkg/machine` and into
`pkg/machine/define`.

Signed-off-by: Jake Correnti <jakecorrenti+github@proton.me>
2024-09-24 15:36:14 -04:00
Mikel Olasagasti Uranga e9a4534cb1 Update module github.com/shirou/gopsutil to v4
Signed-off-by: Mikel Olasagasti Uranga <mikel@olasagasti.info>
2024-09-03 18:20:12 +02:00
Ashley Cui 41f945fc24 machine: Add -all-providers flag to machine list
Podman machine list now supports a new option, --all-providers, which lists all machines from all providers.

Signed-off-by: Ashley Cui <acui@redhat.com>
2024-08-28 13:40:50 -04:00
openshift-merge-bot[bot] e225cae781
Merge pull request from afbjorklund/remove-machine-volume-driver
Remove the unused machine volume-driver
2024-07-15 20:36:19 +00:00
Anders F Björklund f3e945c86e Keep the volume-driver flag deprecated
Signed-off-by: Anders F Björklund <anders.f.bjorklund@gmail.com>
2024-07-15 21:41:34 +02:00
openshift-merge-bot[bot] 3a41bccf7d
Merge pull request from ashley-cui/machreset
Podman machine resets all providers
2024-07-01 19:24:18 +00:00
Anders F Björklund fa75599569 Remove the unused machine volume-driver
The driver is now hardcoded again, and there can only be
one type of mounts at a time (which one changes over time)

Revert "Make it possible to select the volume driver"
This reverts commit 6630e5cf66.

Signed-off-by: Anders F Björklund <anders.f.bjorklund@gmail.com>
2024-06-30 20:25:59 +02:00
Brent Baude 786ea01a64 Error when machine memory exceeds system memory
Close loophole that would allow you to assign more memory than the
system has to a podman machine

Fixes: 

Signed-off-by: Brent Baude <bbaude@redhat.com>
2024-06-28 10:02:11 -05:00
Ashley Cui 069eace84b Podman machine resets all providers
Podman machine reset now removes and resets machines from all providers availabe on the platform.

On windows, if the user is does not have admin privs, machine will only reset WSL, but will emit a warning that it is unable to remove hyperV machines without elevated privs.

Signed-off-by: Ashley Cui <acui@redhat.com>
2024-06-27 13:14:29 -04:00
Shion Tanaka fe7cc67ef4 Add Rosetta support for Apple Silicon mac
Signed-off-by: Shion Tanaka <shtanaka@redhat.com>
2024-05-17 17:53:28 +09:00
Jason T. Greene 11415b3e74 Use built-in ssh impl for all non-pty operations
Windows is not guaranteed to have the SSH feature installed, so prefer the use
of the built-in ssh client for all operations other than podman machine ssh,
which requires terminal pty logic. This restores previous behavior in 4.x.

Signed-off-by: Jason T. Greene <jason.greene@redhat.com>
2024-03-24 21:25:22 -05:00
Paul Holzinger e82d196269
pkg/machine: make checkExclusiveActiveVM race free
We need to take another lock to prevent concurrent starts from different
machines.

I manually tested it by starting three VM in parallel with:
podman machine start & podman machine start test1 & podman machine start test2

I also added a CI test that seems to work as expected (failed with the
old binary, worked with the new)

Before this patch I was able to start more than VM, with this patch it
now only starts one of them and the other ones will fail to start with
a proper error.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-03-14 11:13:08 +01:00
Paul Holzinger 25f3a8ce77
podman machine start/stop do not write config unlocked
Move the writes into the shim level to make sure they happen while we
hold the machine lock to prevent any race conditions reading/writing the
file.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-03-07 15:11:41 +01:00
Paul Holzinger 7a75914921
podman machine init: do not write config unlocked
First make sure we check that a given VM exist when holding the VM lock
for it. The check in cmd/podman/machine/init.go is a nice quick out but
not enough to ensure that 2 processes to not create the same VM at the
same time. The only way to ensure this is by holding the lock and
checking if the VM config file exists.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-03-07 14:58:25 +01:00
Paul Holzinger 3c9c5be7da
podman machine set: change options only locked
Make sure we only update the machine config when we are locked.
While it doesn't make a functional differnce for cpu and memory it was a
problem for disk size. The disk size must be larger than the previous
one so we must have accurate data on the previous value.

Thus change the settings only while locked and refresh the config so we
have the current up to date values.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-03-07 14:19:06 +01:00
Paul Holzinger 4d2fc293c0
machine: make more use of strongunits
To make it very clear in the code what unit the uint represents.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-03-06 16:14:30 +01:00
openshift-merge-bot[bot] 5ad1f2e43b
Merge pull request from tnk4on/fix-wrong-units-size-return
Fix problem with `podman machine list` returning wrong units for Memory and Disk size
2024-03-06 13:55:56 +00:00
Shion Tanaka 92b67a69ae Fix wrong units size return
Signed-off-by: Shion Tanaka <shtanaka@redhat.com>
2024-03-06 19:41:11 +09:00
Jason T. Greene ef7727238a Refactor env dir and port functions into new leaf pkgs
[NO NEW TESTS NEEDED]

Signed-off-by: Jason T. Greene <jason.greene@redhat.com>
2024-03-04 23:54:31 -06:00
Ashley Cui 527b3793b8 Use machine image as specified in containers.conf
For podman machine init, deprecate the --image-path option for --image.
--image now accepts the correct image from containers.conf

Also, add the ability to specify an OCI image from the --image flag using the docker:// transport.

Signed-off-by: Ashley Cui <acui@redhat.com>
2024-02-29 13:38:43 -05:00
Ashley Cui 35133c8424 Move locks to shim layer
Previously, the locks were on the provider layer, which doesn't make a vm operation with a config file update atomic. Move them up a layer, so the entire function locks while doing provider and config operations.

This adds a Remove and a Set function to the shim layer.

[NO NEW TESTS NEEDED] Unsure how to test this

Signed-off-by: Ashley Cui <acui@redhat.com>
2024-02-29 00:12:04 -05:00
openshift-merge-bot[bot] 9d1704396a
Merge pull request from mheon/hyperv_9p_mkdir
Ensure HyperV 9p mounts work when a dir doesn't exist
2024-02-27 22:34:07 +00:00
Matt Heon 26ec570c65 Ensure HyperV 9p mounts work when a dir doesn't exist
Before, we required that the mount target exist and be a
directory for the 9p mount to successfully complete, which is not
how things are supposed to work - the user should be able to
mount anywhere. This should just be a simple mkdir, but with FCOS
the root directory is immutable so we need to undo that before we
can mkdir, and unfortunately we don't have a library that can do
chattr (and I didn't want to drag in a new dependency just for
that), so let's be gross and add it to the SSH command. I
aggressively dislike this but it does work.

[NO NEW TESTS NEEDED] Can worry about getting a more generic
mount test together for Machine later.

Signed-off-by: Matt Heon <mheon@redhat.com>
2024-02-27 14:33:53 -05:00
Paul Holzinger 8d9ff04d10
vendor update gopkg.in/yaml.v2 to v3
There is no reason for us to use v2 here, we use v3 already in most
places. The go-openapi dependency still uses v2 so we do not get rid of
it yet but it looks like they migrated upstream so once a new version
is released there and finds our way to us then we should get some nice
binary size reduction.

[NO NEW TESTS NEEDED]

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-02-27 12:20:58 +01:00
Jake Correnti be9aba7ccd Remove image provenance from `machine inspect`
We don't care about the provenance of the machine image, so this is no
longer applicable to have when displaying info.

Signed-off-by: Jake Correnti <jakecorrenti+github@proton.me>
2024-02-22 08:34:27 -05:00
Jake Correnti d68240b150 Update machine files rm order and add QEMU rm
Changes the order in which the machine-specific files are removed in
`Remove()`. Removes the system connections first, then removes the
`configPath` last. `configPath` is removed last, because in the case of
an error with any of the previous files, the removal can be attempted
again since the machine still "exists".

Made the errors in `Remove` hard errors instead of soft errors.

Added the implementation for the QEMU-specific file removal.

[NO NEW TESTS NEEDED]

Signed-off-by: Jake Correnti <jakecorrenti+github@proton.me>
2024-02-22 08:31:55 -05:00
openshift-merge-bot[bot] 669e718561
Merge pull request from jakecorrenti/inspectinfo-hostuser
machine: Remove unnecessary TODOs
2024-02-22 10:29:51 +00:00
openshift-merge-bot[bot] 59b6f48d90
Merge pull request from jakecorrenti/inspect-conn-vals
machine: Add `ConnectionInfo` to inspect
2024-02-22 02:36:50 +00:00
Jake Correnti 09095acf2b machine: Add `ConnectionInfo` to `MachineConfig`
Adds `ConnectionInfo()` to the `MachineConfig` and fills out
`InspectInfo` accordingly. Additionally fixes the "inspect with go format" test.

Changes `ConfigPath` to `ConfigDir` to better represent the
output.

Signed-off-by: Jake Correnti <jakecorrenti+github@proton.me>
2024-02-20 09:08:11 -05:00
Jake Correnti 66f39eee5e machine: Remove unnecessary TODOs
Remove TODO to swap `Rootful` in Inspect with `HostUser`

It is unnecessary to remove the vfkit logfile in the provider-specific Remove function. Vfkit is fed the default logfile provided by mc.LogFile which is removed by the generic Remove function.

Removes TODO regarding moving the location of Stop. False TODO.

[NO NEW TESTS NEEDED]

Signed-off-by: Jake Correnti <jakecorrenti+github@proton.me>
2024-02-19 19:51:49 -05:00
Brent Baude 10d748f584 Introduce Podman machine reset
Podman machine reset is a new command that will "reset" your podman
machine environment.  Reset is defined as:

* Stop and Remove all VMs
* Remove the following directories:
    - configuration dir i.e. ~/.config/containers/podman/machine/qemu
    - data dir i.e. ~/.local/.share/containers/podman/machine/qemu

When deleting, if errors are encountered, they will be batched and spit
out at the end.  Podman will try to proceed even in error in doing what
it was told.

Signed-off-by: Brent Baude <bbaude@redhat.com>
2024-02-18 08:43:12 -06:00
openshift-merge-bot[bot] fbb4d5dca6
Merge pull request from Luap99/machine-cleanup
machine init: validate machine name and username
2024-02-17 12:33:23 +00:00
Jason T. Greene f036476cfa fix usermode test
Signed-off-by: Jason T. Greene <jason.greene@redhat.com>
2024-02-16 09:17:29 -06:00
Paul Holzinger 2846027dc6
machine init: validate machine name and username
Validate the names with our name regex that we also use for
containers/pods. While we technically do not need to be that strict, I
think it makes sense to match containers. The most important bit of this
validation is that we exclude the use of / and \ which breaks all our
file paths as we just use this in the name an when machine write the
file it ends up being in a subdir which breaks the reading side. Also
other special characters could cause trouble for the URL parsing in the
machine connection URL.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-02-16 15:58:39 +01: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
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 e8501ca991 Implement generic providers
The intial refactor used specifically qemu for testing and infra bring
up.  But the whole point was to have things interfaced.  This PR results
in an interface experience like podman 4 using the same term `provider`
to generically represent 'a provider' like qemu/applehv/etc.

This PR is required to move forward with new providers.

Also renamed pkg/machine/p5 to pkg/machine/shim.

[NO NEW TESTS REQUIRED]

Signed-off-by: Brent Baude <bbaude@redhat.com>
2024-02-07 09:18:38 -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