-
Notifications
You must be signed in to change notification settings - Fork 38.7k
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
Structured output for 'kubeadm token list' #78764
Structured output for 'kubeadm token list' #78764
Conversation
/cc @akutz |
/cc @kubernetes/sig-cluster-lifecycle-pr-reviews |
/test pull-kubernetes-bazel-test |
81e8f11
to
4b2eace
Compare
/test pull-kubernetes-e2e-gce |
4b2eace
to
27afe7e
Compare
3faf861
to
eabc575
Compare
lgtm from my side, however question: should the output of bootstrap token in parsable form to be compatible with something that can be used directly in joinconfig? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @bart0sh !
Looks good for a start. I propose to reuse the corresponding types from the config (when possible).
} | ||
|
||
// Info is a wrapper around klog.Info | ||
func (tp TextPrinter) Info(level klog.Level, args ...interface{}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think we should either only have Infof or both Info and Infof.
also we need Warning(f).
this however raises another question.
users would expected structured output to go to STDOUT.
klog goes to STDERR, so do we need to wrap it with the structured output printer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added Infof.
structured output is handled only by PrintObj. Info* calls are silenced in the current implementation. I'm ok to make them loud if other reviewers agree. It would create a bit messy console output though.
@bart0sh i will do another pass myself at some point. |
6701279
to
64746be
Compare
@neolit123 Thank you for the review! |
/test pull-kubernetes-kubemark-e2e-gce-big |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @bart0sh !
Looks good for a start. Mostly naming stuff that seems to need fixing and logging.
// KubeadmOutputFlags composes common printer flag structs | ||
// used across kubeadm commands, and provides a method | ||
// of retrieving a known printer based on flag values provided. | ||
type KubeadmOutputFlags struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/KubeadmOutputFlags/OutputContext ? Sounds better and shorted. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*Flags suffix is used in the cli-runtime code. I'd rather use their naming convention.
P.S.: Would s/OutputFlags/OutputPrintFlags/ go? cli runtime uses PrintFlags suffix, so this way it would be even closer to their names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but the structure seems to contain more than just flags?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it contains flags and additional fields to serve its second purpose that's mentioned in the comment - to retrive a printer based on the flag values.
|
||
if kof.JSONYamlPrintFlags != nil { | ||
if p, err := kof.JSONYamlPrintFlags.ToPrinter(outputFormat); !genericclioptions.IsNoCompatiblePrinterError(err) { | ||
return NewResourcePrinterWrapper(kof.TypeSetterPrinter.WrapToPrinter(p, err)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not clear at first sight, that the actual error, when ToPrinter
fails, is correctly propagated and returned to the caller. The error plumbing here can be made more easy to see. Let's split this up into helpers with the more verbose (but clear) way of just returning the errors when they happen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This approach was also taken from the cli-runtime code I used it this way just to not reinvent the wheel and be consistent with their implementation.
Let me know if you insist on using helpers - I'll modify the code.
This group contains APIs for handling kubeadm structured output.
5793066
to
b482930
Compare
/test pull-kubernetes-kubemark-e2e-gce-big |
Added internal structures and APIs to handle kubeadm structured output.
Used cli-runtime API to print bootstrap tokens in 5 formats: - TEXT (identical to the current output) - YAML - JSON - JSONPATH - Go template
Tested JSON, YAML, Go Template and Text token output formats.
b482930
to
ba0c84a
Compare
@bart0sh Thanks for your great job on this PR! |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: bart0sh, fabriziopandini The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@fabriziopandini Thank you very much for approving this PR! There will be more of this kind as soon as this one is merged. |
voting on final merge on this PR during today's office hours. |
/lgtm |
…tured-output-v2 Structured output for 'kubeadm token list'
What type of PR is this?
/kind feature
What this PR does / why we need it:
This is an initial implementation of kubeadm structured output described in this KEP
It adds new api group output.kubeadm.k8s.io to define versioned structured output and implements
output in TEXT, JSON, YAML, Go template and JSONPATH for
kubeadm token list
command using cli-runtime printer APIs.Example output:
Does this PR introduce a user-facing change?: