Skip to content

Commit

Permalink
Merge pull request #13560 from n1hility/backport-handle-incompatible
Browse files Browse the repository at this point in the history
[v4.0] Backport handling of incompatible machines
  • Loading branch information
openshift-merge-robot authored Mar 19, 2022
2 parents e3184e9 + 6878376 commit 19c8019
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 69 deletions.
14 changes: 7 additions & 7 deletions cmd/podman/machine/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var (
)

var (
destoryOptions machine.RemoveOptions
destroyOptions machine.RemoveOptions
)

func init() {
Expand All @@ -37,16 +37,16 @@ func init() {

flags := rmCmd.Flags()
formatFlagName := "force"
flags.BoolVar(&destoryOptions.Force, formatFlagName, false, "Do not prompt before rming")
flags.BoolVarP(&destroyOptions.Force, formatFlagName, "f", false, "Stop and do not prompt before rming")

keysFlagName := "save-keys"
flags.BoolVar(&destoryOptions.SaveKeys, keysFlagName, false, "Do not delete SSH keys")
flags.BoolVar(&destroyOptions.SaveKeys, keysFlagName, false, "Do not delete SSH keys")

ignitionFlagName := "save-ignition"
flags.BoolVar(&destoryOptions.SaveIgnition, ignitionFlagName, false, "Do not delete ignition file")
flags.BoolVar(&destroyOptions.SaveIgnition, ignitionFlagName, false, "Do not delete ignition file")

imageFlagName := "save-image"
flags.BoolVar(&destoryOptions.SaveImage, imageFlagName, false, "Do not delete the image file")
flags.BoolVar(&destroyOptions.SaveImage, imageFlagName, false, "Do not delete the image file")
}

func rm(cmd *cobra.Command, args []string) error {
Expand All @@ -64,12 +64,12 @@ func rm(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
confirmationMessage, remove, err := vm.Remove(vmName, machine.RemoveOptions{})
confirmationMessage, remove, err := vm.Remove(vmName, destroyOptions)
if err != nil {
return err
}

if !destoryOptions.Force {
if !destroyOptions.Force {
// Warn user
fmt.Println(confirmationMessage)
reader := bufio.NewReader(os.Stdin)
Expand Down
4 changes: 0 additions & 4 deletions cmd/podman/machine/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ func start(cmd *cobra.Command, args []string) error {
}
return errors.Wrapf(machine.ErrMultipleActiveVM, "cannot start VM %s. VM %s is currently running", vmName, activeName)
}
vm, err = provider.LoadVMByName(vmName)
if err != nil {
return err
}
fmt.Printf("Starting machine %q\n", vmName)
if err := vm.Start(vmName, machine.StartOptions{}); err != nil {
return err
Expand Down
14 changes: 9 additions & 5 deletions docs/source/markdown/podman-machine-rm.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ is used.

Print usage statement.

#### **--force**
#### **--force**, **-f**

Delete without confirmation
Stop and delete without confirmation.

#### **--save-ignition**

Do not delete the generated ignition file
Do not delete the generated ignition file.

#### **--save-image**

Do not delete the VM image
Do not delete the VM image.

#### **--save-keys**

Expand All @@ -42,7 +42,7 @@ deleted.

## EXAMPLES

Remove a VM named "test1"
Remove a VM named "test1":

```
$ podman machine rm test1
Expand All @@ -58,6 +58,10 @@ The following files will be deleted:
Are you sure you want to continue? [y/N] y
```

```
$ podman machine rm -f test1
$
```
## SEE ALSO
**[podman(1)](podman.1.md)**, **[podman-machine(1)](podman-machine.1.md)**

Expand Down
3 changes: 3 additions & 0 deletions pkg/machine/config.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build amd64 || arm64
// +build amd64 arm64

package machine
Expand Down Expand Up @@ -28,6 +29,8 @@ type InitOptions struct {
Username string
ReExec bool
Rootful bool
// The numberical userid of the user that called machine
UID string
}

type QemuMachineStatus = string
Expand Down
28 changes: 24 additions & 4 deletions pkg/machine/ignition.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type DynamicIgnition struct {
Name string
Key string
TimeZone string
UID int
VMName string
WritePath string
}
Expand All @@ -63,12 +64,13 @@ func NewIgnitionFile(ign DynamicIgnition) error {
ignVersion := Ignition{
Version: "3.2.0",
}

ignPassword := Passwd{
Users: []PasswdUser{
{
Name: ign.Name,
SSHAuthorizedKeys: []SSHAuthorizedKey{SSHAuthorizedKey(ign.Key)},
// Set the UID of the core user inside the machine
UID: intToPtr(ign.UID),
},
{
Name: "root",
Expand Down Expand Up @@ -289,9 +291,7 @@ func getDirs(usrName string) []Directory {
}

func getFiles(usrName string) []File {
var (
files []File
)
files := make([]File, 0)

lingerExample := `[Unit]
Description=A systemd user unit demo
Expand All @@ -310,6 +310,7 @@ machine_enabled=true
delegateConf := `[Service]
Delegate=memory pids cpu io
`
subUID := `%s:100000:1000000`

// Add a fake systemd service to get the user socket rolling
files = append(files, File{
Expand Down Expand Up @@ -344,6 +345,25 @@ Delegate=memory pids cpu io
},
})

// Setup /etc/subuid and /etc/subgid
for _, sub := range []string{"/etc/subuid", "/etc/subgid"} {
files = append(files, File{
Node: Node{
Group: getNodeGrp("root"),
Path: sub,
User: getNodeUsr("root"),
Overwrite: boolToPtr(true),
},
FileEmbedded1: FileEmbedded1{
Append: nil,
Contents: Resource{
Source: encodeDataURLPtr(fmt.Sprintf(subUID, usrName)),
},
Mode: intToPtr(0744),
},
})
}

// Set delegate.conf so cpu,io subsystem is delegated to non-root users as well for cgroupv2
// by default
files = append(files, File{
Expand Down
7 changes: 6 additions & 1 deletion pkg/machine/qemu/config.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
//go:build (amd64 && !windows) || (arm64 && !windows)
// +build amd64,!windows arm64,!windows

package qemu

import "time"
import (
"time"
)

type Provider struct{}

Expand Down Expand Up @@ -35,6 +38,8 @@ type MachineVM struct {
RemoteUsername string
// Whether this machine should run in a rootful or rootless manner
Rootful bool
// UID is the numerical id of the user that called machine
UID int
}

type Mount struct {
Expand Down
Loading

0 comments on commit 19c8019

Please sign in to comment.