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
-
The order of kubectl api-resources
result is stable in my environment. The default behavior of api-resources
seems to sort APIGroup
and Name
, as the logic sorts the results explicitly.
- https://github.com/kubernetes/kubectl/blob/77a7b65409fc364fa3ff37060cc9342dc0527292/pkg/cmd/apiresources/apiresources.go#L202
- https://github.com/kubernetes/kubectl/blob/77a7b65409fc364fa3ff37060cc9342dc0527292/pkg/cmd/apiresources/apiresources.go#L264
-
I just briefly tested with the following patch for sorting behavior (making the order as similar as kubectl api-resources
, though the displayed order is reversed).
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,