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

feat: tree option in output flag for app get and app resources cli command for tree view(#13370) #15386

Merged
merged 15 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
82 changes: 27 additions & 55 deletions cmd/argocd/commands/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,27 @@ func parentChildDetails(appIf application.ApplicationServiceClient, ctx context.
}

}
return
return mapUidToNode, mapParentToChild, parentNode
}

func commonOutputFunctionality(acdClient argocdclient.Client, app *argoappv1.Application, ctx context.Context, windows *argoappv1.SyncWindows, showOperation bool, showParams bool) {
schakrad marked this conversation as resolved.
Show resolved Hide resolved
aURL := appURL(ctx, acdClient, app.Name)
printAppSummaryTable(app, aURL, windows)

if len(app.Status.Conditions) > 0 {
fmt.Println()
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
printAppConditions(w, app)
_ = w.Flush()
fmt.Println()
}
if showOperation && app.Status.OperationState != nil {
fmt.Println()
printOperationResult(app.Status.OperationState)
}
if showParams {
printParams(app)
}
}

// NewApplicationGetCommand returns a new instance of an `argocd app get` command
Expand Down Expand Up @@ -333,74 +353,26 @@ func NewApplicationGetCommand(clientOpts *argocdclient.ClientOptions) *cobra.Com
err := PrintResource(app, output)
errors.CheckError(err)
case "wide", "":
aURL := appURL(ctx, acdClient, app.Name)
printAppSummaryTable(app, aURL, windows)

if len(app.Status.Conditions) > 0 {
fmt.Println()
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
printAppConditions(w, app)
_ = w.Flush()
fmt.Println()
}
if showOperation && app.Status.OperationState != nil {
fmt.Println()
printOperationResult(app.Status.OperationState)
}
if showParams {
printParams(app)
}

commonOutputFunctionality(acdClient, app, ctx, windows, showOperation, showParams)
if len(app.Status.Resources) > 0 {
fmt.Println()
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
printAppResources(w, app)
_ = w.Flush()
}
case "tree":
schakrad marked this conversation as resolved.
Show resolved Hide resolved
aURL := appURL(ctx, acdClient, app.Name)
printAppSummaryTable(app, aURL, windows)

if len(app.Status.Conditions) > 0 {
fmt.Println()
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
printAppConditions(w, app)
_ = w.Flush()
fmt.Println()
}
if showOperation && app.Status.OperationState != nil {
fmt.Println()
printOperationResult(app.Status.OperationState)
}
if showParams {
printParams(app)
}
commonOutputFunctionality(acdClient, app, ctx, windows, showOperation, showParams)
mapUidToNode, mapParentToChild, parentNode := parentChildDetails(appIf, ctx, appName, appNs)
mapNodeNameToResourceState := make(map[string]*resourceState)
for _, res := range getResourceStates(app, nil) {
mapNodeNameToResourceState[res.Kind+"/"+res.Name] = res
}
if len(mapUidToNode) > 0 {
fmt.Println()
printTreeView(mapUidToNode, mapParentToChild, parentNode, mapNodeNameToResourceState)
}
case "tree=detailed":
aURL := appURL(ctx, acdClient, app.Name)
printAppSummaryTable(app, aURL, windows)

if len(app.Status.Conditions) > 0 {
fmt.Println()
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
printAppConditions(w, app)
_ = w.Flush()
fmt.Println()
}
if showOperation && app.Status.OperationState != nil {
fmt.Println()
printOperationResult(app.Status.OperationState)
}
if showParams {
printParams(app)
}
commonOutputFunctionality(acdClient, app, ctx, windows, showOperation, showParams)
mapUidToNode, mapParentToChild, parentNode := parentChildDetails(appIf, ctx, appName, appNs)
mapNodeNameToResourceState := make(map[string]*resourceState)
for _, res := range getResourceStates(app, nil) {
Expand Down Expand Up @@ -505,12 +477,12 @@ func NewApplicationLogsCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co
command.Flags().StringVar(&kind, "kind", "", "Resource kind")
command.Flags().StringVar(&namespace, "namespace", "", "Resource namespace")
command.Flags().StringVar(&resourceName, "name", "", "Resource name")
command.Flags().BoolVar(&follow, "follow", false, "Specify if the logs should be streamed")
command.Flags().BoolVarP(&follow, "follow", "f", false, "Specify if the logs should be streamed")
command.Flags().Int64Var(&tail, "tail", 0, "The number of lines from the end of the logs to show")
command.Flags().Int64Var(&sinceSeconds, "since-seconds", 0, "A relative time in seconds before the current time from which to show logs")
command.Flags().StringVar(&untilTime, "until-time", "", "Show logs until this time")
command.Flags().StringVar(&filter, "filter", "", "Show logs contain this string")
command.Flags().StringVar(&container, "container", "", "Optional container name")
command.Flags().StringVarP(&container, "container", "c", "", "Optional container name")
command.Flags().BoolVarP(&previous, "previous", "p", false, "Specify if the previously terminated container logs should be returned")

return command
Expand Down
2 changes: 1 addition & 1 deletion cmd/argocd/commands/app_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func parentChildInfo(nodes []v1alpha1.ResourceNode) (mapUidToNode map[string]v1a
parentNode[node.UID] = struct{}{}
}
}
return
return mapUidToNode, mapParentToChild, parentNode
schakrad marked this conversation as resolved.
Show resolved Hide resolved
}

func printDetailedTreeViewAppResourcesNotOrphaned(nodeMapping map[string]v1alpha1.ResourceNode, parentChildMapping map[string][]string, parentNodes map[string]struct{}, orphaned bool, listAll bool, w *tabwriter.Writer) {
Expand Down
4 changes: 2 additions & 2 deletions docs/user-guide/commands/argocd_app_logs.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ argocd app logs APPNAME [flags]
### Options
schakrad marked this conversation as resolved.
Show resolved Hide resolved

```
--container string Optional container name
-c, --container string Optional container name
--filter string Show logs contain this string
--follow Specify if the logs should be streamed
-f, --follow Specify if the logs should be streamed
--group string Resource group
-h, --help help for logs
--kind string Resource kind
Expand Down
Loading