Skip to content

feat(cli): add structured output formatting (-o json/yaml) - #1925

Draft
dolliecoder wants to merge 1 commit into
kmesh-net:mainfrom
dolliecoder:feature/kmeshctl-structured-output
Draft

feat(cli): add structured output formatting (-o json/yaml)#1925
dolliecoder wants to merge 1 commit into
kmesh-net:mainfrom
dolliecoder:feature/kmeshctl-structured-output

Conversation

@dolliecoder

Copy link
Copy Markdown

What type of PR is this?

/kind feature

What this PR does / why we need it:
This PR introduces structured output formatting to kmeshctl, a highly requested quality-of-life feature for DevOps engineers and CI/CD pipelines.

Currently, kmeshctl commands output data strictly as plain-text tables or strings, making it difficult to parse programmatically. This PR:

  1. Adds a global --output (or -o) persistent flag to the root kmeshctl command.
  2. Introduces a centralized ctl/utils/printer.go utility to marshal internal Go structs into JSON or YAML seamlessly.
  3. Refactors the authz status, log, and secret get commands to natively support structured output via the new printer.

When the -o json or -o yaml flag is omitted, the CLI gracefully falls back to the exact same human-readable table/text formats as before, ensuring 100% backward compatibility.

Which issue(s) this PR fixes:
Fixes #1924

Special notes for your reviewer:
The sigs.k8s.io/yaml and encoding/json libraries are leveraged within printer.go for the struct marshaling. We've ensured that internal data structures (like PodStatus in the authz command) have their fields correctly exported and tagged with json:"" decorators so they serialize cleanly.

Does this PR introduce a user-facing change?:

Added `--output json` and `--output yaml` (or `-o`) flags to `kmeshctl` commands to support structured, machine-readable output formatting.

Signed-off-by: dolliecoder <dollychahar27@gmail.com>
@kmesh-bot

Copy link
Copy Markdown
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign nlgwcy for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enhancement: Bring the Magic of Structured Output (-o json/yaml) to kmeshctl

2 participants