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
REST api - 'kind' property not always exists on entities #3030
Comments
Thanks for the report. I agree kind should always be present. Lists have other inconsistencies that need to be fixed, also -- see #2740. As for why we need kind, we need it for the same reasons as apiVersion (#3000) -- serialized representations, and in cases where we provide GET/WATCH of multiple kinds of objects. |
Yeah, we made a decision a while ago not to fill in redundant 'kind'/'apiVersion' fields, but we can revisit that. Once data is marshalled into a go struct, the kind/apiVersion fields are redundant with the type information, so we have the rule that they're always set on the wire and unset in memory. This rule wouldn't (necessarily) make sense for dynamically typed languages. A consequence of that is that we decided not to recursively set (on the wire) the kind fields on embedded objects of known types, since once you know the enclosing type, you can deduce the other types. But I can see how this would be awkward for non-go clients. Types with sub-objects that are determined at runtime (see the generic List type that @smarterclayton recently added) are different. For those, we emit version/kind for each sub object, since you cannot deduce this information from the enclosing type. I can think about a general solution to this if it's important. It'll probably be a bit of a pain to change, though. |
@lavalamp thanks for the long explanation. |
This would also be fixed by not returning the full bodies of the objects on LIST. :-) |
I like that fix best of all! |
@bgrant0607 this can be problematic for clients because in some cases they'll need afterwards to go to server for each entity again, and that's not effective. |
Yeah, making full objects/list only configurable + adding kind/apiVersion deeply is probably best. |
@lavalamp , on the same topic - what's the expectation from clients creating (POST) a new object - must they fill 'kind' attribute? I mean it's possible to pass it, but not very standard since you already create it on some resource (/services). |
Yes, the server can deduce kind & apiVersion, so they're not required for POSTs or PUTs. Specifying an incorrect kind for the URL you're using will cause an error. Specifying a different version than is in your URL will cause the server to convert your request appropriately (liberal in what it accepts). |
Actually, with the pending renames to minion you can pass both kind "node" and kind "minion" to the v1beta1/2 api endpoints. This is to make backwards compatibility easier.
|
Oh, true-- I forgot about that exception. |
sorry wrong comment, pls ignore this last comment in this thread |
Here's how this should be done. The current rule is "kind & version are set on disk and blank in memory". So we will change the rule to "kind & version are clear in unversioned structs, but set in versioned structs". Then we'll change the conversion routines that copy TypeMeta objects. They can look at the conversion.Scope to see what exactly they're copying to/from, and they can set the kind & apiVersion fields accordingly. (conversion.Scope should already support this, I'm pretty sure I added it recently.) Finally, we can remove all the code in conversion that is currently responsible for setting these values before serialization and clearing them afterwards. This should have the net effect of making serializations faster. We'll also possibly have to update tests; we could expand the api.Semantic's equality functions if that makes sense. |
We'd want to nuke TypeMeta from internal types, correct? ----- Original Message -----
|
Yes, it's not needed on internal types. |
Not having the kind on each item in the list makes it difficult to write a UI to generically describe objects (the |
@jwforres fyi |
cc @caesarxuchao, since it's related to the other apiVersion/kind issues |
Summarizing this issue from the comments above, the list API omits apiVersion and kind from the returned items. We should populate those fields for external types. It looks like there have been attempts at fixing this:
haven't really looked too deep into the PRs, but the main thing I see is that the performance impact needs to be verified and we need consensus on the approach. |
test uses kind field which is not populated for native types
test uses kind field which is not populated for native types
Description of changes: Some version of K8s do not reliably return `TypeMeta` information when you call `apiReader.Get()` (see kubernetes/kubernetes#3030 and kubernetes/kubernetes#80609). This is a [known bug](kubernetes-sigs/controller-runtime#1517) in `controller-runtime` that they don't plan on fixing. Parts of the code, namely around setting up the user agent, currently rely on these fields - and they are currently being given an empty struct (with empty strings for all values). To work around this bug, this PR has introduced a new `GroupVersionKind()` getter in the `ResourceDescriptor` (replacing the existing `GroupKind`), which returns a static description of the GVK. Then, rather than referencing the `RuntimeObject` `TypeMeta` properties, we can reference this new GVK getter anywhere in the runtime. It also replaces any existing use of `GroupKind` to now use `GroupVersionKind`. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
Set type meta when saving objects to the store cache and references index. This information is otherwise stripped by client-go due to kubernetes/kubernetes#3030.
This issue has not been updated in over 1 year, and should be re-triaged. You can:
For more details on the triage process, see https://www.kubernetes.dev/docs/guide/issue-triage/ /remove-triage accepted |
This issue still exists. Is it a problem we actually intend to solve? |
/triage accepted |
'kind' property exists only on the outer entity in REST api hence providing not aligned behavior for REST api consumers.
Example: when querying for all services (/api/v1beta1/services) there's an attribute
"kind": "ServiceList" on the collection, but in the "items" section with the actual services - none of the services has the "kind" attribute.
But when querying for a specific service, for example:
http://localhost:8080/api/v1beta1/services/kubernetes-ro
There is a "kind": "Service" on the entity.
I don't see the necessity to have the "kind" property in the first place since the user knows which resource was called by the api specific url, but even if it has a reason and is by design, the entities attributes should be identical whether retrieved as a single entity or as a collection. Otherwise the client should be adding/deleting attributes when retrieved as a collection by their collection type - which is doable, but definitely not elegant.
In other words, either "kind" should be present in each entity when retrieved in bulk AND when retrieved as a single entity, or not present at all for all cases.
The text was updated successfully, but these errors were encountered: