diff --git a/pkg/crc/preflight/preflight_checks_common.go b/pkg/crc/preflight/preflight_checks_common.go index 63d26112ad..6d7e62d63b 100644 --- a/pkg/crc/preflight/preflight_checks_common.go +++ b/pkg/crc/preflight/preflight_checks_common.go @@ -155,3 +155,32 @@ func removeAllLogs() error { func removeCRCHostEntriesFromKnownHosts() error { return ssh.RemoveCRCHostEntriesFromKnownHosts() } + +func checkPodmanInOcBinDir() error { + podmanBinPath := filepath.Join(constants.CrcOcBinDir, constants.PodmanRemoteExecutableName) + if crcos.FileExists(podmanBinPath) { + return fmt.Errorf("Found podman executable: %s", podmanBinPath) + } + return nil +} + +func fixPodmanInOcBinDir() error { + podmanBinPath := filepath.Join(constants.CrcOcBinDir, constants.PodmanRemoteExecutableName) + if crcos.FileExists(podmanBinPath) { + logging.Debugf("Removing podman binary at: %s", podmanBinPath) + return os.Remove(podmanBinPath) + } + return nil +} + +func removePodmanFromOcBinDirCheck() Check { + return Check{ + configKeySuffix: "check-podman-in-ocbindir", + checkDescription: fmt.Sprintf("Check if Podman binary exists in: %s", constants.CrcOcBinDir), + check: checkPodmanInOcBinDir, + fixDescription: fmt.Sprintf("Removing Podman binary from: %s", constants.CrcOcBinDir), + fix: fixPodmanInOcBinDir, + + labels: None, + } +} diff --git a/pkg/crc/preflight/preflight_darwin.go b/pkg/crc/preflight/preflight_darwin.go index b4d963d11c..05b419eb23 100644 --- a/pkg/crc/preflight/preflight_darwin.go +++ b/pkg/crc/preflight/preflight_darwin.go @@ -120,6 +120,7 @@ func getChecks(_ network.Mode, bundlePath string, preset crcpreset.Preset, enabl checks = append(checks, nonWinPreflightChecks...) checks = append(checks, genericPreflightChecks(preset)...) checks = append(checks, memoryCheck(preset)) + checks = append(checks, removePodmanFromOcBinDirCheck()) checks = append(checks, genericCleanupChecks...) checks = append(checks, vfkitPreflightChecks...) checks = append(checks, resolverPreflightChecks...) diff --git a/pkg/crc/preflight/preflight_linux.go b/pkg/crc/preflight/preflight_linux.go index 1a010337b3..46c7100d39 100644 --- a/pkg/crc/preflight/preflight_linux.go +++ b/pkg/crc/preflight/preflight_linux.go @@ -368,6 +368,7 @@ func getChecks(distro *linux.OsRelease, bundlePath string, preset crcpreset.Pres checks = append(checks, wsl2PreflightCheck) checks = append(checks, genericPreflightChecks(preset)...) checks = append(checks, memoryCheck(preset)) + checks = append(checks, removePodmanFromOcBinDirCheck()) checks = append(checks, genericCleanupChecks...) checks = append(checks, libvirtPreflightChecks(distro)...) checks = append(checks, ubuntuPreflightChecks...) diff --git a/pkg/crc/preflight/preflight_linux_test.go b/pkg/crc/preflight/preflight_linux_test.go index 21de2ccfc8..0eb2db015e 100644 --- a/pkg/crc/preflight/preflight_linux_test.go +++ b/pkg/crc/preflight/preflight_linux_test.go @@ -70,6 +70,7 @@ var checkListForDistros = []checkListForDistro{ {check: checkSupportedCPUArch}, {check: checkCrcSymlink}, {configKeySuffix: "check-ram"}, + {check: checkPodmanInOcBinDir}, {cleanup: removeCRCMachinesDir}, {cleanup: removeAllLogs}, {cleanup: cluster.ForgetPullSecret}, @@ -109,6 +110,7 @@ var checkListForDistros = []checkListForDistro{ {check: checkSupportedCPUArch}, {check: checkCrcSymlink}, {configKeySuffix: "check-ram"}, + {check: checkPodmanInOcBinDir}, {cleanup: removeCRCMachinesDir}, {cleanup: removeAllLogs}, {cleanup: cluster.ForgetPullSecret}, @@ -147,6 +149,7 @@ var checkListForDistros = []checkListForDistro{ {check: checkSupportedCPUArch}, {check: checkCrcSymlink}, {configKeySuffix: "check-ram"}, + {check: checkPodmanInOcBinDir}, {cleanup: removeCRCMachinesDir}, {cleanup: removeAllLogs}, {cleanup: cluster.ForgetPullSecret}, @@ -179,6 +182,7 @@ var checkListForDistros = []checkListForDistro{ {check: checkSupportedCPUArch}, {check: checkCrcSymlink}, {configKeySuffix: "check-ram"}, + {check: checkPodmanInOcBinDir}, {cleanup: removeCRCMachinesDir}, {cleanup: removeAllLogs}, {cleanup: cluster.ForgetPullSecret}, @@ -218,6 +222,7 @@ var checkListForDistros = []checkListForDistro{ {check: checkSupportedCPUArch}, {check: checkCrcSymlink}, {configKeySuffix: "check-ram"}, + {check: checkPodmanInOcBinDir}, {cleanup: removeCRCMachinesDir}, {cleanup: removeAllLogs}, {cleanup: cluster.ForgetPullSecret}, @@ -256,6 +261,7 @@ var checkListForDistros = []checkListForDistro{ {check: checkSupportedCPUArch}, {check: checkCrcSymlink}, {configKeySuffix: "check-ram"}, + {check: checkPodmanInOcBinDir}, {cleanup: removeCRCMachinesDir}, {cleanup: removeAllLogs}, {cleanup: cluster.ForgetPullSecret}, @@ -288,6 +294,7 @@ var checkListForDistros = []checkListForDistro{ {check: checkSupportedCPUArch}, {check: checkCrcSymlink}, {configKeySuffix: "check-ram"}, + {check: checkPodmanInOcBinDir}, {cleanup: removeCRCMachinesDir}, {cleanup: removeAllLogs}, {cleanup: cluster.ForgetPullSecret}, @@ -327,6 +334,7 @@ var checkListForDistros = []checkListForDistro{ {check: checkSupportedCPUArch}, {check: checkCrcSymlink}, {configKeySuffix: "check-ram"}, + {check: checkPodmanInOcBinDir}, {cleanup: removeCRCMachinesDir}, {cleanup: removeAllLogs}, {cleanup: cluster.ForgetPullSecret}, @@ -365,6 +373,7 @@ var checkListForDistros = []checkListForDistro{ {check: checkSupportedCPUArch}, {check: checkCrcSymlink}, {configKeySuffix: "check-ram"}, + {check: checkPodmanInOcBinDir}, {cleanup: removeCRCMachinesDir}, {cleanup: removeAllLogs}, {cleanup: cluster.ForgetPullSecret}, @@ -397,6 +406,7 @@ var checkListForDistros = []checkListForDistro{ {check: checkSupportedCPUArch}, {check: checkCrcSymlink}, {configKeySuffix: "check-ram"}, + {check: checkPodmanInOcBinDir}, {cleanup: removeCRCMachinesDir}, {cleanup: removeAllLogs}, {cleanup: cluster.ForgetPullSecret}, @@ -437,6 +447,7 @@ var checkListForDistros = []checkListForDistro{ {check: checkSupportedCPUArch}, {check: checkCrcSymlink}, {configKeySuffix: "check-ram"}, + {check: checkPodmanInOcBinDir}, {cleanup: removeCRCMachinesDir}, {cleanup: removeAllLogs}, {cleanup: cluster.ForgetPullSecret}, @@ -476,6 +487,7 @@ var checkListForDistros = []checkListForDistro{ {check: checkSupportedCPUArch}, {check: checkCrcSymlink}, {configKeySuffix: "check-ram"}, + {check: checkPodmanInOcBinDir}, {cleanup: removeCRCMachinesDir}, {cleanup: removeAllLogs}, {cleanup: cluster.ForgetPullSecret}, diff --git a/pkg/crc/preflight/preflight_windows.go b/pkg/crc/preflight/preflight_windows.go index b6e96c40c7..7d39c4a9ad 100644 --- a/pkg/crc/preflight/preflight_windows.go +++ b/pkg/crc/preflight/preflight_windows.go @@ -212,6 +212,7 @@ func getAllPreflightChecks() []Check { func getChecks(bundlePath string, preset crcpreset.Preset, enableBundleQuayFallback bool) []Check { checks := []Check{} checks = append(checks, memoryCheck(preset)) + checks = append(checks, removePodmanFromOcBinDirCheck()) checks = append(checks, hypervPreflightChecks...) checks = append(checks, crcUsersGroupExistsCheck) checks = append(checks, userPartOfCrcUsersAndHypervAdminsGroupCheck) diff --git a/pkg/crc/preflight/preflight_windows_test.go b/pkg/crc/preflight/preflight_windows_test.go index 603222d6ac..b0b7834d79 100644 --- a/pkg/crc/preflight/preflight_windows_test.go +++ b/pkg/crc/preflight/preflight_windows_test.go @@ -13,13 +13,13 @@ import ( func TestCountConfigurationOptions(t *testing.T) { cfg := config.New(config.NewEmptyInMemoryStorage(), config.NewEmptyInMemorySecretStorage()) RegisterSettings(cfg) - assert.Len(t, cfg.AllConfigs(), 15) + assert.Len(t, cfg.AllConfigs(), 16) } func TestCountPreflights(t *testing.T) { - assert.Len(t, getPreflightChecks(false, network.SystemNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false), 23) - assert.Len(t, getPreflightChecks(true, network.SystemNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false), 23) + assert.Len(t, getPreflightChecks(false, network.SystemNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false), 24) + assert.Len(t, getPreflightChecks(true, network.SystemNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false), 24) - assert.Len(t, getPreflightChecks(false, network.UserNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false), 22) - assert.Len(t, getPreflightChecks(true, network.UserNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false), 22) + assert.Len(t, getPreflightChecks(false, network.UserNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false), 23) + assert.Len(t, getPreflightChecks(true, network.UserNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false), 23) }