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

Show scope path of the tanzu resource for context type tanzu #852

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
24 changes: 24 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,27 @@ 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 == "" {
return scopePath
}
prkalle marked this conversation as resolved.
Show resolved Hide resolved
// set org scope path as global scope "/" and update the path based on resource hierarchy
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