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

Denote if a printer is generic. #46265

Merged
merged 1 commit into from
Jun 3, 2017

Conversation

waseem
Copy link
Contributor

@waseem waseem commented May 23, 2017

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.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label May 23, 2017
@k8s-ci-robot
Copy link
Contributor

Hi @waseem. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should 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 by org members will still work. Regular contributors should join the org to skip this step.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label May 23, 2017
@k8s-github-robot k8s-github-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. release-note-label-needed labels May 23, 2017
@dims
Copy link
Member

dims commented May 23, 2017

@k8s-bot ok to test

@k8s-ci-robot k8s-ci-robot removed the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label May 23, 2017
Copy link
Contributor

@droot droot left a comment

Choose a reason for hiding this comment

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

LGTM.

return nil, err
if humanReadablePrinter, ok := printer.(*printers.HumanReadablePrinter); ok {
printersinternal.AddHandlers(humanReadablePrinter)
printer = printers.ResourcePrinter(humanReadablePrinter)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this line needed ? (may be a comment explaining the above two lines will help the reader here).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@droot I added a comment explaining the need of these lines. While writing the comment I realized that I was doing an unnecessary conversion which I removed. PTAL.

Can you please queue the test runs again and also remove the release-note-label-needed label?

Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for adding the comment. It looks good now. As per test-run and removing the label, @mengqiy took care of it.


func shouldGetNewPrinterForMapping(printer printers.ResourcePrinter, lastMapping, mapping *meta.RESTMapping) bool {
return printer == nil || lastMapping == nil || mapping == nil || mapping.Resource != lastMapping.Resource
}
Copy link
Contributor

Choose a reason for hiding this comment

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

+1 to this change

@alexandercampbell
Copy link
Contributor

LGTM

@mengqiy
Copy link
Member

mengqiy commented May 23, 2017

@k8s-bot ok to test
/release-note-none

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. and removed release-note-label-needed labels May 23, 2017
case "wide":
fallthrough
case "":
return nil, false, nil

printer = NewHumanReadablePrinter(encoder, decoders[0], options)
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to move this line up for wide only?
I suspect it changes the behavior when not specify --output flag.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mengqiy I don't follow how that is possible.

There are four general cases for --output flag.

  1. It's one of the generic formats these are json, yaml, name, template/go-template, templatefile/go-templatefile, jsonpath, jsonpath-file, custom-columns, or custom-columns-file.
  2. A non-generic format wide or "".
  3. An unknown format.

In the context of just this function, wide and "" are treated the same because of the blank fallthrough in the case of wide. We could also have used just case "wide", "": to get the same result.

Now in case --output is actually set to "", it is actually set to template here and then it is used to retrieve the printer.

Should we get another pair of eyes for this?

@mengqiy
Copy link
Member

mengqiy commented May 24, 2017

/assign @fabianofranz

@dims
Copy link
Member

dims commented May 25, 2017

/unassign

@fabianofranz
Copy link
Contributor

@waseem mind squashing your commits?

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.
@waseem
Copy link
Contributor Author

waseem commented May 31, 2017

@fabianofranz I squashed the commits and rebased the branch.

@fabianofranz
Copy link
Contributor

@waseem thanks!
/approve
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 31, 2017
@k8s-github-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: fabianofranz, waseem

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-github-robot k8s-github-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 31, 2017
@fabianofranz
Copy link
Contributor

@k8s-bot pull-kubernetes-federation-e2e-gce test this
@k8s-bot pull-kubernetes-unit test this

@fabianofranz
Copy link
Contributor

@k8s-bot pull-kubernetes-federation-e2e-gce test this

@calebamiles calebamiles modified the milestone: v1.7 Jun 2, 2017
@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 41563, 45251, 46265, 46462, 46721)

@k8s-github-robot k8s-github-robot merged commit 2629bf7 into kubernetes:master Jun 3, 2017
@waseem waseem deleted the printers-genericity branch June 3, 2017 08:25
k8s-github-robot pushed a commit that referenced this pull request Aug 9, 2017
Automatic merge from submit-queue

Fix sort-by output problem

Fixes kubernetes/kubectl#43

This bug was original introduced in pr here: #46265, I think next time if we touch something printer related package, maybe should let @smarterclayton have a review, although he is pretty busy I guess : ) and that package also changed a lot recently since he's been working on refactoring.
 
this is a quick and dirty fix, not sure if there's better way, I will add some regression test soon...

@kubernetes/sig-cli-pr-reviews 

```release-note
NONE
```

/assign @mengqiy 
/assign @smarterclayton
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update kubectl.GetPrinter to not return both nil for the printer and nil for the error on wide format
10 participants