Skip to content
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
5 changes: 4 additions & 1 deletion crates/stackable-versioned-macros/src/attrs/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ pub struct ContainerSkipArguments {
/// - `scale`: Configure the scale subresource for horizontal pod autoscaling integration.
/// - `shortname`: Set a shortname for the CR object. This can be specified multiple
/// times.
/// - `selectable`: Set the JSON path of a field which can be used as a field selector.
/// This can be specified multiple times.
/// - `doc`: Set the root description of the generated CRD. This argument is required, so
/// that every CRD has a meaningful description instead of the generic one that kube
/// generates by default.
Expand All @@ -73,7 +75,8 @@ pub struct StructCrdArguments {
#[darling(multiple, rename = "shortname")]
pub shortnames: Vec<String>,
// category
// selectable
#[darling(multiple, rename = "selectable")]
pub selectable_fields: Vec<String>,
pub doc: String,
// annotation
// label
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,13 @@ impl Struct {
.map(|s| quote! { , shortname = #s })
.collect();

let selectable_fields: TokenStream = spec_gen_ctx
.kubernetes_arguments
.selectable_fields
.iter()
.map(|s| quote! { , selectable = #s })
.collect();

let doc = &spec_gen_ctx.kubernetes_arguments.doc;

quote! {
Expand All @@ -328,7 +335,7 @@ impl Struct {
// These must be comma separated (except the last) as they always exist:
group = #group, version = #version, kind = #kind, doc = #doc
// These fields are optional, and therefore the token stream must prefix each with a comma:
#singular #plural #namespaced #crates #status #scale #shortnames
#singular #plural #namespaced #crates #status #scale #shortnames #selectable_fields
)]
}
}
Expand Down
6 changes: 5 additions & 1 deletion crates/stackable-versioned-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,11 @@ mod utils;
/// // the generated tracking status struct.
/// status = "FooStatus",
/// // Set a shortname. This can be specified multiple times.
/// shortname = "..."
/// shortname = "...",
/// // Set the JSON path of a field which can be used as a field
/// // selector. This can be specified multiple times. The path is used
/// // for all versions, so the field must exist in every version.
/// selectable = ".spec.baz"
/// ))]
/// # #[derive(Clone, Debug, Deserialize, Serialize, CustomResource, JsonSchema)]
/// pub struct FooSpec {
Expand Down
26 changes: 26 additions & 0 deletions crates/stackable-versioned-macros/tests/inputs/pass/selectable.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use stackable_versioned::versioned;
// ---
#[versioned(version(name = "v1alpha1"), version(name = "v1beta1"))]
// ---
pub(crate) mod versioned {
#[versioned(crd(
group = "stackable.tech",
selectable = ".spec.bar",
selectable = ".spec.baz",
doc = "Test"
))]
#[derive(
Clone,
Debug,
serde::Deserialize,
serde::Serialize,
schemars::JsonSchema,
kube::CustomResource,
)]
pub(crate) struct FooSpec {
bar: String,
baz: bool,
}
}
// ---
fn main() {}
Loading
Loading