-
-
Notifications
You must be signed in to change notification settings - Fork 308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Groups from api discovery returned in non-deterministic order #886
Comments
Fixes #886 Signed-off-by: clux <sszynrae@gmail.com>
I'm inclined to think that this seems more like a client implementation issue... |
It's true. I was hoping it was OK anyway, because it doesn't really cost us anything here to use BTreeMap on something so small. (I'm having a fun time trying to replicate the weird disambiguation logic that kubectl has, and have found that the plural of NodeMetrics is "nodes" and the plural of PodMetrics is "pods" so am kind of forced to implement some sort of real api group preference system if the groups are non-deterministic) |
I'm not super against the BTreeMap itself, as much as going and committing to any one sorting as the one blessed way. Especially when we don't really have any deeper principle going on than "this makes it slightly easier to mimic kubectl". And especially when it seems like the kubectl use case would be better served by a linear scan than bothering to sort the whole list. |
There is another reason to do something like this; it's really hard to build a preference system of api groups because all you have are names. If you knew that builtin types had higher precedence than custom ones then that might be enough for many use cases. btreemap just so happened to push the core group early, but there might be better ways. I did a little more digging to see if there was more solid information. found some mostly useless information
so went for experimentation instead and found:
This is helpful in that if we sort our apigroup vector by the group name, we have aligned.. |
Currently Personally I'd be happier with either (in descending order of preference):
Personally I prefer option 1 because it:
|
Fixes #886 Signed-off-by: clux <sszynrae@gmail.com>
I have tried both 1 and 2 in the PR as it stands, and will highlight a few things in there. I like the idea of not being tied to a data structure, but the |
I'll have to look closer at the kubectl PR again to comment on that.. Hoping to get to it tomorrow. |
* Make Discovery::groups have deterministic order Fixes #886 Signed-off-by: clux <sszynrae@gmail.com> * sort Discovery::groups in kubectl order Signed-off-by: clux <sszynrae@gmail.com> * revert back to hashmap (no need for btree anymore) Signed-off-by: clux <sszynrae@gmail.com> * use peek rather than creating group values twice Signed-off-by: clux <sszynrae@gmail.com> * document Signed-off-by: clux <sszynrae@gmail.com> * update with suggestions Signed-off-by: clux <sszynrae@gmail.com> * update test Signed-off-by: clux <sszynrae@gmail.com> * remove ordering fn since it's simple Signed-off-by: clux <sszynrae@gmail.com> * can avoid making name public since we have a getter Signed-off-by: clux <sszynrae@gmail.com> * ..but then need to update the test Signed-off-by: clux <sszynrae@gmail.com>
Current and expected behavior
when iterating over groups:
we get entries returned in different orders depending on what the internal
HashMap
feels like.This is problematic when used in kubectl like inference that tries to "pick the first matching kind".
Possible solution
Switch
HashMap
forBTreeMap
.Won't fix the inherent problems in not having something more solid to sort on, but it at least provides a consistent interface.
The text was updated successfully, but these errors were encountered: