Skip to content

Commit

Permalink
Merge pull request kube-rs#583 from lfrancke/crd_name
Browse files Browse the repository at this point in the history
Adds a `CustomResourceExt::crd_name()` function
  • Loading branch information
nightkr authored Jul 7, 2021
2 parents 5836e94 + 1c1c4ef commit 347dcdd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions kube-core/src/crd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ pub mod v1 {
///
/// This is using the stable v1::CustomResourceDefinitions (present in kubernetes >= 1.16)
fn crd() -> super::apiexts::v1::CustomResourceDefinition;
/// Helper to return the name of this `CustomResourceDefinition` in kubernetes.
///
/// This is not the name of an _instance_ of this custom resource but the `CustomResourceDefinition` object itself.
fn crd_name() -> &'static str;
/// Helper to generate the api information type for use with the dynamic `Api`
fn api_resource() -> crate::discovery::ApiResource;
}
Expand All @@ -27,6 +31,10 @@ pub mod v1beta1 {
///
/// This is using v1beta1::CustomResourceDefinitions (which will be removed in kubernetes 1.22)
fn crd() -> super::apiexts::v1beta1::CustomResourceDefinition;
/// Helper to return the name of this `CustomResourceDefinition` in kubernetes.
///
/// This is not the name of an _instance_ of this custom resource but the `CustomResourceDefinition` object itself.
fn crd_name() -> &'static str;
/// Helper to generate the api information type for use with the dynamic `Api`
fn api_resource() -> crate::discovery::ApiResource;
}
Expand Down
4 changes: 4 additions & 0 deletions kube-derive/src/custom_resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,10 @@ pub(crate) fn derive(input: proc_macro2::TokenStream) -> proc_macro2::TokenStrea
.expect("valid custom resource from #[kube(attrs..)]")
}

fn crd_name() -> &'static str {
#crd_meta_name
}

fn api_resource() -> kube::core::ApiResource {
kube::core::ApiResource::erase::<Self>(&())
}
Expand Down
6 changes: 6 additions & 0 deletions kube-derive/tests/crd_schema_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ fn default_nullable() -> Option<String> {
Some("default_nullable".into())
}

#[test]
fn test_crd_name() {
use kube::core::CustomResourceExt;
assert_eq!("foos.clux.dev", Foo::crd_name());
}

#[test]
fn test_crd_schema_matches_expected() {
use kube::core::CustomResourceExt;
Expand Down

0 comments on commit 347dcdd

Please sign in to comment.