Skip to content

Commit

Permalink
Add category attribute to support grouped resources (#559)
Browse files Browse the repository at this point in the history
Signed-off-by: Atkins Chang <[email protected]>
  • Loading branch information
AtkinsChang authored Jun 19, 2021
1 parent 7e65072 commit 1653e22
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions kube-derive/src/custom_resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ struct KubeAttrs {
derives: Vec<String>,
#[darling(default)]
status: Option<String>,
#[darling(multiple, rename = "category")]
categories: Vec<String>,
#[darling(multiple, rename = "shortname")]
shortnames: Vec<String>,
#[darling(multiple, rename = "printcolumn")]
Expand Down Expand Up @@ -68,6 +70,7 @@ pub(crate) fn derive(input: proc_macro2::TokenStream) -> proc_macro2::TokenStrea
status,
plural,
singular,
categories,
shortnames,
printcolums,
apiextensions,
Expand Down Expand Up @@ -255,6 +258,7 @@ pub(crate) fn derive(input: proc_macro2::TokenStream) -> proc_macro2::TokenStrea
kube::core::crd::#v1ident
};

let categories_json = serde_json::to_string(&categories).unwrap();
let short_json = serde_json::to_string(&shortnames).unwrap();
let crd_meta_name = format!("{}.{}", plural, group);
let crd_meta = quote! { { "name": #crd_meta_name } };
Expand Down Expand Up @@ -287,6 +291,7 @@ pub(crate) fn derive(input: proc_macro2::TokenStream) -> proc_macro2::TokenStrea
"group": #group,
"scope": #scope,
"names": {
"categories": categories,
"plural": #plural,
"singular": #name,
"kind": #kind,
Expand Down Expand Up @@ -314,6 +319,7 @@ pub(crate) fn derive(input: proc_macro2::TokenStream) -> proc_macro2::TokenStrea
"group": #group,
"scope": #scope,
"names": {
"categories": categories,
"plural": #plural,
"singular": #name,
"kind": #kind,
Expand Down Expand Up @@ -342,6 +348,7 @@ pub(crate) fn derive(input: proc_macro2::TokenStream) -> proc_macro2::TokenStrea
} else {
serde_json::from_str(#scale_code).expect("valid scale subresource json")
};
let categories: Vec<String> = serde_json::from_str(#categories_json).expect("valid categories");
let shorts : Vec<String> = serde_json::from_str(#short_json).expect("valid shortnames");
let subres = if #has_status {
if let Some(s) = &scale {
Expand Down
2 changes: 2 additions & 0 deletions kube-derive/tests/crd_schema_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use serde::{Deserialize, Serialize};
group = "clux.dev",
version = "v1",
kind = "Foo",
category = "clux",
namespaced,
derive = "PartialEq"
)]
Expand Down Expand Up @@ -56,6 +57,7 @@ fn test_crd_schema_matches_expected() {
"spec": {
"group": "clux.dev",
"names": {
"categories": ["clux"],
"kind": "Foo",
"plural": "foos",
"shortNames": [],
Expand Down

0 comments on commit 1653e22

Please sign in to comment.