From 9225f4d574a05fd06bbcb88dcbe2d6d1bb01dfec Mon Sep 17 00:00:00 2001 From: Sebastian Bernauer Date: Thu, 30 Nov 2023 08:53:13 +0100 Subject: [PATCH 1/3] Fix DateTime::from_utc deprecation Signed-off-by: Sebastian Bernauer --- kube-derive/tests/crd_schema_test.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kube-derive/tests/crd_schema_test.rs b/kube-derive/tests/crd_schema_test.rs index 48c1e7b45..8e209e188 100644 --- a/kube-derive/tests/crd_schema_test.rs +++ b/kube-derive/tests/crd_schema_test.rs @@ -1,7 +1,7 @@ #![recursion_limit = "256"] use assert_json_diff::assert_json_eq; -use chrono::{DateTime, NaiveDateTime, Utc}; +use chrono::{DateTime, NaiveDateTime, TimeZone, Utc}; use kube_derive::CustomResource; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; @@ -132,7 +132,7 @@ fn test_serialized_matches_expected() { nullable: None, nullable_skipped_with_default: None, nullable_with_default: None, - timestamp: DateTime::from_utc(NaiveDateTime::from_timestamp_opt(0, 0).unwrap(), Utc), + timestamp: TimeZone::from_utc_datetime(&Utc, &NaiveDateTime::from_timestamp_opt(0, 0).unwrap()), complex_enum: ComplexEnum::VariantOne { int: 23 }, untagged_enum_person: UntaggedEnumPerson::GenderAndAge(GenderAndAge { age: 42, From 6d3a4829291f1a2df959f64eed206b961e367930 Mon Sep 17 00:00:00 2001 From: Sebastian Bernauer Date: Thu, 30 Nov 2023 08:54:27 +0100 Subject: [PATCH 2/3] Allow setting a description on a derived CRD Signed-off-by: Sebastian Bernauer --- examples/crd_derive.rs | 3 ++- kube-derive/src/custom_resource.rs | 5 ++++- kube-derive/tests/crd_schema_test.rs | 3 ++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/examples/crd_derive.rs b/examples/crd_derive.rs index 6715d5616..c96984d16 100644 --- a/examples/crd_derive.rs +++ b/examples/crd_derive.rs @@ -17,6 +17,7 @@ use serde::{Deserialize, Serialize}; plural = "fooz", root = "FooCrd", namespaced, + description = "Custom resource representing a Foo", status = "FooStatus", derive = "PartialEq", derive = "Default", @@ -119,7 +120,7 @@ fn verify_crd() { ], "schema": { "openAPIV3Schema": { - "description": "Auto-generated derived type for MyFoo via `CustomResource`", + "description": "Custom resource representing a Foo", "properties": { "spec": { "description": "Our spec for Foo\n\nA struct with our chosen Kind will be created for us, using the following kube attrs", diff --git a/kube-derive/src/custom_resource.rs b/kube-derive/src/custom_resource.rs index 177abe7de..a02160b16 100644 --- a/kube-derive/src/custom_resource.rs +++ b/kube-derive/src/custom_resource.rs @@ -10,6 +10,7 @@ struct KubeAttrs { group: String, version: String, kind: String, + description: Option, #[darling(rename = "root")] kind_struct: Option, /// lowercase plural of kind (inferred if omitted) @@ -145,6 +146,7 @@ pub(crate) fn derive(input: proc_macro2::TokenStream) -> proc_macro2::TokenStrea kind, kind_struct, version, + description, namespaced, derives, schema: schema_mode, @@ -239,7 +241,8 @@ pub(crate) fn derive(input: proc_macro2::TokenStream) -> proc_macro2::TokenStrea derive_paths.push(syn::parse_quote! { #schemars::JsonSchema }); } - let docstr = format!(" Auto-generated derived type for {ident} via `CustomResource`"); + let docstr = description + .unwrap_or_else(|| format!(" Auto-generated derived type for {ident} via `CustomResource`")); let quoted_serde = Literal::string(&serde.to_token_stream().to_string()); let root_obj = quote! { #[doc = #docstr] diff --git a/kube-derive/tests/crd_schema_test.rs b/kube-derive/tests/crd_schema_test.rs index 8e209e188..c9cf73af3 100644 --- a/kube-derive/tests/crd_schema_test.rs +++ b/kube-derive/tests/crd_schema_test.rs @@ -15,6 +15,7 @@ use std::collections::HashMap; kind = "Foo", category = "clux", namespaced, + description = "Custom resource representing a Foo", derive = "PartialEq", shortname = "fo", shortname = "f" @@ -195,7 +196,7 @@ fn test_crd_schema_matches_expected() { "additionalPrinterColumns": [], "schema": { "openAPIV3Schema": { - "description": "Auto-generated derived type for FooSpec via `CustomResource`", + "description": "Custom resource representing a Foo", "properties": { "spec": { "properties": { From a32e7cc65bb539a767860600c0337dbdede3d7bd Mon Sep 17 00:00:00 2001 From: Sebastian Bernauer Date: Fri, 1 Dec 2023 10:46:41 +0100 Subject: [PATCH 3/3] Add docs for CRD description attribute Signed-off-by: Sebastian Bernauer --- kube-derive/src/lib.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/kube-derive/src/lib.rs b/kube-derive/src/lib.rs index 7e296c3e1..250b3a0cf 100644 --- a/kube-derive/src/lib.rs +++ b/kube-derive/src/lib.rs @@ -141,6 +141,10 @@ mod custom_resource; /// ## `#[kube(category = "apps")]` /// Add a single category to `crd.spec.names.categories`. /// +/// ## `#[kube(description = "description")]` +/// Sets the description of the schema in the generated CRD. If not specified +/// `Auto-generated derived type for {customResourceName} via CustomResource` will be used instead. +/// /// ## Example with all properties /// /// ```rust @@ -155,6 +159,7 @@ mod custom_resource; /// kind = "Foo", /// root = "FooCrd", /// namespaced, +/// description = "Custom resource representing a Foo", /// status = "FooStatus", /// derive = "PartialEq", /// singular = "foot",