Arnavion / k8s-openapi

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

Does it really make sense to allow multiple features to be enabled simultaneously? #18

Closed Arnavion closed 5 years ago

Arnavion commented 6 years ago

k8s-openapi can compile with multiple features enabled, but it isn't clear if it makes sense to allow it.

I originally thought the multiple features would be enabled simultaneously because lib crates would take hard dependencies on particular versions that have what they need. For example, if a lib crate wanted apps::v1 that was introduced in 1.9, it would depend on features = ["v1_9"] and use k8s_openapi::v1_9::api::apps::v1 as apps;"). This would work but would bloat compilation time for each library that chose a different feature, and would complicate passing types between multiple libraries that depend on different versions but didn't care about the difference (eg a PodSpec from crate foo that depends on v1_9 can't be passed to crate bar that depends on v1_10).

That's why I introduced the conditional compilation macros so that lib crates would not depend on a particular version but use whatever's available. But the version-specific module imports mean the lib crates still need to have different imports for each version in the crate, or they won't compile. In fact this means that adding support for a new version is currently a semver-incompatible change, since all crates would stop compiling until they added a new k8s_if_{version}! { use k8s_openapi::v1_{version}::foo::bar; }

It seems to make more sense to:


The counterpoint is that an API that has the same import between different versions isn't necessarily semver-compatible anyway.

For example, if there had been a point where this crate only supported v1.7 and v1.8, someone would write code against apiextensions::CreateApiextensionsV1beta1CustomResourceDefinitionResponse expecting it to return Other on success. But this would break when a new release added support for v1.9 and the user enabled the v1_9 feature since it would now return Created