Repository: crc-org/crc (Go)

Issue:
[BUG] `crc console` gives incorrect output on microshift preset
### General information

I was testing some stuff on microshift cluster related to https://github.com/crc-org/docs/issues/16 . However, I noticed that `crc console` isn't giving the correct output for microshift preset:

When I do plain `crc console`, it's opening up file explorer in current directory instead of browser
```shell
PS C:\Users\rokum\go\src\github.com\crc-org\docs> crc console
Opening the OpenShift Web Console in the default browser... # Opens File explorer instead
```

When I try to list credentials, it's showing incomplete command:
```shell
PS C:\Users\rokum\go\src\github.com\crc-org\docs> crc console --credentials
To login as a regular user, run 'oc login -u developer -p developer '.
To login as an admin, run 'oc login -u kubeadmin -p  '
```

### Operating System

Windows

### Hypervisor

Hyper-V

### Did you run `crc setup` before `crc start`?

yes

### Running on

Laptop

### Steps to reproduce

1. `crc config set preset microshift`
2. `crc setup`
3. `crc start`
4. `crc console` # Opens up file explorer on windows
5. `crc console --credentials` # Gives incomplete output

### CRC version

```shell
CRC version: 2.45.0+7aeb3b
OpenShift version: 4.17.7
MicroShift version: 4.17.7
```

### CRC status

```shell
PS C:\Users\rokum\go\src\github.com\crc-org\docs> crc status
CRC VM:                  Running
MicroShift:              Running (v4.17.7)
RAM Usage:               5.015GB of 16.1GB
Disk Usage:              1.722GB of 4.095GB (Inside the CRC VM)
Persistent Volume Usage: 0B of 15GB (Allocated)
Cache Usage:             57.62GB
Cache Directory:         C:\Users\rokum\.crc\cache
```

### CRC config

```shell
- consent-telemetry                     : yes
- preset                                : microshift
```

### Host Operating System

```shell
Host Name:                 ROKUMAR-LENOVO
OS Name:                   Microsoft Windows 11 Pro
OS Version:                10.0.22631 N/A Build 22631
OS Manufacturer:           Microsoft Corporation
OS Configuration:          Standalone Workstation
OS Build Type:             Multiprocessor Free
Registered Organization:
Product ID:                00330-81616-56784-AA418
Original Install Date:     17-12-2024, 07:05:25
System Boot Time:          09-01-2025, 14:51:05
System Manufacturer:       LENOVO
System Model:              20Y4S1QE0P
System Type:               x64-based PC
Processor(s):              1 Processor(s) Installed.
                           [01]: Intel64 Family 6 Model 141 Stepping 1 GenuineIntel ~2496 Mhz
BIOS Version:              LENOVO N40ET34W (1.16 ), 08-04-2022
Windows Directory:         C:\Windows
System Directory:          C:\Windows\system32
Boot Device:               \Device\HarddiskVolume1
System Locale:             en-us;English (United States)
Input Locale:              00004009
Time Zone:                 (UTC+05:30) Chennai, Kolkata, Mumbai, New Delhi
Total Physical Memory:     65,239 MB
Available Physical Memory: 43,050 MB
Virtual Memory: Max Size:  74,967 MB
Virtual Memory: Available: 52,608 MB
Virtual Memory: In Use:    22,359 MB
Page File Location(s):     C:\pagefile.sys
Domain:                    WORKGROUP
Logon Server:              \\ROKUMAR-LENOVO
Hotfix(s):                 4 Hotfix(s) Installed.
                           [01]: KB5045935
                           [02]: KB5027397
                           [03]: KB5048685
                           [04]: KB5046729
Network Card(s):           6 NIC(s) Installed.
                           [01]: Intel(R) Wi-Fi 6E AX210 160MHz
                                 Connection Name: Wi-Fi
                                 Status:          Media disconnected
                           [02]: Bluetooth Device (Personal Area Network)
                                 Connection Name: Bluetooth Network Connection
                                 Status:          Media disconnected
                           [03]: Lenovo USB Ethernet
                                 Connection Name: Ethernet
                                 DHCP Enabled:    Yes
                                 DHCP Server:     192.168.29.1
                                 IP address(es)
                                 [01]: 192.168.29.207
                                 [02]: fe80::47f5:672f:9a66:4036
                                 [03]: 2405:201:5004:a8c3:8d30:d232:1977:afef
                                 [04]: 2405:201:5004:a8c3:770a:f24a:3d73:c1e7
                           [04]: Wintun Userspace Tunnel
                                 Connection Name: OpenVPN Wintun
                                 Status:          Media disconnected
                           [05]: TAP-Windows Adapter V9
                                 Connection Name: OpenVPN TAP-Windows6
                                 Status:          Media disconnected
                           [06]: OpenVPN Data Channel Offload
                                 Connection Name: OpenVPN Data Channel Offload
                                 Status:          Media disconnected
Hyper-V Requirements:      A hypervisor has been detected. Features required for Hyper-V will not be displayed.
```

### Expected behavior

if this option is unsupported, we should throw an exception with a clear message that this subcommand is unsupported on this preset.

### Actual behavior

CRC prints wrong command output

### CRC Logs

```shell

```

### Additional context

_No response_


Discussion:

Patch:
diff --git a/cmd/crc/cmd/console.go b/cmd/crc/cmd/console.go
index bdd5c6a385..a21d939200 100644
--- a/cmd/crc/cmd/console.go
+++ b/cmd/crc/cmd/console.go
@@ -6,6 +6,8 @@ import (
 	"io"
 	"os"
 
+	"github.com/crc-org/crc/v2/pkg/crc/preset"
+
 	"github.com/crc-org/crc/v2/pkg/crc/api/client"
 	"github.com/crc-org/crc/v2/pkg/crc/daemonclient"
 	crcErrors "github.com/crc-org/crc/v2/pkg/crc/errors"
@@ -44,6 +46,9 @@ func showConsole(client *daemonclient.Client) (*client.ConsoleResult, error) {
 
 func runConsole(writer io.Writer, client *daemonclient.Client, consolePrintURL, consolePrintCredentials bool, outputFormat string) error {
 	result, err := showConsole(client)
+	if err == nil && result.ClusterConfig.ClusterType == preset.Microshift {
+		err = fmt.Errorf("error : this option is only supported for %s and %s preset", preset.OpenShift, preset.OKD)
+	}
 	return render(&consoleResult{
 		Success:                 err == nil,
 		state:                   toState(result),


Test patch:
diff --git a/cmd/crc/cmd/console_test.go b/cmd/crc/cmd/console_test.go
index 0910dfb809..d17359b621 100644
--- a/cmd/crc/cmd/console_test.go
+++ b/cmd/crc/cmd/console_test.go
@@ -6,6 +6,8 @@ import (
 	"fmt"
 	"testing"
 
+	"github.com/crc-org/crc/v2/pkg/crc/preset"
+
 	apiTypes "github.com/crc-org/crc/v2/pkg/crc/api/client"
 	"github.com/crc-org/crc/v2/pkg/crc/daemonclient"
 	"github.com/crc-org/crc/v2/pkg/crc/machine/fakemachine"
@@ -15,19 +17,14 @@ import (
 	"github.com/stretchr/testify/assert"
 )
 
-var DummyClusterConfig = types.ClusterConfig{
-	ClusterType:   "openshift",
-	ClusterCACert: "MIIDODCCAiCgAwIBAgIIRVfCKNUa1wIwDQYJ",
-	KubeConfig:    "/tmp/kubeconfig",
-	KubeAdminPass: "foobar",
-	ClusterAPI:    "https://foo.testing:6443",
-	WebConsoleURL: "https://console.foo.testing:6443",
-	ProxyConfig:   nil,
+func setUpClientForConsole(t *testing.T) *daemonclient.Client {
+	return setUpClientForConsoleWithPreset(t, preset.OpenShift)
 }
 
-func setUpClientForConsole(t *testing.T) *daemonclient.Client {
+func setUpClientForConsoleWithPreset(t *testing.T, preset preset.Preset) *daemonclient.Client {
 	client := mocks.NewClient(t)
 
+	DummyClusterConfig := createDummyClusterConfig(preset)
 	client.On("WebconsoleURL").Return(
 		&apiTypes.ConsoleResult{
 			ClusterConfig: DummyClusterConfig,
@@ -38,6 +35,18 @@ func setUpClientForConsole(t *testing.T) *daemonclient.Client {
 	}
 }
 
+func createDummyClusterConfig(preset preset.Preset) types.ClusterConfig {
+	return types.ClusterConfig{
+		ClusterType:   preset,
+		ClusterCACert: "MIIDODCCAiCgAwIBAgIIRVfCKNUa1wIwDQYJ",
+		KubeConfig:    "/tmp/kubeconfig",
+		KubeAdminPass: "foobar",
+		ClusterAPI:    "https://foo.testing:6443",
+		WebConsoleURL: "https://console.foo.testing:6443",
+		ProxyConfig:   nil,
+	}
+}
+
 func setUpFailingClientForConsole(t *testing.T) *daemonclient.Client {
 	client := mocks.NewClient(t)
 
@@ -106,3 +115,12 @@ func TestConsoleJSONError(t *testing.T) {
 	assert.NoError(t, runConsole(out, setUpFailingClientForConsole(t), false, false, jsonFormat))
 	assert.JSONEq(t, `{"error":"console failed", "success":false}`, out.String())
 }
+
+func TestConsoleThrowsErrorInMicroShiftPreset(t *testing.T) {
+	// Given
+	out := new(bytes.Buffer)
+	// When
+	err := runConsole(out, setUpClientForConsoleWithPreset(t, preset.Microshift), false, false, "")
+	// Then
+	assert.EqualError(t, err, fmt.Sprintf("error : this option is only supported for %s and %s preset", preset.OpenShift, preset.OKD))
+}