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

A warning on api version preference being a group concept #1295

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions kube-client/src/discovery/apigroup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ use std::{cmp::Reverse, collections::HashMap, iter::Iterator};
/// Ok(())
/// }
/// ```
///
/// This type represents an abstraction over the native [`APIGroup`] to provide easier access to underlying group resources.
///
/// ### Common Pitfall
/// Version preference and recommendations shown herein is a **group concept**, not a resource-wide concept.
/// A common mistake is have different stored versions for resources within a group, and then receive confusing results from this module.
/// Resources in a shared group should share versions - and transition together - to minimize confusion.
/// See <https://kubernetes.io/docs/concepts/overview/kubernetes-api/#api-groups-and-versioning> for more info.
///
/// [`ApiResource`]: crate::discovery::ApiResource
/// [`ApiCapabilities`]: crate::discovery::ApiCapabilities
/// [`DynamicObject`]: crate::api::DynamicObject
Expand Down Expand Up @@ -183,6 +192,8 @@ impl ApiGroup {
}

/// Returns preferred version for working with given group.
///
/// Please note the [ApiGroup Common Pitfall](ApiGroup#common-pitfall).
pub fn preferred_version(&self) -> Option<&str> {
self.preferred.as_deref()
}
Expand All @@ -192,6 +203,8 @@ impl ApiGroup {
/// If the server does not recommend a version, we pick the "most stable and most recent" version
/// in accordance with [kubernetes version priority](https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definition-versioning/#version-priority)
/// via the descending sort order from [`Version`](kube_core::Version).
///
/// Please note the [ApiGroup Common Pitfall](ApiGroup#common-pitfall).
pub fn preferred_version_or_latest(&self) -> &str {
// NB: self.versions is non-empty by construction in ApiGroup
self.preferred
Expand Down Expand Up @@ -235,6 +248,8 @@ impl ApiGroup {
/// ```
///
/// This is equivalent to taking the [`ApiGroup::versioned_resources`] at the [`ApiGroup::preferred_version_or_latest`].
///
/// Please note the [ApiGroup Common Pitfall](ApiGroup#common-pitfall).
pub fn recommended_resources(&self) -> Vec<(ApiResource, ApiCapabilities)> {
let ver = self.preferred_version_or_latest();
self.versioned_resources(ver)
Expand Down
Loading