From 9d0ad92acf84eee48787f0a069b5cba7c6bc9e05 Mon Sep 17 00:00:00 2001 From: Abiola Ibrahim Date: Mon, 26 Aug 2024 07:55:23 +0100 Subject: [PATCH] incus: always use vmnet for network address Signed-off-by: Abiola Ibrahim --- environment/container/incus/incus.go | 6 ------ environment/vm/lima/daemon.go | 19 ++++++++++--------- environment/vm/lima/yaml.go | 3 ++- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/environment/container/incus/incus.go b/environment/container/incus/incus.go index 0497193e7..71ee1d679 100644 --- a/environment/container/incus/incus.go +++ b/environment/container/incus/incus.go @@ -263,12 +263,6 @@ func (c incusRuntime) registerNetworks() error { return fmt.Errorf("error creating managed network '%s': %w", name, err) } - // set as default network - err = c.guest.RunQuiet("sudo", "incus", "profile", "device", "set", "default", "eth0", "network="+name) - if err != nil { - return fmt.Errorf("error setting managed network '%s' as default: %w", name, err) - } - return nil } diff --git a/environment/vm/lima/daemon.go b/environment/vm/lima/daemon.go index b71414540..87c9de52c 100644 --- a/environment/vm/lima/daemon.go +++ b/environment/vm/lima/daemon.go @@ -9,20 +9,21 @@ import ( "github.com/abiosoft/colima/daemon" "github.com/abiosoft/colima/daemon/process/inotify" "github.com/abiosoft/colima/daemon/process/vmnet" + "github.com/abiosoft/colima/environment/container/incus" "github.com/abiosoft/colima/environment/vm/lima/limaconfig" "github.com/abiosoft/colima/util" ) func (l *limaVM) startDaemon(ctx context.Context, conf config.Config) (context.Context, error) { - isQEMU := conf.VMType == limaconfig.QEMU - isVZ := conf.VMType == limaconfig.VZ + // vmnet is used by QEMU and always used by incus (even with VZ) + useVmnet := conf.VMType == limaconfig.QEMU || conf.Runtime == incus.Name - // network daemon is only needed for qemu - conf.Network.Address = conf.Network.Address && isQEMU + // network daemon is only needed for vmnet + conf.Network.Address = conf.Network.Address && useVmnet - // limited to macOS (with Qemu driver) - // or vz with inotify enabled - if !util.MacOS() || (isVZ && !conf.MountINotify) { + // limited to macOS (with vmnet required) + // or with inotify enabled + if !util.MacOS() || (!conf.MountINotify && !conf.Network.Address) { return ctx, nil } @@ -48,7 +49,7 @@ func (l *limaVM) startDaemon(ctx context.Context, conf config.Config) (context.C } // add network processes to daemon - if isQEMU { + if useVmnet { a.Add(func() error { if conf.Network.Address { a.Stage("preparing network") @@ -104,7 +105,7 @@ func (l *limaVM) startDaemon(ctx context.Context, conf config.Config) (context.C // network failure is not fatal if err := a.Exec(); err != nil { - if isQEMU { + if useVmnet { func() { installed, _ := ctx.Value(networkInstalledKey).(bool) if !installed { diff --git a/environment/vm/lima/yaml.go b/environment/vm/lima/yaml.go index 5d45ae8a0..a6c041dd7 100644 --- a/environment/vm/lima/yaml.go +++ b/environment/vm/lima/yaml.go @@ -130,7 +130,8 @@ func newConf(ctx context.Context, conf config.Config) (l limaconfig.Config, err reachableIPAddress := true if conf.Network.Address { - if l.VMType == limaconfig.VZ { + // incus always uses vmnet + if l.VMType == limaconfig.VZ && conf.Runtime != incus.Name { l.Networks = append(l.Networks, limaconfig.Network{ VZNAT: true, Interface: limautil.NetInterface,