diff --git a/kube-derive/src/custom_resource.rs b/kube-derive/src/custom_resource.rs index 40deeef7f..055664f31 100644 --- a/kube-derive/src/custom_resource.rs +++ b/kube-derive/src/custom_resource.rs @@ -41,6 +41,18 @@ struct KubeAttrs { annotations: Vec, #[darling(multiple, rename = "label")] labels: Vec, + + /// Sets the `storage` property to `true` or `false`. + /// + /// Defaults to `true`. + #[darling(default = default_storage_arg)] + storage: bool, + + /// Sets the `served` property to `true` or `false`. + /// + /// Defaults to `true`. + #[darling(default = default_served_arg)] + served: bool, } #[derive(Debug)] @@ -77,6 +89,16 @@ impl ToTokens for KVTuple { } } +fn default_storage_arg() -> bool { + // This defaults to true to be backwards compatible. + true +} + +fn default_served_arg() -> bool { + // This defaults to true to be backwards compatible. + true +} + #[derive(Debug, FromMeta)] struct Crates { #[darling(default = "Self::default_kube_core")] @@ -201,6 +223,8 @@ pub(crate) fn derive(input: proc_macro2::TokenStream) -> proc_macro2::TokenStrea printcolums, selectable, scale, + storage, + served, crates: Crates { kube_core, @@ -505,8 +529,8 @@ pub(crate) fn derive(input: proc_macro2::TokenStream) -> proc_macro2::TokenStrea }, "versions": [{ "name": #version, - "served": true, - "storage": true, + "served": #served, + "storage": #storage, "schema": { "openAPIV3Schema": schema, }, diff --git a/kube-derive/src/lib.rs b/kube-derive/src/lib.rs index b349b3762..36b7df07c 100644 --- a/kube-derive/src/lib.rs +++ b/kube-derive/src/lib.rs @@ -154,6 +154,12 @@ mod resource; /// ## `#[kube(label("LABEL_KEY", "LABEL_VALUE"))]` /// Add a single label to the generated CRD. /// +/// ## `#[kube(storage = true)]` +/// Sets the `storage` property to `true` or `false`. +/// +/// ## `#[kube(served = true)]` +/// Sets the `served` property to `true` or `false`. +/// /// ## Example with all properties /// /// ```rust diff --git a/kube-derive/tests/crd_schema_test.rs b/kube-derive/tests/crd_schema_test.rs index 5086e1e66..e975d8ff3 100644 --- a/kube-derive/tests/crd_schema_test.rs +++ b/kube-derive/tests/crd_schema_test.rs @@ -19,6 +19,8 @@ use std::collections::{HashMap, HashSet}; derive = "PartialEq", shortname = "fo", shortname = "f", + served = false, + storage = false, selectable = ".spec.nonNullable", selectable = ".spec.nullable", annotation("clux.dev", "cluxingv1"), @@ -217,8 +219,8 @@ fn test_crd_schema_matches_expected() { "versions": [ { "name": "v1", - "served": true, - "storage": true, + "served": false, + "storage": false, "additionalPrinterColumns": [], "selectableFields": [{ "jsonPath": ".spec.nonNullable"