Skip to content

Commit 347dcdd

Browse files
authored
Merge pull request #583 from lfrancke/crd_name
Adds a `CustomResourceExt::crd_name()` function
2 parents 5836e94 + 1c1c4ef commit 347dcdd

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

kube-core/src/crd.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ pub mod v1 {
1212
///
1313
/// This is using the stable v1::CustomResourceDefinitions (present in kubernetes >= 1.16)
1414
fn crd() -> super::apiexts::v1::CustomResourceDefinition;
15+
/// Helper to return the name of this `CustomResourceDefinition` in kubernetes.
16+
///
17+
/// This is not the name of an _instance_ of this custom resource but the `CustomResourceDefinition` object itself.
18+
fn crd_name() -> &'static str;
1519
/// Helper to generate the api information type for use with the dynamic `Api`
1620
fn api_resource() -> crate::discovery::ApiResource;
1721
}
@@ -27,6 +31,10 @@ pub mod v1beta1 {
2731
///
2832
/// This is using v1beta1::CustomResourceDefinitions (which will be removed in kubernetes 1.22)
2933
fn crd() -> super::apiexts::v1beta1::CustomResourceDefinition;
34+
/// Helper to return the name of this `CustomResourceDefinition` in kubernetes.
35+
///
36+
/// This is not the name of an _instance_ of this custom resource but the `CustomResourceDefinition` object itself.
37+
fn crd_name() -> &'static str;
3038
/// Helper to generate the api information type for use with the dynamic `Api`
3139
fn api_resource() -> crate::discovery::ApiResource;
3240
}

kube-derive/src/custom_resource.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,10 @@ pub(crate) fn derive(input: proc_macro2::TokenStream) -> proc_macro2::TokenStrea
368368
.expect("valid custom resource from #[kube(attrs..)]")
369369
}
370370

371+
fn crd_name() -> &'static str {
372+
#crd_meta_name
373+
}
374+
371375
fn api_resource() -> kube::core::ApiResource {
372376
kube::core::ApiResource::erase::<Self>(&())
373377
}

kube-derive/tests/crd_schema_test.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ fn default_nullable() -> Option<String> {
4343
Some("default_nullable".into())
4444
}
4545

46+
#[test]
47+
fn test_crd_name() {
48+
use kube::core::CustomResourceExt;
49+
assert_eq!("foos.clux.dev", Foo::crd_name());
50+
}
51+
4652
#[test]
4753
fn test_crd_schema_matches_expected() {
4854
use kube::core::CustomResourceExt;

0 commit comments

Comments
 (0)