Skip to content

Commit 1c2cde0

Browse files
authored
Merge pull request #3728 from olamilekan000/add-workspace-clusterid-to-workspace-i
add workspace clusterID when in interactive mode
2 parents a578b7f + 5285aec commit 1c2cde0

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

staging/src/github.com/kcp-dev/cli/pkg/workspace/plugin/interactive.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package plugin
1818

1919
import (
20+
"fmt"
2021
"strings"
2122

2223
tea "github.com/charmbracelet/bubbletea"
@@ -126,6 +127,9 @@ func (m model) View() string {
126127
}
127128
detailParts = append(detailParts, typeRef)
128129
}
130+
if m.currentNode.info.Cluster != "" {
131+
detailParts = append(detailParts, fmt.Sprintf("cluster:%s", m.currentNode.info.Cluster))
132+
}
129133
details = detailStyle.Render(strings.Join(detailParts, " | "))
130134
}
131135

staging/src/github.com/kcp-dev/cli/pkg/workspace/plugin/tree.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ import (
3838

3939
// workspaceInfo contains workspace path and type information.
4040
type workspaceInfo struct {
41-
Path logicalcluster.Path
42-
Type *tenancyv1alpha1.WorkspaceTypeReference
41+
Path logicalcluster.Path
42+
Type *tenancyv1alpha1.WorkspaceTypeReference
43+
Cluster string
4344
}
4445

4546
// TreeOptions contains options for displaying the workspace tree.
@@ -170,17 +171,25 @@ func (o *TreeOptions) runInteractive(ctx context.Context, currentWorkspace logic
170171

171172
func (o *TreeOptions) populateInteractiveNodeBubble(ctx context.Context, node *treeNode, workspace logicalcluster.Path, workspaceName string, currentWorkspace logicalcluster.Path, currentNode **treeNode) error {
172173
var workspaceType *tenancyv1alpha1.WorkspaceTypeReference
174+
var workspaceCluster string
173175
if parent, hasParent := workspace.Parent(); hasParent {
174176
workspaceBaseName := workspace.Base()
175177
ws, err := o.kcpClusterClient.Cluster(parent).TenancyV1alpha1().Workspaces().Get(ctx, workspaceBaseName, metav1.GetOptions{})
176-
if err == nil && ws.Spec.Type != nil {
177-
workspaceType = ws.Spec.Type
178+
if err == nil {
179+
if ws.Spec.Type != nil {
180+
workspaceType = ws.Spec.Type
181+
}
182+
workspaceCluster = ws.Spec.Cluster
178183
}
179184
}
185+
if workspaceCluster == "" {
186+
workspaceCluster = workspace.Base()
187+
}
180188

181189
wsInfo := &workspaceInfo{
182-
Path: workspace,
183-
Type: workspaceType,
190+
Path: workspace,
191+
Type: workspaceType,
192+
Cluster: workspaceCluster,
184193
}
185194

186195
node.info = wsInfo
@@ -210,8 +219,9 @@ func (o *TreeOptions) populateInteractiveNodeBubble(ctx context.Context, node *t
210219
}
211220

212221
childWorkspaceInfo := &workspaceInfo{
213-
Path: childPath,
214-
Type: ws.Spec.Type,
222+
Path: childPath,
223+
Type: ws.Spec.Type,
224+
Cluster: ws.Spec.Cluster,
215225
}
216226

217227
childNode := &treeNode{

0 commit comments

Comments
 (0)