Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix (console) : Throw error for crc console configured with MicroShift preset (#4561) #4576

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmd/crc/cmd/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 not supported for microshift preset. Please refer to the documentation for a list of supported presets for using this option")
}
return render(&consoleResult{
Success: err == nil,
state: toState(result),
Expand Down
36 changes: 27 additions & 9 deletions cmd/crc/cmd/console_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
Expand All @@ -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)

Expand Down Expand Up @@ -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, "error : this option is not supported for microshift preset. Please refer to the documentation for a list of supported presets for using this option")
}
Loading