Skip to content

Commit

Permalink
Version gate crd method with selectable fields
Browse files Browse the repository at this point in the history
Adds a if ge_1_30 macro to the fn with fields
and duplicates it for le_1_29 without the fields

Signed-off-by: clux <[email protected]>
  • Loading branch information
clux committed Oct 18, 2024
1 parent 1addf43 commit 7e17967
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions kube-derive/src/custom_resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ pub(crate) fn derive(input: proc_macro2::TokenStream) -> proc_macro2::TokenStrea
let impl_crd = quote! {
impl #extver::CustomResourceExt for #rootident {

k8s_openapi::k8s_if_ge_1_30! {
fn crd() -> #apiext::CustomResourceDefinition {
let columns : Vec<#apiext::CustomResourceColumnDefinition> = #serde_json::from_str(#printers).expect("valid printer column json");
let fields : Vec<#apiext::SelectableField> = #serde_json::from_str(#fields).expect("valid selectableField column json");
Expand Down Expand Up @@ -472,6 +473,35 @@ pub(crate) fn derive(input: proc_macro2::TokenStream) -> proc_macro2::TokenStrea
#serde_json::from_value(jsondata)
.expect("valid custom resource from #[kube(attrs..)]")
}
}
k8s_openapi::k8s_if_le_1_29! {
fn crd() -> #apiext::CustomResourceDefinition {
let columns : Vec<#apiext::CustomResourceColumnDefinition> = #serde_json::from_str(#printers).expect("valid printer column json");
let scale: Option<#apiext::CustomResourceSubresourceScale> = if #scale_code.is_empty() {
None
} 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 {
#serde_json::json!({
"status": {},
"scale": scale
})
} else {
#serde_json::json!({"status": {} })
}
} else {
#serde_json::json!({})
};

#jsondata
#serde_json::from_value(jsondata)
.expect("valid custom resource from #[kube(attrs..)]")
}
}

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

0 comments on commit 7e17967

Please sign in to comment.