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

REST api - 'kind' property not always exists on entities #3030

Open
abonas opened this issue Dec 18, 2014 · 37 comments
Open

REST api - 'kind' property not always exists on entities #3030

abonas opened this issue Dec 18, 2014 · 37 comments
Assignees
Labels
area/api Indicates an issue on api area. area/usability lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. priority/backlog Higher priority than priority/awaiting-more-evidence. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. triage/accepted Indicates an issue or PR is ready to be actively worked on.

Comments

@abonas
Copy link
Contributor

abonas commented Dec 18, 2014

'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.

@bgrant0607 bgrant0607 added area/api Indicates an issue on api area. area/usability priority/backlog Higher priority than priority/awaiting-more-evidence. labels Dec 18, 2014
@bgrant0607
Copy link
Member

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.

@lavalamp
Copy link
Member

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.

@abonas
Copy link
Contributor Author

abonas commented Dec 18, 2014

@lavalamp thanks for the long explanation.
Consider a ruby client or a Java client consuming the api and converting the json response to objects - it will have to have some "if"s to populate the kind attribute or omit it because otherwise the objects won't be symmetrical, and it can also make some noise when comparing 2 objects. So it's solve-able on client sides, but I'd say it's better to solve it once on server side for all clients.

@bgrant0607
Copy link
Member

This would also be fixed by not returning the full bodies of the objects on LIST. :-)

@lavalamp
Copy link
Member

I like that fix best of all!

@abonas
Copy link
Contributor Author

abonas commented Dec 19, 2014

@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.
What are you planning not to return in LIST? which part of entities?
BTW this could also be solved by providing support with a flag that clients pass - by default you could pass shallow entities, and with that flag - full entities.

@lavalamp
Copy link
Member

Yeah, making full objects/list only configurable + adding kind/apiVersion deeply is probably best.

@lavalamp lavalamp self-assigned this Dec 19, 2014
@abonas
Copy link
Contributor Author

abonas commented Dec 21, 2014

@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).
I tried creating without this property and it works fine, but it's important to understand what's the 'formal' expectation.

@lavalamp
Copy link
Member

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).

@smarterclayton
Copy link
Contributor

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.

On Dec 21, 2014, at 3:28 PM, Daniel Smith notifications@github.com wrote:

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).


Reply to this email directly or view it on GitHub.

@lavalamp
Copy link
Member

Oh, true-- I forgot about that exception.

@abonas
Copy link
Contributor Author

abonas commented Dec 22, 2014

sorry wrong comment, pls ignore this last comment in this thread

@lavalamp
Copy link
Member

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.

@lavalamp lavalamp removed their assignment Jan 15, 2015
@smarterclayton
Copy link
Contributor

We'd want to nuke TypeMeta from internal types, correct?

----- Original Message -----

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.


Reply to this email directly or view it on GitHub:
#3030 (comment)

@lavalamp
Copy link
Member

Yes, it's not needed on internal types.

@bgrant0607 bgrant0607 added the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label Feb 5, 2015
@bgrant0607 bgrant0607 modified the milestone: v1.0 Feb 6, 2015
@brendandburns brendandburns modified the milestones: v1.0-bubble, v1.0 Mar 23, 2015
@liggitt
Copy link
Member

liggitt commented Apr 15, 2015

Not having the kind on each item in the list makes it difficult to write a UI to generically describe objects (the kind attr is required input for something like https://github.com/kubernetes-ui/object-describer/blob/master/object-describer.js#L42-L53)

@liggitt
Copy link
Member

liggitt commented Apr 15, 2015

@jwforres fyi

@bgrant0607
Copy link
Member

PR to set the kind and apiversion would be welcome. Sort of related: #3000, #6439

@bgrant0607
Copy link
Member

cc @caesarxuchao, since it's related to the other apiVersion/kind issues

@bgrant0607 bgrant0607 removed this from the v1.0-post milestone Jul 24, 2015
@leilajal
Copy link
Contributor

thanks!
/assign @leilajal @Jefftree

@Jefftree
Copy link
Member

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.

alexzielenski added a commit to alexzielenski/kubernetes that referenced this issue Jan 24, 2023
test uses kind field which is not populated for native types
karan2704 pushed a commit to karan2704/kubernetes that referenced this issue Feb 6, 2023
test uses kind field which is not populated for native types
ack-prow bot pushed a commit to aws-controllers-k8s/runtime that referenced this issue Mar 22, 2023
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.
rainest pushed a commit to Kong/kubernetes-ingress-controller that referenced this issue Sep 13, 2023
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.
@k8s-triage-robot
Copy link

This issue has not been updated in over 1 year, and should be re-triaged.

You can:

  • Confirm that this issue is still relevant with /triage accepted (org members only)
  • Close this issue with /close

For more details on the triage process, see https://www.kubernetes.dev/docs/guide/issue-triage/

/remove-triage accepted

@k8s-ci-robot k8s-ci-robot added needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. and removed triage/accepted Indicates an issue or PR is ready to be actively worked on. labels Jan 18, 2024
@thockin
Copy link
Member

thockin commented Jan 19, 2024

This issue still exists. Is it a problem we actually intend to solve?

@seans3
Copy link
Contributor

seans3 commented Feb 8, 2024

/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/api Indicates an issue on api area. area/usability lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. priority/backlog Higher priority than priority/awaiting-more-evidence. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet