Repository: ray-project/kuberay (Go)

Issue:
[Bug] kubectl-plugin get cluster without all-namespace still shows all-namespace.
### Search before asking

- [x] I searched the [issues](https://github.com/ray-project/kuberay/issues) and found no similar issues.


### KubeRay Component

kubectl-plugin

### What happened + What you expected to happen

The `--all-namespaces` is false by default. However, it still shows the clusters under all namespaces.

<img width="1091" alt="Image" src="https://github.com/user-attachments/assets/9539b676-5f0d-421f-a005-468f6b32325d" />

### Reproduction script

Create two RayClusters in the different namespaces. And get Raycluster without specifying `--all-namespace`. The result will look like the screenshot above.
```bash
kubectl ray create cluster sample-cluster
kubectl create namespace ns01
kubectl ray create cluster ns-cluster -n ns01
kubectl ray get cluster
```

### Anything else

_No response_

### Are you willing to submit a PR?

- [x] Yes I am willing to submit a PR!


Discussion:

Patch:
diff --git a/kubectl-plugin/pkg/cmd/get/get_cluster.go b/kubectl-plugin/pkg/cmd/get/get_cluster.go
index 27dfdeeed6a..620d99c01b6 100644
--- a/kubectl-plugin/pkg/cmd/get/get_cluster.go
+++ b/kubectl-plugin/pkg/cmd/get/get_cluster.go
@@ -68,7 +68,7 @@ func (options *GetClusterOptions) Complete(args []string, cmd *cobra.Command) er
 	}
 	options.namespace = namespace
 	if options.namespace == "" {
-		options.allNamespaces = true
+		options.namespace = "default"
 	}
 
 	if len(args) >= 1 {


Test patch:
diff --git a/kubectl-plugin/pkg/cmd/get/get_cluster_test.go b/kubectl-plugin/pkg/cmd/get/get_cluster_test.go
index 2557f05610b..7f4a5dc0aa0 100644
--- a/kubectl-plugin/pkg/cmd/get/get_cluster_test.go
+++ b/kubectl-plugin/pkg/cmd/get/get_cluster_test.go
@@ -42,7 +42,7 @@ func TestRayClusterGetComplete(t *testing.T) {
 			name:                  "neither namespace nor args set",
 			namespace:             "",
 			args:                  []string{},
-			expectedAllNamespaces: true,
+			expectedAllNamespaces: false,
 			expectedCluster:       "",
 		},
 		{
@@ -56,7 +56,7 @@ func TestRayClusterGetComplete(t *testing.T) {
 			name:                  "namespace not set, args set",
 			namespace:             "",
 			args:                  []string{"foo", "bar"},
-			expectedAllNamespaces: true,
+			expectedAllNamespaces: false,
 			expectedCluster:       "foo",
 		},
 		{
@@ -223,75 +223,102 @@ func TestGetRayClusters(t *testing.T) {
 		},
 	}
 
+	defaultNamespace := "default"
+	rayClusterInDefault := &rayv1.RayCluster{
+		ObjectMeta: v1.ObjectMeta{
+			Name:      "raycluster-kuberay-default",
+			Namespace: defaultNamespace,
+		},
+	}
+
 	tests := []struct {
-		namespace      *string
-		name           string
-		expectedError  string
-		expectedOutput string
-		cluster        string
-		rayClusters    []runtime.Object
+		namespace           *string
+		name                string
+		expectedError       string
+		expectedOutput      string
+		cluster             string
+		expectedRayClusters []runtime.Object
+		allFakeRayClusters  []runtime.Object
+		allNamespaces       bool
 	}{
 		{
-			name:        "should not error if no cluster name is provided, searching all namespaces, and no clusters are found",
-			namespace:   nil,
-			rayClusters: []runtime.Object{},
+			name:                "should not error if no cluster name is provided, searching all namespaces, and no clusters are found",
+			namespace:           nil,
+			expectedRayClusters: []runtime.Object{},
+		},
+		{
+			name:                "should error if a cluster name is provided, searching all namespaces, and no clusters are found",
+			cluster:             "my-cluster",
+			namespace:           nil,
+			expectedRayClusters: []runtime.Object{},
+			expectedError:       "Ray cluster my-cluster not found",
+		},
+		{
+			name:                "should not error if no cluster name is provided, searching one namespace, and no clusters are found",
+			namespace:           &namespace,
+			expectedRayClusters: []runtime.Object{},
 		},
 		{
-			name:          "should error if a cluster name is provided, searching all namespaces, and no clusters are found",
-			cluster:       "my-cluster",
-			namespace:     nil,
-			rayClusters:   []runtime.Object{},
-			expectedError: "Ray cluster my-cluster not found",
+			name:                "should error if a cluster name is provided, searching one namespace, and no clusters are found",
+			cluster:             "my-cluster",
+			namespace:           &namespace,
+			expectedRayClusters: []runtime.Object{},
+			expectedError:       fmt.Sprintf("Ray cluster my-cluster not found in namespace %s", namespace),
 		},
 		{
-			name:        "should not error if no cluster name is provided, searching one namespace, and no clusters are found",
-			namespace:   &namespace,
-			rayClusters: []runtime.Object{},
+			name:                "should not error if no cluster name is provided, searching all namespaces, and clusters are found",
+			namespace:           nil,
+			allFakeRayClusters:  []runtime.Object{rayCluster},
+			expectedRayClusters: []runtime.Object{rayCluster},
 		},
 		{
-			name:          "should error if a cluster name is provided, searching one namespace, and no clusters are found",
-			cluster:       "my-cluster",
-			namespace:     &namespace,
-			rayClusters:   []runtime.Object{},
-			expectedError: fmt.Sprintf("Ray cluster my-cluster not found in namespace %s", namespace),
+			name:                "should not error if a cluster name is provided, searching all namespaces, and clusters are found",
+			cluster:             "my-cluster",
+			namespace:           nil,
+			allFakeRayClusters:  []runtime.Object{rayCluster},
+			expectedRayClusters: []runtime.Object{rayCluster},
 		},
 		{
-			name:        "should not error if no cluster name is provided, searching all namespaces, and clusters are found",
-			namespace:   nil,
-			rayClusters: []runtime.Object{rayCluster},
+			name:                "should not error if no cluster name is provided, searching one namespace, and clusters are found",
+			namespace:           &namespace,
+			allFakeRayClusters:  []runtime.Object{rayCluster},
+			expectedRayClusters: []runtime.Object{rayCluster},
 		},
 		{
-			name:        "should not error if a cluster name is provided, searching all namespaces, and clusters are found",
-			cluster:     "my-cluster",
-			namespace:   nil,
-			rayClusters: []runtime.Object{rayCluster},
+			name:                "should not error if a cluster name is provided, searching one namespace, and clusters are found",
+			cluster:             "my-cluster",
+			namespace:           &namespace,
+			allFakeRayClusters:  []runtime.Object{rayCluster},
+			expectedRayClusters: []runtime.Object{rayCluster},
 		},
 		{
-			name:        "should not error if no cluster name is provided, searching one namespace, and clusters are found",
-			namespace:   &namespace,
-			rayClusters: []runtime.Object{rayCluster},
+			name:                "should not error if no cluster name is provided, searching default namespace, and clusters are found",
+			namespace:           &defaultNamespace,
+			allFakeRayClusters:  []runtime.Object{rayCluster, rayClusterInDefault},
+			expectedRayClusters: []runtime.Object{rayClusterInDefault},
 		},
 		{
-			name:        "should not error if a cluster name is provided, searching one namespace, and clusters are found",
-			cluster:     "my-cluster",
-			namespace:   &namespace,
-			rayClusters: []runtime.Object{rayCluster},
+			name:                "should not error if no cluster name is provided, searching all namespace, and clusters are found",
+			allNamespaces:       true,
+			allFakeRayClusters:  []runtime.Object{rayCluster, rayClusterInDefault},
+			expectedRayClusters: []runtime.Object{rayCluster, rayClusterInDefault},
 		},
 	}
 
 	for _, tc := range tests {
 		t.Run(tc.name, func(t *testing.T) {
 			fakeClusterGetOptions := GetClusterOptions{
-				cmdFactory: cmdFactory,
-				ioStreams:  &testStreams,
-				cluster:    tc.cluster,
+				cmdFactory:    cmdFactory,
+				ioStreams:     &testStreams,
+				cluster:       tc.cluster,
+				allNamespaces: tc.allNamespaces,
 			}
 			if tc.namespace != nil {
 				fakeClusterGetOptions.namespace = *tc.namespace
 			}
 
 			kubeClientSet := kubefake.NewClientset()
-			rayClient := rayClientFake.NewSimpleClientset(tc.rayClusters...)
+			rayClient := rayClientFake.NewSimpleClientset(tc.allFakeRayClusters...)
 			k8sClients := client.NewClientForTesting(kubeClientSet, rayClient)
 
 			rayClusters, err := getRayClusters(context.Background(), &fakeClusterGetOptions, k8sClients)
@@ -302,7 +329,7 @@ func TestGetRayClusters(t *testing.T) {
 			}
 
 			require.NoError(t, err)
-			assert.Equal(t, len(tc.rayClusters), len(rayClusters.Items))
+			assert.Equal(t, len(tc.expectedRayClusters), len(rayClusters.Items))
 		})
 	}
 }