Merge pull request #13849 from baude/defaultvolumess

Mount $HOME:$HOME by default in podman machine init
This commit is contained in:
OpenShift Merge Robot
2022-04-15 06:10:17 -04:00
committed by GitHub
2 changed files with 10 additions and 3 deletions

View File

@ -5,6 +5,7 @@ package machine
import ( import (
"fmt" "fmt"
"os"
"github.com/containers/common/pkg/completion" "github.com/containers/common/pkg/completion"
"github.com/containers/podman/v4/cmd/podman/registry" "github.com/containers/podman/v4/cmd/podman/registry"
@ -94,7 +95,7 @@ func init() {
_ = initCmd.RegisterFlagCompletionFunc(ImagePathFlagName, completion.AutocompleteDefault) _ = initCmd.RegisterFlagCompletionFunc(ImagePathFlagName, completion.AutocompleteDefault)
VolumeFlagName := "volume" VolumeFlagName := "volume"
flags.StringArrayVarP(&initOpts.Volumes, VolumeFlagName, "v", []string{}, "Volumes to mount, source:target") flags.StringArrayVarP(&initOpts.Volumes, VolumeFlagName, "v", cfg.Machine.Volumes, "Volumes to mount, source:target")
_ = initCmd.RegisterFlagCompletionFunc(VolumeFlagName, completion.AutocompleteDefault) _ = initCmd.RegisterFlagCompletionFunc(VolumeFlagName, completion.AutocompleteDefault)
VolumeDriverFlagName := "volume-driver" VolumeDriverFlagName := "volume-driver"
@ -112,9 +113,10 @@ func init() {
// TODO should we allow for a users to append to the qemu cmdline? // TODO should we allow for a users to append to the qemu cmdline?
func initMachine(cmd *cobra.Command, args []string) error { func initMachine(cmd *cobra.Command, args []string) error {
var ( var (
vm machine.VM
err error err error
vm machine.VM
) )
provider := getSystemDefaultProvider() provider := getSystemDefaultProvider()
initOpts.Name = defaultMachineName initOpts.Name = defaultMachineName
if len(args) > 0 { if len(args) > 0 {
@ -126,7 +128,9 @@ func initMachine(cmd *cobra.Command, args []string) error {
if _, err := provider.LoadVMByName(initOpts.Name); err == nil { if _, err := provider.LoadVMByName(initOpts.Name); err == nil {
return errors.Wrap(machine.ErrVMAlreadyExists, initOpts.Name) return errors.Wrap(machine.ErrVMAlreadyExists, initOpts.Name)
} }
for idx, vol := range initOpts.Volumes {
initOpts.Volumes[idx] = os.ExpandEnv(vol)
}
vm, err = provider.NewMachine(initOpts) vm, err = provider.NewMachine(initOpts)
if err != nil { if err != nil {
return err return err

View File

@ -83,6 +83,9 @@ Podman mounts _host-dir_ in the host to _machine-dir_ in the Podman machine.
The root filesystem is mounted read-only in the default operating system, The root filesystem is mounted read-only in the default operating system,
so mounts must be created under the /mnt directory. so mounts must be created under the /mnt directory.
Default volume mounts are defined in *containers.conf*. Unless changed, the default values
is `$HOME:$HOME`.
#### **--volume-driver** #### **--volume-driver**
Driver to use for mounting volumes from the host, such as `virtfs`. Driver to use for mounting volumes from the host, such as `virtfs`.