keisku/kubectl-explore

Sorting order is unstable?

parroty opened this issue ยท 2 comments

Hi ๐Ÿ‘‹ . It's a very nice tool.

Description

It might be a minor issue, but I just realized that the order of the results seems unstable (the order of the APIGroups is consistent, but the Resources within the APIGroup change every time). I have tested with the AKS cluster (1.22.6).

I could only test in my local environment, but does this behavior happen in other settings?
(If so, how do you think about adding sorting?)

Try1

$ kubectl explore
...
  secret
  configmap
  replicationcontroller
> namespace
  62/62

Try2

$ kubectl explore
...
  limitrange
  componentstatus
  serviceaccount
> replicationcontroller
  62/62

Notes

diff --git a/options.go b/options.go
index 9ac4627..2be1974 100644
--- a/options.go
+++ b/options.go
@@ -3,6 +3,7 @@ package main
 import (
        "fmt"
        "os"
+       "sort"
        "strings"

        "github.com/ktr0731/go-fuzzyfinder"
@@ -164,6 +165,12 @@ func (o *Options) listGVKs() ([]schema.GroupVersionKind, error) {
                if err != nil {
                        continue
                }
+
+               sort.Slice(list.APIResources,
+                       func(i, j int) bool {
+                               return list.APIResources[i].Name < list.APIResources[j].Name
+                       },
+               )
                for _, r := range list.APIResources {
                        gvks = append(gvks, schema.GroupVersionKind{
                                Group:   gv.Group,

@parroty I appreciate your feedback๐Ÿ˜Š I believe #11 can solve this issue, so close it!

Thank you! ๐Ÿ˜„