Skip to content

Commit

Permalink
feat : Add config option to set developer password for cluster (crc-o…
Browse files Browse the repository at this point in the history
…rg#2539)

Add option to set developer password for the user.

```
$ crc config set developer-password mypassword
$ crc start
[...]
INFO Adding crc-admin and crc-developer contexts to kubeconfig...
Started the OpenShift cluster.

The server is accessible via web console at:
  https://console-openshift-console.apps-crc.testing

Log in as user:
  Username: developer
  Password: mypassword
```

Signed-off-by: Rohan Kumar <[email protected]>
  • Loading branch information
rohanKanojia committed Jan 10, 2025
1 parent e079898 commit d068c17
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/crc/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
1 change: 1 addition & 0 deletions pkg/crc/api/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
3 changes: 3 additions & 0 deletions pkg/crc/config/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions pkg/crc/config/settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ var configDefaultValuesTestArguments = []struct {
{
KubeAdminPassword, "",
},
{
DeveloperPassword, "developer",
},
{
CPUs, uint(4),
},
Expand Down Expand Up @@ -286,6 +289,9 @@ var configProvidedValuesTestArguments = []struct {
{
KubeAdminPassword, "kubeadmin-secret-password",
},
{
DeveloperPassword, "developer-secret-password",
},
{
CPUs, uint(8),
},
Expand Down
1 change: 1 addition & 0 deletions pkg/crc/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
3 changes: 3 additions & 0 deletions pkg/crc/machine/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ type StartConfig struct {
// User defined kubeadmin password
KubeAdminPassword string

// User defined developer password
DeveloperPassword string

// Preset
Preset crcpreset.Preset

Expand Down

0 comments on commit d068c17

Please sign in to comment.