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

Fix index out of range error when sorting kubectl get #70740

Merged

Conversation

mfpierre
Copy link
Contributor

@mfpierre mfpierre commented Nov 7, 2018

What type of PR is this?
/kind bug

What this PR does / why we need it:

There's an unsafe access to the [0] element of r.objects which can cause this error to happen:

panic: runtime error: index out of range

goroutine 1 [running]:
k8s.io/kubernetes/pkg/kubectl/cmd/get.(*RuntimeSorter).Sort(0xc0008980f0, 0x0, 0x0)
    /private/tmp/kubernetes-cli-20180928-18549-oxqbkv/src/k8s.io/kubernetes/_output/local/go/src/k8s.io/kubernetes/pkg/kubectl/cmd/get/get.go:320 +0x3bc
k8s.io/kubernetes/pkg/kubectl/cmd/get.(*GetOptions).Run(0xc0002ba540, 0x25fa0c0, 0xc000567e60, 0xc000538280, 0xc0000a12c0, 0x1, 0x6, 0x0, 0x0)
    /private/tmp/kubernetes-cli-20180928-18549-oxqbkv/src/k8s.io/kubernetes/_output/local/go/src/k8s.io/kubernetes/pkg/kubectl/cmd/get/get.go:489 +0x1391
k8s.io/kubernetes/pkg/kubectl/cmd/get.NewCmdGet.func1(0xc000538280, 0xc0000a12c0, 0x1, 0x6)
    /private/tmp/kubernetes-cli-20180928-18549-oxqbkv/src/k8s.io/kubernetes/_output/local/go/src/k8s.io/kubernetes/pkg/kubectl/cmd/get/get.go:161 +0x115
k8s.io/kubernetes/vendor/github.com/spf13/cobra.(*Command).execute(0xc000538280, 0xc0000a1260, 0x6, 0x6, 0xc000538280, 0xc0000a1260)
    /private/tmp/kubernetes-cli-20180928-18549-oxqbkv/src/k8s.io/kubernetes/_output/local/go/src/k8s.io/kubernetes/vendor/github.com/spf13/cobra/command.go:760 +0x2cc
k8s.io/kubernetes/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0xc00012b180, 0xc0003a2930, 0x12a05f200, 0xc0007f5f10)
    /private/tmp/kubernetes-cli-20180928-18549-oxqbkv/src/k8s.io/kubernetes/_output/local/go/src/k8s.io/kubernetes/vendor/github.com/spf13/cobra/command.go:846 +0x2fd
k8s.io/kubernetes/vendor/github.com/spf13/cobra.(*Command).Execute(0xc00012b180, 0x248e758, 0x3597a80)
    /private/tmp/kubernetes-cli-20180928-18549-oxqbkv/src/k8s.io/kubernetes/_output/local/go/src/k8s.io/kubernetes/vendor/github.com/spf13/cobra/command.go:794 +0x2b
main.main()
    /private/tmp/kubernetes-cli-20180928-18549-oxqbkv/src/k8s.io/kubernetes/_output/local/go/src/k8s.io/kubernetes/cmd/kubectl/kubectl.go:50 +0x150

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

fixes a runtime error occuring when sorting the output of `kubectl get` with empty results

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/bug Categorizes issue or PR as related to a bug. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Nov 7, 2018
@k8s-ci-robot
Copy link
Contributor

Hi @mfpierre. 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 /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.

I understand the commands that are listed here.

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.

@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 Nov 7, 2018
@k8s-ci-robot k8s-ci-robot added area/kubectl sig/cli Categorizes an issue or PR as relevant to SIG CLI. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Nov 7, 2018
Copy link
Member

@neolit123 neolit123 left a comment

Choose a reason for hiding this comment

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

thanks for the PR @mfpierre
seems to me like get_test.go would need an update here.

/ok-to-test

@neolit123
Copy link
Member

@kubernetes/sig-cli-bugs
/priority important-soon

@k8s-ci-robot k8s-ci-robot added priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. and removed needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Nov 8, 2018
@mfpierre
Copy link
Contributor Author

mfpierre commented Nov 8, 2018

@neolit123 just added a unit test case with an empty list of objects

The test is crashing without the fix

@neolit123
Copy link
Member

@mfpierre thanks for the update.

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Nov 8, 2018
@mfpierre mfpierre force-pushed the fix-kubectl-get-sort-out-of-range branch from b6dbd08 to bb9ea69 Compare November 8, 2018 17:36
@mfpierre
Copy link
Contributor Author

mfpierre commented Nov 8, 2018

Looks like trailing some whitespaces caused issues

/retest

@mfpierre
Copy link
Contributor Author

mfpierre commented Nov 8, 2018

/test pull-kubernetes-e2e-kops-aws
/test pull-kubernetes-e2e-gce-100-performance

@justinsb
Copy link
Member

justinsb commented Nov 9, 2018

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 9, 2018
@mfpierre
Copy link
Contributor Author

Hey @justinsb thanks for the review, do you think this bug fix can make it into 1.13?

@justinsb
Copy link
Member

I think it should, but that's probably a question for sig-cli maintainers. Looks like janetkuo won the github lottery here...

/assign janetkuo

@liggitt
Copy link
Member

liggitt commented Nov 24, 2018

it's not a regression (bug existed in 1.12), but the fix is contained, the risk is low, and I'd consider it a candidate for cherry-pick.

/milestone v1.13
/priority critical-urgent

@k8s-ci-robot k8s-ci-robot added this to the v1.13 milestone Nov 24, 2018
@k8s-ci-robot k8s-ci-robot added the priority/critical-urgent Highest priority. Must be actively worked on as someone's top priority right now. label Nov 24, 2018
@liggitt liggitt removed the priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. label Nov 24, 2018
@liggitt
Copy link
Member

liggitt commented Nov 24, 2018

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: liggitt, mfpierre

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 24, 2018
@k8s-ci-robot k8s-ci-robot merged commit 1e50c57 into kubernetes:master Nov 24, 2018
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. area/kubectl cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. priority/critical-urgent Highest priority. Must be actively worked on as someone's top priority right now. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/cli Categorizes an issue or PR as relevant to SIG CLI. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants