Skip to content

Commit

Permalink
preflight: add missing minimum memory check for windows
Browse files Browse the repository at this point in the history
this moves the memory check from the unix platform specific go file
to the common preflight checks file to ensure it runs for all three
platform
  • Loading branch information
anjannath authored and praveenkumar committed May 8, 2023
1 parent 9dfd795 commit 31f0f27
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 30 deletions.
15 changes: 15 additions & 0 deletions pkg/crc/preflight/preflight_checks_common.go
Expand Up @@ -13,6 +13,7 @@ import (
crcpreset "github.com/crc-org/crc/pkg/crc/preset"
"github.com/crc-org/crc/pkg/crc/ssh"
"github.com/crc-org/crc/pkg/crc/validation"
"github.com/docker/go-units"
"github.com/pkg/errors"
)

Expand All @@ -29,6 +30,20 @@ func bundleCheck(bundlePath string, preset crcpreset.Preset) Check {
}
}

func memoryCheck(preset crcpreset.Preset) Check {
return Check{
configKeySuffix: "check-ram",
checkDescription: "Checking minimum RAM requirements",
check: func() error {
return validation.ValidateEnoughMemory(constants.GetDefaultMemory(preset))
},
fixDescription: fmt.Sprintf("crc requires at least %s to run", units.HumanSize(float64(constants.GetDefaultMemory(preset)*1024*1024))),
flags: NoFix,

labels: None,
}
}

var genericCleanupChecks = []Check{
{
cleanupDescription: "Removing CRC Machine Instance directory",
Expand Down
13 changes: 0 additions & 13 deletions pkg/crc/preflight/preflight_checks_unix.go
Expand Up @@ -15,10 +15,8 @@ import (
"github.com/crc-org/crc/pkg/crc/constants"
"github.com/crc-org/crc/pkg/crc/logging"
crcpreset "github.com/crc-org/crc/pkg/crc/preset"
"github.com/crc-org/crc/pkg/crc/validation"
"github.com/crc-org/crc/pkg/crc/version"
crcos "github.com/crc-org/crc/pkg/os"
"github.com/docker/go-units"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -55,17 +53,6 @@ func genericPreflightChecks(preset crcpreset.Preset) []Check {

labels: None,
},
{
configKeySuffix: "check-ram",
checkDescription: "Checking minimum RAM requirements",
check: func() error {
return validation.ValidateEnoughMemory(constants.GetDefaultMemory(preset))
},
fixDescription: fmt.Sprintf("crc requires at least %s to run", units.HumanSize(float64(constants.GetDefaultMemory(preset)*1024*1024))),
flags: NoFix,

labels: None,
},
{
configKeySuffix: "check-crc-symlink",
checkDescription: "Checking if crc executable symlink exists",
Expand Down
1 change: 1 addition & 0 deletions pkg/crc/preflight/preflight_darwin.go
Expand Up @@ -107,6 +107,7 @@ func getChecks(mode network.Mode, bundlePath string, preset crcpreset.Preset) []

checks = append(checks, nonWinPreflightChecks...)
checks = append(checks, genericPreflightChecks(preset)...)
checks = append(checks, memoryCheck(preset))
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
Expand Up @@ -367,6 +367,7 @@ func getChecks(distro *linux.OsRelease, bundlePath string, preset crcpreset.Pres
checks = append(checks, nonWinPreflightChecks...)
checks = append(checks, wsl2PreflightCheck)
checks = append(checks, genericPreflightChecks(preset)...)
checks = append(checks, memoryCheck(preset))
checks = append(checks, genericCleanupChecks...)
checks = append(checks, libvirtPreflightChecks(distro)...)
checks = append(checks, ubuntuPreflightChecks...)
Expand Down
24 changes: 12 additions & 12 deletions pkg/crc/preflight/preflight_linux_test.go
Expand Up @@ -68,8 +68,8 @@ var checkListForDistros = []checkListForDistro{
{check: checkRunningInsideWSL2},
{check: checkAdminHelperExecutableCached},
{check: checkSupportedCPUArch},
{configKeySuffix: "check-ram"},
{check: checkCrcSymlink},
{configKeySuffix: "check-ram"},
{cleanup: removeCRCMachinesDir},
{cleanup: removeOldLogs},
{cleanup: cluster.ForgetPullSecret},
Expand Down Expand Up @@ -107,8 +107,8 @@ var checkListForDistros = []checkListForDistro{
{check: checkRunningInsideWSL2},
{check: checkAdminHelperExecutableCached},
{check: checkSupportedCPUArch},
{configKeySuffix: "check-ram"},
{check: checkCrcSymlink},
{configKeySuffix: "check-ram"},
{cleanup: removeCRCMachinesDir},
{cleanup: removeOldLogs},
{cleanup: cluster.ForgetPullSecret},
Expand Down Expand Up @@ -145,8 +145,8 @@ var checkListForDistros = []checkListForDistro{
{check: checkRunningInsideWSL2},
{check: checkAdminHelperExecutableCached},
{check: checkSupportedCPUArch},
{configKeySuffix: "check-ram"},
{check: checkCrcSymlink},
{configKeySuffix: "check-ram"},
{cleanup: removeCRCMachinesDir},
{cleanup: removeOldLogs},
{cleanup: cluster.ForgetPullSecret},
Expand Down Expand Up @@ -177,8 +177,8 @@ var checkListForDistros = []checkListForDistro{
{check: checkRunningInsideWSL2},
{check: checkAdminHelperExecutableCached},
{check: checkSupportedCPUArch},
{configKeySuffix: "check-ram"},
{check: checkCrcSymlink},
{configKeySuffix: "check-ram"},
{cleanup: removeCRCMachinesDir},
{cleanup: removeOldLogs},
{cleanup: cluster.ForgetPullSecret},
Expand Down Expand Up @@ -216,8 +216,8 @@ var checkListForDistros = []checkListForDistro{
{check: checkRunningInsideWSL2},
{check: checkAdminHelperExecutableCached},
{check: checkSupportedCPUArch},
{configKeySuffix: "check-ram"},
{check: checkCrcSymlink},
{configKeySuffix: "check-ram"},
{cleanup: removeCRCMachinesDir},
{cleanup: removeOldLogs},
{cleanup: cluster.ForgetPullSecret},
Expand Down Expand Up @@ -254,8 +254,8 @@ var checkListForDistros = []checkListForDistro{
{check: checkRunningInsideWSL2},
{check: checkAdminHelperExecutableCached},
{check: checkSupportedCPUArch},
{configKeySuffix: "check-ram"},
{check: checkCrcSymlink},
{configKeySuffix: "check-ram"},
{cleanup: removeCRCMachinesDir},
{cleanup: removeOldLogs},
{cleanup: cluster.ForgetPullSecret},
Expand Down Expand Up @@ -286,8 +286,8 @@ var checkListForDistros = []checkListForDistro{
{check: checkRunningInsideWSL2},
{check: checkAdminHelperExecutableCached},
{check: checkSupportedCPUArch},
{configKeySuffix: "check-ram"},
{check: checkCrcSymlink},
{configKeySuffix: "check-ram"},
{cleanup: removeCRCMachinesDir},
{cleanup: removeOldLogs},
{cleanup: cluster.ForgetPullSecret},
Expand Down Expand Up @@ -325,8 +325,8 @@ var checkListForDistros = []checkListForDistro{
{check: checkRunningInsideWSL2},
{check: checkAdminHelperExecutableCached},
{check: checkSupportedCPUArch},
{configKeySuffix: "check-ram"},
{check: checkCrcSymlink},
{configKeySuffix: "check-ram"},
{cleanup: removeCRCMachinesDir},
{cleanup: removeOldLogs},
{cleanup: cluster.ForgetPullSecret},
Expand Down Expand Up @@ -363,8 +363,8 @@ var checkListForDistros = []checkListForDistro{
{check: checkRunningInsideWSL2},
{check: checkAdminHelperExecutableCached},
{check: checkSupportedCPUArch},
{configKeySuffix: "check-ram"},
{check: checkCrcSymlink},
{configKeySuffix: "check-ram"},
{cleanup: removeCRCMachinesDir},
{cleanup: removeOldLogs},
{cleanup: cluster.ForgetPullSecret},
Expand Down Expand Up @@ -395,8 +395,8 @@ var checkListForDistros = []checkListForDistro{
{check: checkRunningInsideWSL2},
{check: checkAdminHelperExecutableCached},
{check: checkSupportedCPUArch},
{configKeySuffix: "check-ram"},
{check: checkCrcSymlink},
{configKeySuffix: "check-ram"},
{cleanup: removeCRCMachinesDir},
{cleanup: removeOldLogs},
{cleanup: cluster.ForgetPullSecret},
Expand Down Expand Up @@ -435,8 +435,8 @@ var checkListForDistros = []checkListForDistro{
{check: checkRunningInsideWSL2},
{check: checkAdminHelperExecutableCached},
{check: checkSupportedCPUArch},
{configKeySuffix: "check-ram"},
{check: checkCrcSymlink},
{configKeySuffix: "check-ram"},
{cleanup: removeCRCMachinesDir},
{cleanup: removeOldLogs},
{cleanup: cluster.ForgetPullSecret},
Expand Down Expand Up @@ -474,8 +474,8 @@ var checkListForDistros = []checkListForDistro{
{check: checkRunningInsideWSL2},
{check: checkAdminHelperExecutableCached},
{check: checkSupportedCPUArch},
{configKeySuffix: "check-ram"},
{check: checkCrcSymlink},
{configKeySuffix: "check-ram"},
{cleanup: removeCRCMachinesDir},
{cleanup: removeOldLogs},
{cleanup: cluster.ForgetPullSecret},
Expand Down
1 change: 1 addition & 0 deletions pkg/crc/preflight/preflight_windows.go
Expand Up @@ -193,6 +193,7 @@ func getAllPreflightChecks() []Check {

func getChecks(bundlePath string, preset crcpreset.Preset) []Check {
checks := []Check{}
checks = append(checks, memoryCheck(preset))
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
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(), 12)
assert.Len(t, cfg.AllConfigs(), 13)
}

func TestCountPreflights(t *testing.T) {
assert.Len(t, getPreflightChecks(false, network.SystemNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift), 19)
assert.Len(t, getPreflightChecks(true, network.SystemNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift), 19)
assert.Len(t, getPreflightChecks(false, network.SystemNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift), 20)
assert.Len(t, getPreflightChecks(true, network.SystemNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift), 20)

assert.Len(t, getPreflightChecks(false, network.UserNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift), 18)
assert.Len(t, getPreflightChecks(true, network.UserNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift), 18)
assert.Len(t, getPreflightChecks(false, network.UserNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift), 19)
assert.Len(t, getPreflightChecks(true, network.UserNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift), 19)
}

0 comments on commit 31f0f27

Please sign in to comment.