Skip to content

Commit

Permalink
Show scope path of the tanzu resource for context type tanzu
Browse files Browse the repository at this point in the history
Signed-off-by: Prem Kumar Kalle <[email protected]>
  • Loading branch information
prkalle committed Feb 4, 2025
1 parent b4a8578 commit 6dd11e8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
22 changes: 22 additions & 0 deletions pkg/command/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -1497,6 +1497,9 @@ func printContext(writer io.Writer, ctx *configtypes.Context) {
columns = append(columns, "Cluster Group")
row = append(row, resources.ClusterGroupName)
}
scopePath := getTanzuResourceScopePath(resources)
columns = append(columns, "Scope Path")
row = append(row, scopePath)
}
}

Expand All @@ -1517,6 +1520,25 @@ func printContext(writer io.Writer, ctx *configtypes.Context) {
outputWriter.Render()
}

// getTanzuResourceScopePath returns the scope path based on the ResourceInfo
// TODO: Update this function when CLI context provides support for cluster/CF resources(CF Foundation/CF Org/CF Space)
func getTanzuResourceScopePath(resources *config.ResourceInfo) string {
scopePath := ""
if resources.OrgID != "" {
scopePath += "/"
}
if resources.ProjectName != "" {
scopePath += "projects/" + resources.ProjectName
}
if resources.SpaceName != "" {
scopePath += "/spaces/" + resources.SpaceName
} else if resources.ClusterGroupName != "" {
scopePath += "/clustergroups/" + resources.ClusterGroupName
}

return scopePath
}

func newDeleteCtxCmd() *cobra.Command {
var deleteCtxCmd = &cobra.Command{
Use: "delete CONTEXT_NAME",
Expand Down
4 changes: 4 additions & 0 deletions pkg/command/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1860,6 +1860,7 @@ func TestContextCurrentCmd(t *testing.T) {
Type: tanzu
Organization: org-name (org-id)
Project: none set
Scope Path: /
Kube Config: /home/user/.kube/config
Kube Context: kube-context-name
`,
Expand All @@ -1877,6 +1878,7 @@ func TestContextCurrentCmd(t *testing.T) {
Type: tanzu
Organization: org-name (org-id)
Project: project-name (project-id)
Scope Path: /projects/project-name
Kube Config: /home/user/.kube/config
Kube Context: kube-context-name
`,
Expand All @@ -1895,6 +1897,7 @@ func TestContextCurrentCmd(t *testing.T) {
Organization: org-name (org-id)
Project: project-name (project-id)
Space: space-name
Scope Path: /projects/project-name/spaces/space-name
Kube Config: /home/user/.kube/config
Kube Context: kube-context-name
`,
Expand All @@ -1913,6 +1916,7 @@ func TestContextCurrentCmd(t *testing.T) {
Organization: org-name (org-id)
Project: project-name (project-id)
Cluster Group: clustergroup-name
Scope Path: /projects/project-name/clustergroups/clustergroup-name
Kube Config: /home/user/.kube/config
Kube Context: kube-context-name
`,
Expand Down

0 comments on commit 6dd11e8

Please sign in to comment.