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

CustomResource derive; allow status attribute to take a path #1704

Merged
merged 3 commits into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
20 changes: 18 additions & 2 deletions examples/crd_derive_multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,33 @@ mod v1 {
use super::*;
// spec that is forwards compatible with v2 (can upgrade by truncating)
#[derive(CustomResource, Serialize, Deserialize, Default, Debug, Clone, JsonSchema)]
#[kube(group = "kube.rs", version = "v1", kind = "ManyDerive", namespaced)]
#[kube(
group = "kube.rs",
version = "v1",
kind = "ManyDerive",
status = "ManyDeriveStatus",
namespaced
)]
pub struct ManyDeriveSpec {
pub name: String,
pub oldprop: u32,
}
#[derive(Serialize, Deserialize, Default, Debug, Clone, JsonSchema)]
pub struct ManyDeriveStatus {
pub condition: Option<bool>,
}
}
mod v2 {
// spec that is NOT backwards compatible with v1 (cannot retrieve oldprop if truncated)
use super::*;
#[derive(CustomResource, Serialize, Deserialize, Default, Debug, Clone, JsonSchema)]
#[kube(group = "kube.rs", version = "v2", kind = "ManyDerive", namespaced)]
#[kube(
group = "kube.rs",
version = "v2",
kind = "ManyDerive",
namespaced,
status = "v1::ManyDeriveStatus" // cross-referencing from v1 module
)]
pub struct ManyDeriveSpec {
pub name: String,
pub extra: Option<String>,
Expand Down
16 changes: 8 additions & 8 deletions kube-derive/src/custom_resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct KubeAttrs {
#[darling(multiple, rename = "derive")]
derives: Vec<String>,
schema: Option<SchemaMode>,
status: Option<String>,
status: Option<Path>,
#[darling(multiple, rename = "category")]
categories: Vec<String>,
#[darling(multiple, rename = "shortname")]
Expand Down Expand Up @@ -808,28 +808,28 @@ struct StatusInformation {
/// returns: A `StatusInformation` struct
fn process_status(
root_ident: &Ident,
status: &Option<String>,
status: &Option<Path>,
visibility: &Visibility,
kube_core: &Path,
) -> StatusInformation {
if let Some(status_name) = &status {
let ident = format_ident!("{}", status_name);
if let Some(status_path) = &status {
let pth = quote! { #status_path };
StatusInformation {
field: quote! {
#[serde(skip_serializing_if = "Option::is_none")]
#visibility status: Option<#ident>,
#visibility status: Option<#pth>,
},
default: quote! { status: None, },
impl_hasstatus: quote! {
impl #kube_core::object::HasStatus for #root_ident {

type Status = #ident;
type Status = #pth;

fn status(&self) -> Option<&#ident> {
fn status(&self) -> Option<&#pth> {
self.status.as_ref()
}

fn status_mut(&mut self) -> &mut Option<#ident> {
fn status_mut(&mut self) -> &mut Option<#pth> {
&mut self.status
}
}
Expand Down
Loading