-
Notifications
You must be signed in to change notification settings - Fork 41
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
Parsing error when decoding bookmark #70
Comments
The openapi spec says that On that basis, the JSON sent by the API server is violating the spec and it would count as an API server bug or a spec bug. (Yes, the spec says it's "required", not that it's non-nullable, but historically the generator that Kubernetes uses uses the former to mean the latter.) But that said, it seems more logical to me to consider that bookmark events will only have |
😦 I suspected this would be the issue. One of the more generic workarounds would be to generally relax serde deserializer strictness to be more like Go decoder. It seems like it's something that could be tweaked for the generic case, and some other potential issues with similar effect.
The type of the event is now known upfront, so it'd have to be something like |
Just noting that people have also reported |
It's not a matter of "relaxing". A
Golang is able to deserialize this type not because the decoder is special, but because golang is not type-safe enough to have non-nullable types.
I'm saying that we can change the definition from: enum WatchEvent<T> {
...,
Bookmark(T),
} to: enum WatchEvent<T> {
...,
Bookmark(Bookmark),
}
struct Bookmark {
kind: String,
api_version: String,
metadata: ObjectMeta,
} |
@clux Your issue I'm more inclined to consider is an openapi spec bug regarding the nullability of @MOZGIII Just to confirm, do all pod watch bookmark events have |
The ones I saw are like that, and I haven't seen other bookmarks, so I guess it's safe to assume they're all like that (with |
Actually, So I'm inclined to make it This could become problematic in the future if bookmark events start getting more fields outside the flattened |
…instead of the full object. In some cases, the API server sends a BOOKMARK watch event that can't be successfully deserialized as the resource type. The example in #70 is of a watch event for pods where the `spec.containers` field is `null`, even though the spec requires that `containers` be non-null. Since the only point of bookmark events is to carry a resource version, this change makes it so that the deserializer only looks for the `metadata.resourceVersion` field, in addition to the `apiVersion` and `kind` fields like before. Apart from changing the definition of the `WatchEvent::Bookmark` variant, this change also adds a bound to the type parameter of `WatchEvent` - it must now also implement `k8s_openapi::Resource` since its API_VERSION and KIND are still needed to validate the bookmark object. Fixes #70
@MOZGIII Can you test with https://github.com/Arnavion/k8s-openapi/compare/fix-70 ? |
Unit test I have at the parsing module on our end now passes! I'll run our E2E suite tomorrow to be sure, but so far looks good. 👍 |
This bug no longer appears at our E2E tests. 👍 |
Are there any plans to ship this? |
I'm getting an error
when parsing this data:
with
Pod::try_from_parts
.I get this set of bytes from the K8s API as part of the watch request stream.
Expected output:
Versions:
serde
1.0.104serde_json
1.0.52k8s-openapi
0.7.1The text was updated successfully, but these errors were encountered: