From ab9136012d4ebe8bd2f9c9d55edcde0bab59dd46 Mon Sep 17 00:00:00 2001 From: Christophe Fergeau Date: Wed, 17 May 2023 10:36:05 +0200 Subject: [PATCH] version: Add GetDefaultPreset() This will allow to override it at compile-time when needed. I changed the default preset in the configuration code, but I did not check if it was used in other places. This will help with https://github.com/crc-org/crc/issues/3637 --- pkg/crc/config/settings.go | 2 +- pkg/crc/version/version.go | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/pkg/crc/config/settings.go b/pkg/crc/config/settings.go index 68daefa9ed..3215a84546 100644 --- a/pkg/crc/config/settings.go +++ b/pkg/crc/config/settings.go @@ -70,7 +70,7 @@ func RegisterSettings(cfg *Config) { } // Preset setting should be on top because CPUs/Memory config depend on it. - cfg.AddSetting(Preset, string(preset.OpenShift), validatePreset, RequiresDeleteAndSetupMsg, + cfg.AddSetting(Preset, version.GetDefaultPreset().String(), validatePreset, RequiresDeleteAndSetupMsg, fmt.Sprintf("Virtual machine preset (valid values are: %s)", preset.AllPresets())) // Start command settings in config cfg.AddSetting(Bundle, defaultBundlePath(cfg), validateBundlePath, SuccessfullyApplied, BundleHelpMsg(cfg)) diff --git a/pkg/crc/version/version.go b/pkg/crc/version/version.go index 3889fa7c07..d03b16c210 100644 --- a/pkg/crc/version/version.go +++ b/pkg/crc/version/version.go @@ -35,6 +35,8 @@ var ( // will be true for releases on macos and windows // will be false for git builds on macos and windows installerBuild = "false" + + defaultPreset = "openshift" ) const ( @@ -140,3 +142,12 @@ func GetCRCLatestVersionFromMirror(transport http.RoundTripper) (*CrcReleaseInfo return &releaseInfo, nil } + +func GetDefaultPreset() crcPreset.Preset { + preset, err := crcPreset.ParsePresetE(defaultPreset) + if err != nil { + // defaultPreset is set at compile-time, it should *never* be invalid + panic(fmt.Sprintf("Invalid compilet-time default preset '%s'", defaultPreset)) + } + return preset +}