Skip to content
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

ApiGroup::recommended_kind returns None while I expected Some(_) #1289

Closed
xMAC94x opened this issue Sep 1, 2023 · 1 comment · Fixed by #1295
Closed

ApiGroup::recommended_kind returns None while I expected Some(_) #1289

xMAC94x opened this issue Sep 1, 2023 · 1 comment · Fixed by #1295
Assignees
Labels
docs unclear documentation

Comments

@xMAC94x
Copy link
Contributor

xMAC94x commented Sep 1, 2023

Current and expected behavior

I would expect for ApiGroup::recommended_kind to return a kind when one exists. And only return None when no viable kind exist.

Imagine 2 CRD deployed KindA and KindB. both in the same group example.com
KindA has versions v1 and v2.
KindB only supports v1.

Now running recommended_kind for KindB will result in the following.

The code of https://github.com/kube-rs/kube/blob/0.85.0/kube-client/src/discovery/apigroup.rs#L301 will first detect the preferable version, which is v2 and now it does not find any kind supporting this.

So the coding asserts that all Kinds in a Group support the same version.
I would either expect a change in that behavior and fall back to v1. or at least add a comment to the function so that its clear that it might return None, even if there working versions available, when another kind in a similar group has a newer version. And link to the resources_by_stability function.

Possible solution

I am not 100% sure if this is a documentation bug or a actual behavior bug.
In case of a documentation bug. Add the documentation to make people aware of this constellation.

Otherwise, we need to check other versions, if the loop finished and the return inside wasnt hit.

Additional context

No response

Environment

 [
  (ApiResource { group: "example.com", version: "v1", api_version: "example.com/v1", kind: "KindA", plural: "KindAs" }, ApiCapabilities { scope: Namespaced, subresources: [...], operations: [...] }), 
  (ApiResource { group: "example.com", version: "v2", api_version: "example.com/v2", kind: "KindA", plural: "KindAs" }, ApiCapabilities { scope: Namespaced, subresources: [...], operations: [...] }), 
  (ApiResource { group: "example.com", version: "v1", api_version: "example.com/v1", kind: "KindB", plural: "KindBs" }, ApiCapabilities { scope: Namespaced, subresources: [...], operations: [...] }), 
 ]
Client Version: v1.27.4
Kustomize Version: v5.0.1
Server Version: v1.25.10

Configuration and features

k8s-openapi = { version = "0.19", features = ["v1_27"] }
kube = { version = "0.85", features = ["runtime", "client"] }

Affected crates

No response

Would you like to work on fixing this bug?

maybe

@xMAC94x xMAC94x added the bug Something isn't working label Sep 1, 2023
@xMAC94x xMAC94x changed the title recommended_kind returns None while I expected Some(_) ApiGroup::recommended_kind returns None while I expected Some(_) Sep 1, 2023
@clux
Copy link
Member

clux commented Sep 6, 2023

Thanks for reporting / writing this down. This is definitely one of those strange footguns that everyone is confused by. It still feels like a documentation issue to me, because it kind falls out of the upstream api (that returns APIGroupList containing APIGroups) that a preferred_version is a group-wide concept (and so you should probably version resources in a group consistently).

This is not at all intuitive though. It kind of also discourages version changes imo.

It would at the very least make sense to add a paragraph or two about it under our ApiGroup or the main methods where people are likely to read about preferred versions.

@clux clux added docs unclear documentation and removed bug Something isn't working labels Sep 6, 2023
@clux clux self-assigned this Sep 13, 2023
@clux clux closed this as completed in #1295 Oct 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs unclear documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants