Skip to content

Commit

Permalink
preflight: add check to remove podman from ~/.crc/bin/oc
Browse files Browse the repository at this point in the history
  • Loading branch information
anjannath authored and praveenkumar committed Mar 8, 2024
1 parent 012cf33 commit 4026f7f
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 5 deletions.
29 changes: 29 additions & 0 deletions pkg/crc/preflight/preflight_checks_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
1 change: 1 addition & 0 deletions pkg/crc/preflight/preflight_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down
1 change: 1 addition & 0 deletions pkg/crc/preflight/preflight_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down
12 changes: 12 additions & 0 deletions pkg/crc/preflight/preflight_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ var checkListForDistros = []checkListForDistro{
{check: checkSupportedCPUArch},
{check: checkCrcSymlink},
{configKeySuffix: "check-ram"},
{check: checkPodmanInOcBinDir},
{cleanup: removeCRCMachinesDir},
{cleanup: removeAllLogs},
{cleanup: cluster.ForgetPullSecret},
Expand Down Expand Up @@ -109,6 +110,7 @@ var checkListForDistros = []checkListForDistro{
{check: checkSupportedCPUArch},
{check: checkCrcSymlink},
{configKeySuffix: "check-ram"},
{check: checkPodmanInOcBinDir},
{cleanup: removeCRCMachinesDir},
{cleanup: removeAllLogs},
{cleanup: cluster.ForgetPullSecret},
Expand Down Expand Up @@ -147,6 +149,7 @@ var checkListForDistros = []checkListForDistro{
{check: checkSupportedCPUArch},
{check: checkCrcSymlink},
{configKeySuffix: "check-ram"},
{check: checkPodmanInOcBinDir},
{cleanup: removeCRCMachinesDir},
{cleanup: removeAllLogs},
{cleanup: cluster.ForgetPullSecret},
Expand Down Expand Up @@ -179,6 +182,7 @@ var checkListForDistros = []checkListForDistro{
{check: checkSupportedCPUArch},
{check: checkCrcSymlink},
{configKeySuffix: "check-ram"},
{check: checkPodmanInOcBinDir},
{cleanup: removeCRCMachinesDir},
{cleanup: removeAllLogs},
{cleanup: cluster.ForgetPullSecret},
Expand Down Expand Up @@ -218,6 +222,7 @@ var checkListForDistros = []checkListForDistro{
{check: checkSupportedCPUArch},
{check: checkCrcSymlink},
{configKeySuffix: "check-ram"},
{check: checkPodmanInOcBinDir},
{cleanup: removeCRCMachinesDir},
{cleanup: removeAllLogs},
{cleanup: cluster.ForgetPullSecret},
Expand Down Expand Up @@ -256,6 +261,7 @@ var checkListForDistros = []checkListForDistro{
{check: checkSupportedCPUArch},
{check: checkCrcSymlink},
{configKeySuffix: "check-ram"},
{check: checkPodmanInOcBinDir},
{cleanup: removeCRCMachinesDir},
{cleanup: removeAllLogs},
{cleanup: cluster.ForgetPullSecret},
Expand Down Expand Up @@ -288,6 +294,7 @@ var checkListForDistros = []checkListForDistro{
{check: checkSupportedCPUArch},
{check: checkCrcSymlink},
{configKeySuffix: "check-ram"},
{check: checkPodmanInOcBinDir},
{cleanup: removeCRCMachinesDir},
{cleanup: removeAllLogs},
{cleanup: cluster.ForgetPullSecret},
Expand Down Expand Up @@ -327,6 +334,7 @@ var checkListForDistros = []checkListForDistro{
{check: checkSupportedCPUArch},
{check: checkCrcSymlink},
{configKeySuffix: "check-ram"},
{check: checkPodmanInOcBinDir},
{cleanup: removeCRCMachinesDir},
{cleanup: removeAllLogs},
{cleanup: cluster.ForgetPullSecret},
Expand Down Expand Up @@ -365,6 +373,7 @@ var checkListForDistros = []checkListForDistro{
{check: checkSupportedCPUArch},
{check: checkCrcSymlink},
{configKeySuffix: "check-ram"},
{check: checkPodmanInOcBinDir},
{cleanup: removeCRCMachinesDir},
{cleanup: removeAllLogs},
{cleanup: cluster.ForgetPullSecret},
Expand Down Expand Up @@ -397,6 +406,7 @@ var checkListForDistros = []checkListForDistro{
{check: checkSupportedCPUArch},
{check: checkCrcSymlink},
{configKeySuffix: "check-ram"},
{check: checkPodmanInOcBinDir},
{cleanup: removeCRCMachinesDir},
{cleanup: removeAllLogs},
{cleanup: cluster.ForgetPullSecret},
Expand Down Expand Up @@ -437,6 +447,7 @@ var checkListForDistros = []checkListForDistro{
{check: checkSupportedCPUArch},
{check: checkCrcSymlink},
{configKeySuffix: "check-ram"},
{check: checkPodmanInOcBinDir},
{cleanup: removeCRCMachinesDir},
{cleanup: removeAllLogs},
{cleanup: cluster.ForgetPullSecret},
Expand Down Expand Up @@ -476,6 +487,7 @@ var checkListForDistros = []checkListForDistro{
{check: checkSupportedCPUArch},
{check: checkCrcSymlink},
{configKeySuffix: "check-ram"},
{check: checkPodmanInOcBinDir},
{cleanup: removeCRCMachinesDir},
{cleanup: removeAllLogs},
{cleanup: cluster.ForgetPullSecret},
Expand Down
1 change: 1 addition & 0 deletions pkg/crc/preflight/preflight_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions pkg/crc/preflight/preflight_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 4026f7f

Please sign in to comment.