resolve an Api's ApiResource directly from a DynamicObject/TypeMeta via Discovery#2031
Open
jessemin wants to merge 1 commit into
Open
resolve an Api's ApiResource directly from a DynamicObject/TypeMeta via Discovery#2031jessemin wants to merge 1 commit into
jessemin wants to merge 1 commit into
Conversation
…ia Discovery Add Discovery::resolve_typemeta(&TypeMeta) and Discovery::resolve_object(&DynamicObject), thin wrappers over the existing GroupVersionKind::try_from(&TypeMeta) + resolve_gvk, so callers can go from a dynamic object to its ApiResource without hand-assembling a GVK. Closes kube-rs#1430 Signed-off-by: Jesik Min <serendipity9210@gmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2031 +/- ##
=======================================
+ Coverage 77.3% 77.4% +0.2%
=======================================
Files 89 89
Lines 9017 9054 +37
=======================================
+ Hits 6965 7006 +41
+ Misses 2052 2048 -4
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds two convenience methods on Discovery to remove the boilerplate of going from a DynamicObject (or a bare TypeMeta) to its ApiResource/ApiCapabilities, so callers can build an Api without hand-assembling a GroupVersionKind.
pub fn resolve_typemeta(&self, tm: &TypeMeta) -> Option<(ApiResource, ApiCapabilities)>
pub fn resolve_object(&self, obj: &DynamicObject) -> Option<(ApiResource, ApiCapabilities)>
Both are thin wrappers over the existing GroupVersionKind::try_from(&TypeMeta) (kube-core/src/gvk.rs) and Discovery::resolve_gvk, so there's no new parsing/discovery logic — resolve_object just delegates to resolve_typemeta(obj.types.as_ref()?).
This follows the direction converged on in #1430 (resolve_typemeta as the general primitive that also enables custom dynamic types, resolve_object as the ergonomic wrapper for the motivating case), and keeps the surface on Discovery rather than adding an Api constructor.
Before:
After:
let (ar, _caps) = discovery.resolve_object(&object).unwrap();Also adds a doc example on resolve_object (the TryFrom<&TypeMeta> impls are hard to discover in docs, per @nightkr's note).
Testing
Closes #1430