mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 23:37:01 +00:00
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:
commit
1903c4eb51
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user