Skip to content

Commit a974c2f

Browse files
committed
preflight: Replace libvirt VM removal with macadam integration
Update the removeCrcVM function to utilize macadam for VM status checks and removal. This change eliminates the previous libvirt dependency, streamlining the VM management process and improving error handling when removing the 'crc' VM.
1 parent 8505a55 commit a974c2f

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

pkg/crc/preflight/preflight_checks_linux.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/crc-org/crc/v2/pkg/crc/constants"
1414
"github.com/crc-org/crc/v2/pkg/crc/daemonclient"
1515
"github.com/crc-org/crc/v2/pkg/crc/logging"
16+
"github.com/crc-org/crc/v2/pkg/crc/macadam"
1617
"github.com/crc-org/crc/v2/pkg/crc/systemd"
1718
"github.com/crc-org/crc/v2/pkg/crc/systemd/states"
1819
crcos "github.com/crc-org/crc/v2/pkg/os"
@@ -440,23 +441,17 @@ func warnNoDaemonAutostart() error {
440441
}
441442

442443
func removeCrcVM() error {
443-
stdout, _, err := crcos.RunWithDefaultLocale("virsh", "--connect", "qemu:///system", "domstate", constants.DefaultName)
444+
m := macadam.UseMacadam()
445+
_, err := m.GetVMStatus(constants.DefaultName)
444446
if err != nil {
445447
// User may have run `crc delete` before `crc cleanup`
446448
// in that case there is no crc vm so return early.
447449
return nil
448450
}
449-
if strings.TrimSpace(stdout) == "running" {
450-
_, stderr, err := crcos.RunWithDefaultLocale("virsh", "--connect", "qemu:///system", "destroy", constants.DefaultName)
451-
if err != nil {
452-
logging.Debugf("%v : %s", err, stderr)
453-
return fmt.Errorf("Failed to destroy 'crc' VM")
454-
}
455-
}
456-
_, stderr, err := crcos.RunWithDefaultLocale("virsh", "--connect", "qemu:///system", "undefine", "--nvram", constants.DefaultName)
451+
_, stderr, err := m.DeleteVM(constants.DefaultName)
457452
if err != nil {
458453
logging.Debugf("%v : %s", err, stderr)
459-
return fmt.Errorf("Failed to undefine 'crc' VM")
454+
return fmt.Errorf("Failed to remove 'crc' VM")
460455
}
461456
logging.Debug("'crc' VM is removed")
462457
return nil

0 commit comments

Comments
 (0)