Skip to content

Commit 5e4a2e3

Browse files
cfergeaupraveenkumar
authored andcommitted
Issue #439: Add preflight check to remove system-wide crc-driver-libvirt
It's now installed in ~/.crc/bin, so we need to cleanup the older binary we were installing systemwide in /usr/local/bin. This needs to be done with sudo, hence why this is done during crc setup This is related to #439
1 parent 274948c commit 5e4a2e3

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

pkg/crc/preflight/preflight_checks_linux.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,32 @@ func fixMachineDriverLibvirtInstalled() (bool, error) {
248248
return true, nil
249249
}
250250

251+
/* These 2 checks can be removed after a few releases */
252+
func checkOldMachineDriverLibvirtInstalled() (bool, error) {
253+
logging.Debugf("Checking if an older libvirt driver %s is installed", libvirtDriverCommand)
254+
oldLibvirtDriverPath := filepath.Join("/usr/local/bin/", libvirtDriverCommand)
255+
if _, err := os.Stat(oldLibvirtDriverPath); !os.IsNotExist(err) {
256+
return false, fmt.Errorf("Found old system-wide crc-machine-driver binary")
257+
}
258+
logging.Debugf("No older %s installation found", libvirtDriverCommand)
259+
260+
return true, nil
261+
}
262+
263+
func fixOldMachineDriverLibvirtInstalled() (bool, error) {
264+
oldLibvirtDriverPath := filepath.Join("/usr/local/bin/", libvirtDriverCommand)
265+
logging.Debugf("Removing %s", oldLibvirtDriverPath)
266+
_, _, err := crcos.RunWithPrivilege("rm", "-f", oldLibvirtDriverPath)
267+
if err != nil {
268+
logging.Debugf("Removal of %s failed", oldLibvirtDriverPath)
269+
/* Ignoring error, an obsolete file being still present is not a fatal error */
270+
} else {
271+
logging.Debugf("%s successfully removed", oldLibvirtDriverPath)
272+
}
273+
274+
return true, nil
275+
}
276+
251277
func checkLibvirtCrcNetworkAvailable() (bool, error) {
252278
logging.Debug("Checking if libvirt 'crc' network exists")
253279
stdOut, stdErr, err := crcos.RunWithDefaultLocale("virsh", "--connect", "qemu:///system", "net-list")

pkg/crc/preflight/preflight_linux.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ func SetupHost(vmDriver string) {
124124
"Installing crc-driver-libvirt",
125125
config.GetBool(cmdConfig.WarnCheckLibvirtDriver.Name),
126126
)
127+
preflightCheckAndFix(false,
128+
checkOldMachineDriverLibvirtInstalled,
129+
fixOldMachineDriverLibvirtInstalled,
130+
"Removing older system-wide crc-driver-libvirt",
131+
false,
132+
)
127133
preflightCheckAndFix(config.GetBool(cmdConfig.SkipCheckCrcNetwork.Name),
128134
checkLibvirtCrcNetworkAvailable,
129135
fixLibvirtCrcNetworkAvailable,

0 commit comments

Comments
 (0)