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

Add support for json output in inject and uninject commands #12600

Merged
merged 3 commits into from
May 21, 2024

Conversation

adleong
Copy link
Member

@adleong adleong commented May 16, 2024

We add support for the --output/-o flag in linkerd inject and linkerd uninject commands. The supported output formats are yaml (default) and json. Kubectl is able to accept both of these formats which means that linkerd inject and linkerd uninject output can be piped into kubectl regardless of which output format is used.

@adleong adleong requested a review from a team as a code owner May 16, 2024 02:22
Comment on lines 273 to 275
type lineReader struct {
reader *bufio.Reader
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I can see, this reader only admits a single-line json, which is very limiting. Instead, how about assuming first the input is json, try unmarhalling, and if that fails, fallback to using the yaml reader?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only reason we needed to be able to handle json input here at all is because we perform an uninject step before injecting and the uninject was producing json output when -o json was specified (which meant that we needed to handle json input during inject).

I've updated this so that the uninject that happens as a first step to inject will always produce yaml as its (intermediate) output so that we don't need to add json input support at all.

Copy link
Member

@alpeb alpeb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice solution!

@adleong adleong merged commit 10b1a7a into main May 21, 2024
39 checks passed
@adleong adleong deleted the alex/inject-json branch May 21, 2024 23:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants