vmware-tanzu / tanzu-framework

Tanzu Framework provides a set of building blocks to build atop of the Tanzu platform and leverages Carvel packaging and plugins to provide users with a much stronger, more integrated experience than the loose coupling and stand-alone commands of the previous generation of tools.
Apache License 2.0
197 stars 194 forks source link

`tanzu cluster list` call is not behaving as expected #1510

Open rajaskakodkar opened 2 years ago

rajaskakodkar commented 2 years ago

Bug description

tanzu cluster list call is not behaving as expected. Some errors returned as stderr like below:

tanzu cluster list --include-management-cluster --output=json 
result.stderr:Downloading the TKG Bill of Materials (BOM) file from 'projects-stg.registry.vmware.com/tkg/sandbox/bom/389829566966811173/tkg-bom:v1.6.0-tf-v0.15.0' 
Downloading the TKr Bill of Materials (BOM) file from 'projects-stg.registry.vmware.com/tkg/sandbox/bom/389829566966811173/tkr-bom:v1.22.3_vmware.1-tkg.2-tf-v0.15.0'

Affected product area (please put an X in all that apply)

Expected behavior

tanzu cluster list should return Downloading of TKG BOM to stdout instead of stderr

Steps to reproduce the bug

Create a management-cluster preferably on AWS and a workload cluster and run tanzu cluster list --include-management-cluster --output=json

Version (include the SHA if the version is not obvious) 52af51fc81daccc180cb874ef7b21f959da3167d

Environment where the bug was observed (cloud, OS, etc) Cloud: AWS

Relevant Debug Output (Logs, manifests, etc)

stmcginnis commented 2 years ago

tanzu cluster list should return Downloading of TKG BOM to stdout instead of stderr

I would think especially with --output=json, this would not be the desired behavior. That would mix the progress information with the JSON response of a command, which would mess up any piped operations to something like jq.

I think the bigger issue is that something like cluster list is even emitting anything to do with downloading a BOM.

klxfeiyang commented 2 years ago

For some additional context, it looks like all console output goes to stderr instead of stdout as a result of this line:

https://github.com/vmware-tanzu/tanzu-framework/blob/main/pkg/v1/tkg/log/writer.go#L112-L115

According to @anujc25:

Currently there are multiple types of outputs we are writing. Regular output (like the actual result command in table, json, yaml format) goes to stdout . Whereas any log lines (info, warning, error) goes to stderr. Because it would be quite hard to distinguish between normal flow output like command output (in table, json, yaml format) and normal log lines that was used to redirect from stdout.

It appears that as part of the cluster list operation, bom file downloading is treated as INFO, and thereby outputted to stderr.