summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md1
-rw-r--r--RELEASE_NOTES.md1
-rw-r--r--cmd/podman/machine/init.go2
-rw-r--r--cmd/podman/machine/inspect.go2
-rw-r--r--cmd/podman/machine/list.go2
-rw-r--r--cmd/podman/machine/machine.go2
-rw-r--r--cmd/podman/machine/platform.go2
-rw-r--r--cmd/podman/machine/platform_windows.go2
-rw-r--r--cmd/podman/machine/rm.go2
-rw-r--r--cmd/podman/machine/set.go2
-rw-r--r--cmd/podman/machine/ssh.go2
-rw-r--r--cmd/podman/machine/start.go2
-rw-r--r--cmd/podman/machine/stop.go2
-rw-r--r--cmd/podman/system/reset.go10
-rw-r--r--cmd/podman/system/reset_machine.go13
-rw-r--r--cmd/podman/system/reset_machine_unsupported.go8
-rw-r--r--docs/source/Reference.rst2
-rw-r--r--docs/source/markdown/podman-system-reset.1.md3
-rw-r--r--pkg/machine/config.go29
-rw-r--r--pkg/machine/qemu/machine.go76
-rw-r--r--pkg/machine/wsl/machine.go76
-rw-r--r--test/e2e/system_reset_test.go7
22 files changed, 231 insertions, 17 deletions
diff --git a/README.md b/README.md
index 9b375e35d..d8a29b6ff 100644
--- a/README.md
+++ b/README.md
@@ -32,6 +32,7 @@ Podman presently only supports running containers on Linux. However, we are buil
## Roadmap
+1. Improvements to OS X and Windows support
1. Further improvements to the REST API, with a focus on bugfixes and implementing missing functionality
1. Improvements on rootless containers, with a focus on improving the user experience and exposing presently-unavailable features when possible
1. Improvements to Pods, including the addition of pod-level resource limits
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md
index fd4f96fe0..eefb68a46 100644
--- a/RELEASE_NOTES.md
+++ b/RELEASE_NOTES.md
@@ -6,6 +6,7 @@
- A new container command has been added, `podman container clone`. This command makes a copy of an existing container, with the ability to change some settings (e.g. resource limits) while doing so.
- A new machine command has been added, `podman machine inspect`. This command provides details on the configuration of machine VMs.
- The `podman machine set` command can now change the CPUs, memory, and disk space available to machines after they were initially created, using the new `--cpus`, `--disk-size`, and `--memory` options ([#13633](https://github.com/containers/podman/issues/13633)).
+- Podman now supports sending JSON events related to machines to a Unix socket named `machine_events.*\.sock` in `XDG_RUNTIME_DIR/podman` or to a socket whose path is set in the `PODMAN_MACHINE_EVENTS_SOCK` environment variable.
- Two new volume commands have been added, `podman volume mount` and `podman volume unmount`. These allow for Podman-managed named volumes to be mounted and accessed from outside containers ([#12768](https://github.com/containers/podman/issues/12768)).
- VMs created by `podman machine` now automatically mount the host's `$HOME` into the VM, to allow mounting volumes from the host into containers.
- The `podman container checkpoint` and `podman container restore` options now support checkpointing to and restoring from OCI images. This allows checkpoints to be distributed via standard image registries.
diff --git a/cmd/podman/machine/init.go b/cmd/podman/machine/init.go
index 733266b85..6c31f3531 100644
--- a/cmd/podman/machine/init.go
+++ b/cmd/podman/machine/init.go
@@ -118,7 +118,7 @@ func initMachine(cmd *cobra.Command, args []string) error {
vm machine.VM
)
- provider := getSystemDefaultProvider()
+ provider := GetSystemDefaultProvider()
initOpts.Name = defaultMachineName
if len(args) > 0 {
if len(args[0]) > maxMachineNameSize {
diff --git a/cmd/podman/machine/inspect.go b/cmd/podman/machine/inspect.go
index b8de8e4f4..4600a2b6d 100644
--- a/cmd/podman/machine/inspect.go
+++ b/cmd/podman/machine/inspect.go
@@ -51,7 +51,7 @@ func inspect(cmd *cobra.Command, args []string) error {
args = append(args, defaultMachineName)
}
vms := make([]machine.InspectInfo, 0, len(args))
- provider := getSystemDefaultProvider()
+ provider := GetSystemDefaultProvider()
for _, vmName := range args {
vm, err := provider.LoadVMByName(vmName)
if err != nil {
diff --git a/cmd/podman/machine/list.go b/cmd/podman/machine/list.go
index 861feee07..ef26b7886 100644
--- a/cmd/podman/machine/list.go
+++ b/cmd/podman/machine/list.go
@@ -84,7 +84,7 @@ func list(cmd *cobra.Command, args []string) error {
listFlag.format = "{{.Name}}\n"
}
- provider := getSystemDefaultProvider()
+ provider := GetSystemDefaultProvider()
listResponse, err = provider.List(opts)
if err != nil {
return errors.Wrap(err, "error listing vms")
diff --git a/cmd/podman/machine/machine.go b/cmd/podman/machine/machine.go
index cf7542389..553f1ef7a 100644
--- a/cmd/podman/machine/machine.go
+++ b/cmd/podman/machine/machine.go
@@ -64,7 +64,7 @@ func autocompleteMachine(cmd *cobra.Command, args []string, toComplete string) (
func getMachines(toComplete string) ([]string, cobra.ShellCompDirective) {
suggestions := []string{}
- provider := getSystemDefaultProvider()
+ provider := GetSystemDefaultProvider()
machines, err := provider.List(machine.ListOptions{})
if err != nil {
cobra.CompErrorln(err.Error())
diff --git a/cmd/podman/machine/platform.go b/cmd/podman/machine/platform.go
index 77fec083e..5ba649a48 100644
--- a/cmd/podman/machine/platform.go
+++ b/cmd/podman/machine/platform.go
@@ -8,6 +8,6 @@ import (
"github.com/containers/podman/v4/pkg/machine/qemu"
)
-func getSystemDefaultProvider() machine.Provider {
+func GetSystemDefaultProvider() machine.Provider {
return qemu.GetQemuProvider()
}
diff --git a/cmd/podman/machine/platform_windows.go b/cmd/podman/machine/platform_windows.go
index 03978eda1..cdbc52459 100644
--- a/cmd/podman/machine/platform_windows.go
+++ b/cmd/podman/machine/platform_windows.go
@@ -5,6 +5,6 @@ import (
"github.com/containers/podman/v4/pkg/machine/wsl"
)
-func getSystemDefaultProvider() machine.Provider {
+func GetSystemDefaultProvider() machine.Provider {
return wsl.GetWSLProvider()
}
diff --git a/cmd/podman/machine/rm.go b/cmd/podman/machine/rm.go
index e678eb629..a6e66265c 100644
--- a/cmd/podman/machine/rm.go
+++ b/cmd/podman/machine/rm.go
@@ -61,7 +61,7 @@ func rm(_ *cobra.Command, args []string) error {
vmName = args[0]
}
- provider := getSystemDefaultProvider()
+ provider := GetSystemDefaultProvider()
vm, err = provider.LoadVMByName(vmName)
if err != nil {
return err
diff --git a/cmd/podman/machine/set.go b/cmd/podman/machine/set.go
index a994c981b..5777882da 100644
--- a/cmd/podman/machine/set.go
+++ b/cmd/podman/machine/set.go
@@ -83,7 +83,7 @@ func setMachine(cmd *cobra.Command, args []string) error {
if len(args) > 0 && len(args[0]) > 0 {
vmName = args[0]
}
- provider := getSystemDefaultProvider()
+ provider := GetSystemDefaultProvider()
vm, err = provider.LoadVMByName(vmName)
if err != nil {
return err
diff --git a/cmd/podman/machine/ssh.go b/cmd/podman/machine/ssh.go
index e1175d632..4a86da67a 100644
--- a/cmd/podman/machine/ssh.go
+++ b/cmd/podman/machine/ssh.go
@@ -51,7 +51,7 @@ func ssh(cmd *cobra.Command, args []string) error {
// Set the VM to default
vmName := defaultMachineName
- provider := getSystemDefaultProvider()
+ provider := GetSystemDefaultProvider()
// If len is greater than 0, it means we may have been
// provided the VM name. If so, we check. The VM name,
diff --git a/cmd/podman/machine/start.go b/cmd/podman/machine/start.go
index 2b0c8213d..c9b99e63b 100644
--- a/cmd/podman/machine/start.go
+++ b/cmd/podman/machine/start.go
@@ -42,7 +42,7 @@ func start(_ *cobra.Command, args []string) error {
vmName = args[0]
}
- provider := getSystemDefaultProvider()
+ provider := GetSystemDefaultProvider()
vm, err = provider.LoadVMByName(vmName)
if err != nil {
return err
diff --git a/cmd/podman/machine/stop.go b/cmd/podman/machine/stop.go
index dcb124dd4..993662792 100644
--- a/cmd/podman/machine/stop.go
+++ b/cmd/podman/machine/stop.go
@@ -41,7 +41,7 @@ func stop(cmd *cobra.Command, args []string) error {
if len(args) > 0 && len(args[0]) > 0 {
vmName = args[0]
}
- provider := getSystemDefaultProvider()
+ provider := GetSystemDefaultProvider()
vm, err = provider.LoadVMByName(vmName)
if err != nil {
return err
diff --git a/cmd/podman/system/reset.go b/cmd/podman/system/reset.go
index 8f2e73375..176573bf6 100644
--- a/cmd/podman/system/reset.go
+++ b/cmd/podman/system/reset.go
@@ -61,7 +61,9 @@ func reset(cmd *cobra.Command, args []string) {
- all pods
- all images
- all networks
- - all build cache`)
+ - all build cache
+ - all machines`)
+
if len(listCtn) > 0 {
fmt.Println(`WARNING! The following external containers will be purged:`)
// print first 12 characters of ID and first configured name alias
@@ -103,5 +105,11 @@ func reset(cmd *cobra.Command, args []string) {
//nolint:gocritic
os.Exit(define.ExecErrorCodeGeneric)
}
+
+ // Shutdown podman-machine and delete all machine files
+ if err := resetMachine(); err != nil {
+ logrus.Error(err)
+ }
+
os.Exit(0)
}
diff --git a/cmd/podman/system/reset_machine.go b/cmd/podman/system/reset_machine.go
new file mode 100644
index 000000000..a07b4fb83
--- /dev/null
+++ b/cmd/podman/system/reset_machine.go
@@ -0,0 +1,13 @@
+//go:build (amd64 && !remote) || (arm64 && !remote)
+// +build amd64,!remote arm64,!remote
+
+package system
+
+import (
+ cmdMach "github.com/containers/podman/v4/cmd/podman/machine"
+)
+
+func resetMachine() error {
+ provider := cmdMach.GetSystemDefaultProvider()
+ return provider.RemoveAndCleanMachines()
+}
diff --git a/cmd/podman/system/reset_machine_unsupported.go b/cmd/podman/system/reset_machine_unsupported.go
new file mode 100644
index 000000000..e063cd089
--- /dev/null
+++ b/cmd/podman/system/reset_machine_unsupported.go
@@ -0,0 +1,8 @@
+//go:build !amd64 && !arm64
+// +build !amd64,!arm64
+
+package system
+
+func resetMachine() error {
+ return nil
+}
diff --git a/docs/source/Reference.rst b/docs/source/Reference.rst
index dca49a559..7b3442201 100644
--- a/docs/source/Reference.rst
+++ b/docs/source/Reference.rst
@@ -7,6 +7,8 @@ Show the API documentation for version:
* `latest (main branch) <_static/api.html>`_
+* `version 4.1 <_static/api.html?version=v4.1>`_
+
* `version 4.0 <_static/api.html?version=v4.0>`_
* `version 3.4 <_static/api.html?version=v3.4>`_
diff --git a/docs/source/markdown/podman-system-reset.1.md b/docs/source/markdown/podman-system-reset.1.md
index c463481e6..11ce11d07 100644
--- a/docs/source/markdown/podman-system-reset.1.md
+++ b/docs/source/markdown/podman-system-reset.1.md
@@ -7,7 +7,7 @@ podman\-system\-reset - Reset storage back to initial state
**podman system reset** [*options*]
## DESCRIPTION
-**podman system reset** removes all pods, containers, images, networks and volumes.
+**podman system reset** removes all pods, containers, images, networks and volumes, and machines.
This command must be run **before** changing any of the following fields in the
`containers.conf` or `storage.conf` files: `driver`, `static_dir`, `tmp_dir`
@@ -36,6 +36,7 @@ WARNING! This will remove:
- all images
- all networks
- all build cache
+ - all machines
Are you sure you want to continue? [y/N] y
```
diff --git a/pkg/machine/config.go b/pkg/machine/config.go
index 9a0ce757a..d34776714 100644
--- a/pkg/machine/config.go
+++ b/pkg/machine/config.go
@@ -52,6 +52,7 @@ type Provider interface {
List(opts ListOptions) ([]*ListResponse, error)
IsValidVMName(name string) (bool, error)
CheckExclusiveActiveVM() (bool, string, error)
+ RemoveAndCleanMachines() error
}
type RemoteConnectionType string
@@ -170,11 +171,11 @@ func (rc RemoteConnectionType) MakeSSHURL(host, path, port, userName string) url
// GetDataDir returns the filepath where vm images should
// live for podman-machine.
func GetDataDir(vmType string) (string, error) {
- data, err := homedir.GetDataHome()
+ dataDirPrefix, err := DataDirPrefix()
if err != nil {
return "", err
}
- dataDir := filepath.Join(data, "containers", "podman", "machine", vmType)
+ dataDir := filepath.Join(dataDirPrefix, vmType)
if _, err := os.Stat(dataDir); !os.IsNotExist(err) {
return dataDir, nil
}
@@ -182,14 +183,24 @@ func GetDataDir(vmType string) (string, error) {
return dataDir, mkdirErr
}
+// DataDirPrefix returns the path prefix for all machine data files
+func DataDirPrefix() (string, error) {
+ data, err := homedir.GetDataHome()
+ if err != nil {
+ return "", err
+ }
+ dataDir := filepath.Join(data, "containers", "podman", "machine")
+ return dataDir, nil
+}
+
// GetConfigDir returns the filepath to where configuration
// files for podman-machine should live
func GetConfDir(vmType string) (string, error) {
- conf, err := homedir.GetConfigHome()
+ confDirPrefix, err := ConfDirPrefix()
if err != nil {
return "", err
}
- confDir := filepath.Join(conf, "containers", "podman", "machine", vmType)
+ confDir := filepath.Join(confDirPrefix, vmType)
if _, err := os.Stat(confDir); !os.IsNotExist(err) {
return confDir, nil
}
@@ -197,6 +208,16 @@ func GetConfDir(vmType string) (string, error) {
return confDir, mkdirErr
}
+// ConfDirPrefix returns the path prefix for all machine config files
+func ConfDirPrefix() (string, error) {
+ conf, err := homedir.GetConfigHome()
+ if err != nil {
+ return "", err
+ }
+ confDir := filepath.Join(conf, "containers", "podman", "machine")
+ return confDir, nil
+}
+
// ResourceConfig describes physical attributes of the machine
type ResourceConfig struct {
// CPUs to be assigned to the VM
diff --git a/pkg/machine/qemu/machine.go b/pkg/machine/qemu/machine.go
index fe33e580c..6e36b0886 100644
--- a/pkg/machine/qemu/machine.go
+++ b/pkg/machine/qemu/machine.go
@@ -1544,3 +1544,79 @@ func (v *MachineVM) editCmdLine(flag string, value string) {
v.CmdLine = append(v.CmdLine, []string{flag, value}...)
}
}
+
+// RemoveAndCleanMachines removes all machine and cleans up any other files associatied with podman machine
+func (p *Provider) RemoveAndCleanMachines() error {
+ var (
+ vm machine.VM
+ listResponse []*machine.ListResponse
+ opts machine.ListOptions
+ destroyOptions machine.RemoveOptions
+ )
+ destroyOptions.Force = true
+ var prevErr error
+
+ listResponse, err := p.List(opts)
+ if err != nil {
+ return err
+ }
+
+ for _, mach := range listResponse {
+ vm, err = p.LoadVMByName(mach.Name)
+ if err != nil {
+ if prevErr != nil {
+ logrus.Error(prevErr)
+ }
+ prevErr = err
+ }
+ _, remove, err := vm.Remove(mach.Name, destroyOptions)
+ if err != nil {
+ if prevErr != nil {
+ logrus.Error(prevErr)
+ }
+ prevErr = err
+ } else {
+ if err := remove(); err != nil {
+ if prevErr != nil {
+ logrus.Error(prevErr)
+ }
+ prevErr = err
+ }
+ }
+ }
+
+ // Clean leftover files in data dir
+ dataDir, err := machine.DataDirPrefix()
+ if err != nil {
+ if prevErr != nil {
+ logrus.Error(prevErr)
+ }
+ prevErr = err
+ } else {
+ err := os.RemoveAll(dataDir)
+ if err != nil {
+ if prevErr != nil {
+ logrus.Error(prevErr)
+ }
+ prevErr = err
+ }
+ }
+
+ // Clean leftover files in conf dir
+ confDir, err := machine.ConfDirPrefix()
+ if err != nil {
+ if prevErr != nil {
+ logrus.Error(prevErr)
+ }
+ prevErr = err
+ } else {
+ err := os.RemoveAll(confDir)
+ if err != nil {
+ if prevErr != nil {
+ logrus.Error(prevErr)
+ }
+ prevErr = err
+ }
+ }
+ return prevErr
+}
diff --git a/pkg/machine/wsl/machine.go b/pkg/machine/wsl/machine.go
index bc2ac7864..57fb36fc9 100644
--- a/pkg/machine/wsl/machine.go
+++ b/pkg/machine/wsl/machine.go
@@ -1442,3 +1442,79 @@ func (v *MachineVM) getResources() (resources machine.ResourceConfig) {
resources.DiskSize = getDiskSize(v)
return
}
+
+// RemoveAndCleanMachines removes all machine and cleans up any other files associatied with podman machine
+func (p *Provider) RemoveAndCleanMachines() error {
+ var (
+ vm machine.VM
+ listResponse []*machine.ListResponse
+ opts machine.ListOptions
+ destroyOptions machine.RemoveOptions
+ )
+ destroyOptions.Force = true
+ var prevErr error
+
+ listResponse, err := p.List(opts)
+ if err != nil {
+ return err
+ }
+
+ for _, mach := range listResponse {
+ vm, err = p.LoadVMByName(mach.Name)
+ if err != nil {
+ if prevErr != nil {
+ logrus.Error(prevErr)
+ }
+ prevErr = err
+ }
+ _, remove, err := vm.Remove(mach.Name, destroyOptions)
+ if err != nil {
+ if prevErr != nil {
+ logrus.Error(prevErr)
+ }
+ prevErr = err
+ } else {
+ if err := remove(); err != nil {
+ if prevErr != nil {
+ logrus.Error(prevErr)
+ }
+ prevErr = err
+ }
+ }
+ }
+
+ // Clean leftover files in data dir
+ dataDir, err := machine.DataDirPrefix()
+ if err != nil {
+ if prevErr != nil {
+ logrus.Error(prevErr)
+ }
+ prevErr = err
+ } else {
+ err := os.RemoveAll(dataDir)
+ if err != nil {
+ if prevErr != nil {
+ logrus.Error(prevErr)
+ }
+ prevErr = err
+ }
+ }
+
+ // Clean leftover files in conf dir
+ confDir, err := machine.ConfDirPrefix()
+ if err != nil {
+ if prevErr != nil {
+ logrus.Error(prevErr)
+ }
+ prevErr = err
+ } else {
+ err := os.RemoveAll(confDir)
+ if err != nil {
+ if prevErr != nil {
+ logrus.Error(prevErr)
+ }
+ prevErr = err
+ }
+ }
+ return prevErr
+}
diff --git a/test/e2e/system_reset_test.go b/test/e2e/system_reset_test.go
index ec94bb819..28f2e25ca 100644
--- a/test/e2e/system_reset_test.go
+++ b/test/e2e/system_reset_test.go
@@ -89,5 +89,12 @@ var _ = Describe("podman system reset", func() {
Expect(session).Should(Exit(0))
// default network should exists
Expect(session.OutputToStringArray()).To(HaveLen(1))
+
+ // TODO: machine tests currently don't run outside of the machine test pkg
+ // no machines are created here to cleanup
+ session = podmanTest.Podman([]string{"machine", "list", "-q"})
+ session.WaitWithDefaultTimeout()
+ Expect(session).Should(Exit(0))
+ Expect(session.OutputToStringArray()).To(BeEmpty())
})
})