Arnavion / k8s-openapi

Rust definitions of the resource types in the Kubernetes client API
Apache License 2.0
379 stars 40 forks source link

Strongly-typed WatchEvent #34

Closed Arnavion closed 5 years ago

Arnavion commented 5 years ago

Currently, WatchEvent.object is a RawExtension, which is a newtype wrapper around serde_json::Value. This means the user has to re-deserialize the serde_json::Value as the actual type they want, like api::core::v1::Pod.

For watch events associated with a group-version-kind, it should be possible to emit a strongly typed WatchEvent instead. Perhaps override WatchEvent with:

enum WatchEvent<T> {
    Added(T),
    Deleted(T),
    ErrorStatus(apimachinery::pkg::apis::meta::v1::Status),
    ErrorOther(apimachinery::pkg::runtime::RawExtension),
    Modified(T),
}

Then use WatchEvent<Pod>, etc for things with a gvk, and WatchEvent<apimachinery::pkg::runtime::RawExtension> for everything else.

As before, the user can ignore the response type and manually deserialize into a WatchEvent<apimachinery::pkg::runtime::RawExtension> if the strong type doesn't meet their requirements for any reason (eg it's incorrect due to a spec bug).