diff --git a/cmd/crc/cmd/start.go b/cmd/crc/cmd/start.go index e33d1fba2b..c8e9779e20 100644 --- a/cmd/crc/cmd/start.go +++ b/cmd/crc/cmd/start.go @@ -75,6 +75,7 @@ func runStart(ctx context.Context) (*types.StartResult, error) { NameServer: config.Get(crcConfig.NameServer).AsString(), PullSecret: cluster.NewInteractivePullSecretLoader(config), KubeAdminPassword: config.Get(crcConfig.KubeAdminPassword).AsString(), + DeveloperPassword: config.Get(crcConfig.DeveloperPassword).AsString(), Preset: crcConfig.GetPreset(config), IngressHTTPPort: config.Get(crcConfig.IngressHTTPPort).AsUInt(), IngressHTTPSPort: config.Get(crcConfig.IngressHTTPSPort).AsUInt(), diff --git a/pkg/crc/api/handlers.go b/pkg/crc/api/handlers.go index 82221f6620..870abf0621 100644 --- a/pkg/crc/api/handlers.go +++ b/pkg/crc/api/handlers.go @@ -127,6 +127,7 @@ func getStartConfig(cfg crcConfig.Storage, args client.StartConfig) types.StartC NameServer: cfg.Get(crcConfig.NameServer).AsString(), PullSecret: cluster.NewNonInteractivePullSecretLoader(cfg, args.PullSecretFile), KubeAdminPassword: cfg.Get(crcConfig.KubeAdminPassword).AsString(), + DeveloperPassword: cfg.Get(crcConfig.DeveloperPassword).AsString(), IngressHTTPPort: cfg.Get(crcConfig.IngressHTTPPort).AsUInt(), IngressHTTPSPort: cfg.Get(crcConfig.IngressHTTPSPort).AsUInt(), Preset: crcConfig.GetPreset(cfg), diff --git a/pkg/crc/config/settings.go b/pkg/crc/config/settings.go index d4236d6a5c..ce44450014 100644 --- a/pkg/crc/config/settings.go +++ b/pkg/crc/config/settings.go @@ -29,6 +29,7 @@ const ( ConsentTelemetry = "consent-telemetry" EnableClusterMonitoring = "enable-cluster-monitoring" KubeAdminPassword = "kubeadmin-password" + DeveloperPassword = "developer-password" Preset = "preset" EnableSharedDirs = "enable-shared-dirs" SharedDirPassword = "shared-dir-password" // #nosec G101 @@ -134,6 +135,8 @@ func RegisterSettings(cfg *Config) { cfg.AddSetting(KubeAdminPassword, "", validateString, SuccessfullyApplied, "User defined kubeadmin password") + cfg.AddSetting(DeveloperPassword, constants.DefaultDeveloperPassword, validateString, SuccessfullyApplied, + "User defined developer password") cfg.AddSetting(IngressHTTPPort, constants.OpenShiftIngressHTTPPort, validatePort, RequiresHTTPPortChangeWarning, fmt.Sprintf("HTTP port to use for OpenShift ingress/routes on the host (1024-65535, default: %d)", constants.OpenShiftIngressHTTPPort)) cfg.AddSetting(IngressHTTPSPort, constants.OpenShiftIngressHTTPSPort, validatePort, RequiresHTTPSPortChangeWarning, diff --git a/pkg/crc/config/settings_test.go b/pkg/crc/config/settings_test.go index f815ed5644..eb2c89132f 100644 --- a/pkg/crc/config/settings_test.go +++ b/pkg/crc/config/settings_test.go @@ -182,3 +182,205 @@ func TestPath(t *testing.T) { IsSecret: false, }, cfg.Get(ProxyCAFile)) } + +func TestWhenInvalidKeySetThenErrorIsThrown(t *testing.T) { + // Given + cfg, err := newInMemoryConfig() + require.NoError(t, err) + + // When + Then + _, err = cfg.Set("i-dont-exist", "i-should-not-be-set") + assert.Error(t, err, "Configuration property 'i-dont-exist' does not exist") +} + +func TestSetDeveloperPasswordIsSetInConfig(t *testing.T) { + // Given + cfg, err := newInMemoryConfig() + require.NoError(t, err) + + // When + _, err = cfg.Set(DeveloperPassword, "secret-developer-password") + require.NoError(t, err) + + // Then + assert.Equal(t, SettingValue{ + Value: "secret-developer-password", + Invalid: false, + }, cfg.Get(DeveloperPassword)) +} + +var configDefaultValuesTestArguments = []struct { + key string + defaultValue interface{} +}{ + { + KubeAdminPassword, "", + }, + { + DeveloperPassword, "developer", + }, + { + CPUs, uint(4), + }, + { + Memory, uint(10752), + }, + { + DiskSize, 31, + }, + { + NameServer, "", + }, + { + PullSecretFile, "", + }, + { + DisableUpdateCheck, false, + }, + { + ExperimentalFeatures, false, + }, + { + EmergencyLogin, false, + }, + { + PersistentVolumeSize, 15, + }, + { + HostNetworkAccess, false, + }, + { + HTTPProxy, "", + }, + { + HTTPSProxy, "", + }, + { + NoProxy, "", + }, + { + ProxyCAFile, Path(""), + }, + { + EnableClusterMonitoring, false, + }, + { + ConsentTelemetry, "", + }, + { + IngressHTTPPort, 80, + }, + { + IngressHTTPSPort, 443, + }, + { + EnableBundleQuayFallback, false, + }, + { + Preset, "openshift", + }, +} + +func TestDefaultKeyValuesSetInConfig(t *testing.T) { + for _, tt := range configDefaultValuesTestArguments { + t.Run(tt.key, func(t *testing.T) { + // Given + cfg, err := newInMemoryConfig() + require.NoError(t, err) + + // When + Then + assert.Equal(t, SettingValue{ + Value: tt.defaultValue, + Invalid: false, + IsDefault: true, + }, cfg.Get(tt.key)) + }) + } +} + +var configProvidedValuesTestArguments = []struct { + key string + providedValue interface{} +}{ + { + KubeAdminPassword, "kubeadmin-secret-password", + }, + { + DeveloperPassword, "developer-secret-password", + }, + { + CPUs, uint(8), + }, + { + Memory, uint(21504), + }, + { + DiskSize, 62, + }, + { + NameServer, "127.0.0.1", + }, + { + DisableUpdateCheck, true, + }, + { + ExperimentalFeatures, true, + }, + { + EmergencyLogin, true, + }, + { + PersistentVolumeSize, 20, + }, + { + HTTPProxy, "http://proxy-via-http-proxy-property:3128", + }, + { + HTTPSProxy, "https://proxy-via-http-proxy-property:3128", + }, + { + NoProxy, "http://no-proxy-property:3128", + }, + { + EnableClusterMonitoring, true, + }, + { + ConsentTelemetry, "yes", + }, + { + IngressHTTPPort, 8080, + }, + { + IngressHTTPSPort, 6443, + }, + { + EnableBundleQuayFallback, true, + }, + { + Preset, "microshift", + }, +} + +func TestSetProvidedValuesOverrideDefaultValuesInConfig(t *testing.T) { + for _, tt := range configProvidedValuesTestArguments { + t.Run(tt.key, func(t *testing.T) { + + // When + Then + + // Given + cfg, err := newInMemoryConfig() + require.NoError(t, err) + + // When + _, err = cfg.Set(tt.key, tt.providedValue) + require.NoError(t, err) + + // Then + assert.Equal(t, SettingValue{ + Value: tt.providedValue, + Invalid: false, + IsDefault: false, + }, cfg.Get(tt.key)) + }) + } +} diff --git a/pkg/crc/constants/constants.go b/pkg/crc/constants/constants.go index c76afb6ee3..7bd2db7566 100644 --- a/pkg/crc/constants/constants.go +++ b/pkg/crc/constants/constants.go @@ -30,6 +30,7 @@ const ( BackgroundLauncherURL = "https://github.com/crc-org/win32-background-launcher/releases/download/v%s/win32-background-launcher.exe" DefaultBundleURLBase = "https://mirror.openshift.com/pub/openshift-v4/clients/crc/bundles/%s/%s/%s" DefaultContext = "admin" + DefaultDeveloperPassword = "developer" DaemonHTTPEndpoint = "http://unix/api" DaemonVsockPort = 1024 DefaultPodmanNamedPipe = `\\.\pipe\crc-podman` diff --git a/pkg/crc/machine/types/types.go b/pkg/crc/machine/types/types.go index ef810a7218..1e8c1e48ea 100644 --- a/pkg/crc/machine/types/types.go +++ b/pkg/crc/machine/types/types.go @@ -26,6 +26,9 @@ type StartConfig struct { // User defined kubeadmin password KubeAdminPassword string + // User defined developer password + DeveloperPassword string + // Preset Preset crcpreset.Preset