-
Notifications
You must be signed in to change notification settings - Fork 39.6k
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 json,yaml output format support to kubectl create, kubectl apply #38112
Add json,yaml output format support to kubectl create, kubectl apply #38112
Conversation
Can a kubernetes member verify that this patch is reasonable to test? If so, please reply with "@k8s-bot ok to test" on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands will still work. Regular contributors should join the org to skip this step.
If you have questions or suggestions related to this bot's behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.
|
func decodeUnstructuredObject(obj runtime.Object) (runtime.Object, bool) { | ||
switch obj.(type) { | ||
case *runtime.UnstructuredList, *runtime.Unstructured, *runtime.Unknown: | ||
if objBytes, err := runtime.Encode(api.Codecs.LegacyCodec(), obj); err == nil { |
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 looks very, very wrong. What are you trying to do?
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 looks very, very wrong. What are you trying to do?
I'm attempting to convert to a known type, I used this implementation in filter.go as an example.
Is the output what I sent or what I got back. I expect it to be what I got back. |
Why would I want to do that? The whole point of these commands is to be generic if possible. |
if I did not convert the object here, however another solution in the downstream PR was also to just output something like |
I'd rather see the conversion contained in something like the printer that knows what it cares about. As we move GET to the server, this should fall out of the flow |
@kubernetes/kubectl |
Thanks for the feedback. It looks like |
@juanvallejo Do you have another PR to fix the similar issue with |
@ymqytw
Sorry about that, I had forgotten to address this. Will add as part of this PR. Thanks! |
63c4d8b
to
1112a57
Compare
@ymqytw Sample output
|
@@ -251,6 +251,20 @@ func RunApply(f cmdutil.Factory, cmd *cobra.Command, out io.Writer, options *App | |||
} | |||
|
|||
count++ | |||
if len(output) > 0 && !shortOutput { |
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.
Please extract this code into pkg/kubectl
- appears to be identical across all three.
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.
@smarterclayton done! extracted this out to kubectl/cmd/util/printing.go
PTAL
if err != nil { | ||
return err | ||
} | ||
return printer.PrintObj(info.Object, out) |
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 don't need this line.
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 line is using the printer declared in line 142 although I realize that this entire part could read a bit better. I'll go ahead and rename the printer
declared inside of the !generic || printer == nil
block to something a bit more specific, like nonGenericPrinter
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.
@ymqytw
This line is using the printer declared in line 142 although I realize that this entire part could read a bit better. I'll go ahead and rename the printer declared inside of the !generic || printer == nil block to something a bit more specific, like nonGenericPrinter
Sorry, misunderstood which line you were pointing out. I see what you mean, I'll go ahead and update. Please ignore the above comment.
This PR should have a release note, since it changes the output behavior. |
66f3121
to
3249527
Compare
@ymqytw
Added a release note |
@fabianofranz or @ymqytw Is this patch okay to test? Thanks! |
@k8s-bot ok to test |
Jenkins GCE e2e failed for commit 29e65475f4460f9c362c79c689b73f28c3e1fa22. Full PR test history. The magic incantation to run this job again is |
Jenkins GCI GCE e2e failed for commit 29e65475f4460f9c362c79c689b73f28c3e1fa22. Full PR test history. The magic incantation to run this job again is |
29e6547
to
3916587
Compare
Jenkins verification failed for commit 29e65475f4460f9c362c79c689b73f28c3e1fa22. Full PR test history. The magic incantation to run this job again is |
This patch adds the ability to specify an output format other than "name" to `kubectl create ...`. It can be used in conjunction with the `--dry-run` option. Converts unstructured objects into known types in order to support all `--output` values.
3916587
to
cbe4790
Compare
@ymqytw or @deads2k are there any more comments on this patch? Thanks! |
The description still isn't clear to me. Is this showing me what was submitted or what was actually created (returned from the API). You definitely need tests. Also, the printing API needs a significant overhaul. I'll let @fabianofranz decide what order things need to happen. I think this reduces overall readability. |
Thanks, went ahead and updated the description to clarify this. The printed objects are the ones returned from the server. If an info is returned and does not yet exist in the server (and the |
@fabianofranz I agree that adding another helper to handle printing resources does not feel completely right. The reason why the new helper PrintResourceInfoForCommand was added in this PR was to handle cases where Maybe this is something that could be added to the kubectl umbrella issue for printers? |
Added #38779 to the printers and describers umbrella. I agree it needs a significant overhaul which we are proposing to do after an analysis of the existing issues, but let's do that in a separate effort. |
Any other comments here? |
@k8s-bot bazel test this |
Automatic merge from submit-queue |
This fixes kubernetes#38779. This allows us to avoid case in which printers.GetStandardPrinter returns nil for both printer and err removing any potential panics that may arise throughout kubectl commands. Please see kubernetes#38779 and kubernetes#38112 for complete context. Add comment explaining adding handlers to printers.HumanReadablePrinter also remove an unnecessary conversion of printers.HumanReadablePrinter to printers.ResourcePrinter.
Automatic merge from submit-queue (batch tested with PRs 41563, 45251, 46265, 46462, 46721) Denote if a printer is generic. This fixes #38779. This allows us to avoid case in which printers.GetStandardPrinter returns nil for both printer and err removing any potential panics that may arise throughout kubectl commands. Please see #38779 and #38112 for complete context.
This fixes kubernetes#38779. This allows us to avoid case in which printers.GetStandardPrinter returns nil for both printer and err removing any potential panics that may arise throughout kubectl commands. Please see kubernetes#38779 and kubernetes#38112 for complete context. Add comment explaining adding handlers to printers.HumanReadablePrinter also remove an unnecessary conversion of printers.HumanReadablePrinter to printers.ResourcePrinter.
Fixes: #37390
Release note:
This patch adds the ability to specify an output format other than
"name" to
kubectl create ...
. It can be used in conjunction with the--dry-run
option. Converts unstructured objects into known types inorder to support all
--output
values.The patch prints
*resource.Info
s returned by the server. If a resource does not yet exist (and the--dry-run
option is not set), the resource is created and printed in the specified format.@kubernetes/cli-review @fabianofranz