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

feat: Add storage and served argument to derive macro #1644

Merged
merged 5 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
28 changes: 26 additions & 2 deletions kube-derive/src/custom_resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ struct KubeAttrs {
annotations: Vec<KVTuple>,
#[darling(multiple, rename = "label")]
labels: Vec<KVTuple>,

/// 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)]
Expand Down Expand Up @@ -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")]
Expand Down Expand Up @@ -201,6 +223,8 @@ pub(crate) fn derive(input: proc_macro2::TokenStream) -> proc_macro2::TokenStrea
printcolums,
selectable,
scale,
storage,
served,
crates:
Crates {
kube_core,
Expand Down Expand Up @@ -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,
},
Expand Down
6 changes: 6 additions & 0 deletions kube-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions kube-derive/tests/crd_schema_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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"
Expand Down