k9s icon indicating copy to clipboard operation
k9s copied to clipboard

Sort containers in declared order

Open ryanbrainard opened this issue 1 year ago • 4 comments




Is your feature request related to a problem? Please describe. When viewing a pod with multiple containers, they are displayed in alphabetical order instead of the order they are declared in the pod spec. For normal containers this isn't so much of a problem since the order is irrelevant, but for initContainers, the declared order dictates the run order. It would make it much easier to view the pod stepping through the initContainers if they were in run order.

Describe the solution you'd like Provide a sort option for containers to sort by the same order they are declared in the pod spec. Bonus if it's the default, but certainly not a requirement.

Describe alternatives you've considered I guess one could prefix the container names with numbers to make them sort alphabetically.

ryanbrainard avatar Aug 22 '24 14:08 ryanbrainard

@ryanbrainard Thank you for this great suggestion Ryan! I like this idea especially in light of more workloads specify multiple init cos.

derailed avatar Aug 22 '24 21:08 derailed

@derailed Glad you like it! I have a basic branch of this working and happy to open a PR, but before I do, a few questions:

  • What would be a good name for this column? I used "DECLARED" for now, which is ok, but I feel like it may not be intuitive to users. Other ideas: "SPEC", "NATURAL", "DEFINED", "YAML", "INDEX" etc. Any preferences?
  • Should the values be 0-indexed or 1-indexed? The way I did it is just an incrementing value with the init containers followed by the regular containers, but I guess we could get fancy and prefix them with something like "init-" and "reg-" so they are still sortable but show the index within each array.
  • Any preferences on the keyboard shortcut, visibility, and if this is the default?

ryanbrainard avatar Aug 26 '24 14:08 ryanbrainard

@derailed I took a stab at the implemention in https://github.com/derailed/k9s/pull/2878

ryanbrainard avatar Sep 12 '24 03:09 ryanbrainard

@ryanbrainard Thank you for the details here Ryan! I'll take a peek at the pr.

derailed avatar Sep 15 '24 14:09 derailed

Implemented in https://github.com/derailed/k9s/pull/2955/commits/b70b32c5a80cc96ab01d6f4d84559ec3a9142c36

ryanbrainard avatar Dec 11 '24 16:12 ryanbrainard