Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ podman_machine_aarch64_task:
depends_on: *build
ec2_instance:
<<: *standard_build_ec2_aarch64
timeout_in: 30m
timeout_in: 40m
env:
TEST_FLAVOR: "machine-linux"
TEST_BUILD_TAGS: ""
Expand Down
4 changes: 4 additions & 0 deletions cmd/podman/machine/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ func init() {
providerFlagName := "provider"
flags.StringVar(&providerOverride, providerFlagName, "", "Override the default machine provider")
_ = initCmd.RegisterFlagCompletionFunc(providerFlagName, autocompleteMachineProvider)

setDefaultConnectionFlagName := "update-connection"
flags.BoolVarP(&setDefaultSystemConn, setDefaultConnectionFlagName, "u", false, "Set default system connection for this machine")
}

func initMachine(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -296,6 +299,7 @@ func initMachine(cmd *cobra.Command, args []string) error {
if now {
return start(cmd, args)
}

extra := ""
if initOpts.Name != defaultMachineName {
extra = " " + initOpts.Name
Expand Down
23 changes: 15 additions & 8 deletions cmd/podman/machine/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ var (
Example: `podman machine start podman-machine-default`,
ValidArgsFunction: autocompleteMachine,
}
startOpts = machine.StartOptions{}
startOpts = machine.StartOptions{}
setDefaultSystemConn bool
)

func init() {
Expand All @@ -38,15 +39,13 @@ func init() {

quietFlagName := "quiet"
flags.BoolVarP(&startOpts.Quiet, quietFlagName, "q", false, "Suppress machine starting status output")
}

func start(_ *cobra.Command, args []string) error {
var (
err error
)
setDefaultConnectionFlagName := "update-connection"
flags.BoolVarP(&setDefaultSystemConn, setDefaultConnectionFlagName, "u", false, "Set default system connection for this machine")
}

func start(cmd *cobra.Command, args []string) error {
startOpts.NoInfo = startOpts.Quiet || startOpts.NoInfo

vmName := defaultMachineName
if len(args) > 0 && len(args[0]) > 0 {
vmName = args[0]
Expand All @@ -61,10 +60,18 @@ func start(_ *cobra.Command, args []string) error {
fmt.Printf("Starting machine %q\n", vmName)
}

if err := shim.Start(mc, vmProvider, startOpts); err != nil {
shouldUpdate := processSystemConnUpdate(cmd, setDefaultSystemConn)
if err := shim.Start(mc, vmProvider, startOpts, shouldUpdate); err != nil {
return err
}
fmt.Printf("Machine %q started successfully\n", vmName)
newMachineEvent(events.Start, events.Event{Name: vmName})
return nil
}

func processSystemConnUpdate(cmd *cobra.Command, updateVal bool) *bool {
if !cmd.Flags().Changed("update-connection") {
return nil
}
return &updateVal
}
1 change: 1 addition & 0 deletions docs/source/markdown/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ podman-logs.1.md
podman-machine-init.1.md
podman-machine-list.1.md
podman-machine-set.1.md
podman-machine-start.1.md
podman-manifest-add.1.md
podman-manifest-annotate.1.md
podman-manifest-create.1.md
Expand Down
14 changes: 14 additions & 0 deletions docs/source/markdown/options/update-connection.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
####> This option file is used in:
####> podman machine init, machine start
####> If file is edited, make sure the changes
####> are applicable to all of those.
#### **--update-connection**, **-u**

When used in conjunction with `podman machine init --now` or `podman machine start`, this option sets the
associated machine system connection as the default. When using this option, a `-u` or `-update-connection` will
set the value to true. To set this value to false, meaning no change and no prompting,
use `--update-connection=false`.

If the value is set to true, the machine connection will be set as the system default.
If the value is set to false, the system default will be unchanged.
If the option is not set, the user will be prompted and asked if it should be changed.
2 changes: 2 additions & 0 deletions docs/source/markdown/podman-machine-init.1.md.in
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ as the host Windows operating system.

@@option tls-verify

@@option update-connection

#### **--usb**=*bus=number,devnum=number* or *vendor=hexadecimal,product=hexadecimal*

Assign a USB device from the host to the VM via USB passthrough.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ Suppress informational tips.

Suppress machine starting status output.

@@option update-connection

## EXAMPLES

Start the specified podman machine.
Expand Down
11 changes: 11 additions & 0 deletions pkg/machine/e2e/config_init_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package e2e_test

import (
"fmt"
"strconv"
"strings"

Expand All @@ -23,6 +24,7 @@ type initMachine struct {
timezone string
rootful bool
volumes []string
updateConnection *bool
userModeNetworking bool
tlsVerify *bool

Expand Down Expand Up @@ -78,6 +80,10 @@ func (i *initMachine) buildCmd(m *machineTestBuilder) []string {
if i.tlsVerify != nil {
cmd = append(cmd, "--tls-verify="+strconv.FormatBool(*i.tlsVerify))
}
if i.updateConnection != nil {
cmd = append(cmd, fmt.Sprintf("--update-connection=%s", strconv.FormatBool(*i.updateConnection)))
}

name := m.name
cmd = append(cmd, name)

Expand Down Expand Up @@ -175,6 +181,11 @@ func (i *initMachine) withTlsVerify(tlsVerify *bool) *initMachine {
return i
}

func (i *initMachine) withUpdateConnection(value *bool) *initMachine {
i.updateConnection = value
return i
}

func (i *initMachine) withUserModeNetworking(r bool) *initMachine { //nolint:unused,nolintlint
i.userModeNetworking = r
return i
Expand Down
22 changes: 20 additions & 2 deletions pkg/machine/e2e/config_start_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package e2e_test

import (
"fmt"
"strconv"
)

type startMachine struct {
/*
No command line args other than a machine vm name (also not required)
*/
quiet bool
noInfo bool
quiet bool
noInfo bool
updateConnection *bool
}

func (s *startMachine) buildCmd(m *machineTestBuilder) []string {
Expand All @@ -19,6 +25,9 @@ func (s *startMachine) buildCmd(m *machineTestBuilder) []string {
if s.noInfo {
cmd = append(cmd, "--no-info")
}
if s.updateConnection != nil {
cmd = append(cmd, fmt.Sprintf("--update-connection=%s", strconv.FormatBool(*s.updateConnection)))
}
return cmd
}

Expand All @@ -31,3 +40,12 @@ func (s *startMachine) withNoInfo() *startMachine {
s.noInfo = true
return s
}

func (s *startMachine) withUpdateConnection(value *bool) *startMachine {
s.updateConnection = value
return s
}

func ptrBool(v bool) *bool {
return &v
}
2 changes: 1 addition & 1 deletion pkg/machine/e2e/rm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ var _ = Describe("podman machine rm", func() {

barName := "bar"
bar := new(initMachine)
session, err = mb.setName(barName).setCmd(bar.withImage(mb.imagePath).withNow()).run()
session, err = mb.setName(barName).setCmd(bar.withUpdateConnection(ptrBool(false)).withImage(mb.imagePath).withNow()).run()
Expect(err).ToNot(HaveOccurred())
Expect(session).To(Exit(0))

Expand Down
Loading