Merge pull request #19605 from aveshagarwal/master-sort-by-panic

Fix panic when sort-by is used with kubectl get.
This commit is contained in:
Alex Robinson 2016-01-30 10:48:56 -08:00
commit 1903c4eb51
2 changed files with 11 additions and 1 deletions

View File

@ -1343,6 +1343,16 @@ __EOF__
[[ "$(grep "Watch for changes to the described resources" "${file}")" ]]
fi
#####################
# Kubectl --sort-by #
#####################
### sort-by should not panic if no pod exists
# Pre-condition: no POD exists
kube::test::get_object_assert pods "{{range.items}}{{$id_field}}:{{end}}" ''
# Command
kubectl get pods --sort-by="{metadata.name}"
kube::test::clear_all
}

View File

@ -243,7 +243,7 @@ func RunGet(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []string
sorting, err := cmd.Flags().GetString("sort-by")
var sorter *kubectl.RuntimeSort
if err == nil && len(sorting) > 0 {
if err == nil && len(sorting) > 0 && len(objs) > 1 {
// TODO: questionable
if sorter, err = kubectl.SortObjects(f.Decoder(true), objs, sorting); err != nil {
return err