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
10 changes: 8 additions & 2 deletions crates/stackable-versioned-macros/src/attrs/container.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use darling::{Error, FromAttributes, FromMeta, Result, util::Flag};
use syn::Path;
use syn::{Meta, Path};

#[derive(Debug, FromAttributes)]
#[darling(attributes(versioned), and_then = ContainerAttributes::validate)]
Expand Down Expand Up @@ -51,6 +51,9 @@ pub struct ContainerSkipArguments {
/// - `crates`: Override specific crates.
/// - `status`: Set the specified struct as the status subresource.
/// - `scale`: Configure the scale subresource for horizontal pod autoscaling integration.
/// - `printcolumn`: Add an additional printer column, which is displayed by `kubectl get` and
/// also nicely shows up in tools like k9s. This can be specified multiple times. The argument is
/// passed through as-is, so it supports the same syntax as `#[kube(printcolumn(...))]`.
/// - `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.
Expand All @@ -71,7 +74,10 @@ pub struct StructCrdArguments {
// derive
// schema
pub scale: Option<Scale>,
// printcolumn
// Kept as raw meta and passed through verbatim, so that kube-derive does the parsing and
// validation and we don't need to keep a copy of its printcolumn struct in sync.
#[darling(multiple, rename = "printcolumn")]
pub printcolumns: Vec<Meta>,
#[darling(multiple, rename = "shortname")]
pub shortnames: Vec<String>,
// category
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,20 +312,9 @@ impl Struct {
)}
});

let shortnames: TokenStream = spec_gen_ctx
.kubernetes_arguments
.shortnames
.iter()
.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 printcolumns = &spec_gen_ctx.kubernetes_arguments.printcolumns;
let shortnames = &spec_gen_ctx.kubernetes_arguments.shortnames;
let selectable_fields = &spec_gen_ctx.kubernetes_arguments.selectable_fields;
let doc = &spec_gen_ctx.kubernetes_arguments.doc;

quote! {
Expand All @@ -335,7 +324,10 @@ 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 #selectable_fields
#singular #plural #namespaced #crates #status #scale
#(, #printcolumns)*
#(, shortname = #shortnames)*
#(, selectable = #selectable_fields)*
)]
}
}
Expand Down
9 changes: 9 additions & 0 deletions crates/stackable-versioned-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,15 @@ mod utils;
/// // tracking is enabled, this struct will be automatically merged into
/// // the generated tracking status struct.
/// status = "FooStatus",
/// // Add an additional printer column, which is displayed by `kubectl
/// // get` and also nicely shows up in tools like k9s. This can be
/// // specified multiple times and supports the same syntax as
/// // `#[kube(printcolumn(...))]`. The column is used for all versions,
/// // so the JSON path must be valid in every version. Keep in mind
/// // that changing (renaming) or deprecating a field also changes its
/// // name. Kubernetes doesn't validate the path, the column just shows
/// // `<none>` in versions where the field doesn't exist.
/// printcolumn(name = "Baz", json_path = ".spec.baz", type_ = "boolean"),
/// // Set a shortname. This can be specified multiple times.
/// shortname = "...",
/// // Set the JSON path of a field which can be used as a field
Expand Down
33 changes: 33 additions & 0 deletions crates/stackable-versioned-macros/tests/inputs/pass/printcolumn.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use stackable_versioned::versioned;
// ---
#[versioned(version(name = "v1alpha1"), version(name = "v1beta1"))]
// ---
pub(crate) mod versioned {
#[versioned(crd(
group = "stackable.tech",
printcolumn(name = "Bar", json_path = ".spec.bar", type_ = "string"),
printcolumn(
name = "Baz",
json_path = ".spec.baz",
type_ = "integer",
description = "The baz value",
format = "int32",
priority = 1
),
doc = "Test"
))]
#[derive(
Clone,
Debug,
serde::Deserialize,
serde::Serialize,
schemars::JsonSchema,
kube::CustomResource,
)]
pub(crate) struct FooSpec {
bar: String,
baz: u16,
}
}
// ---
fn main() {}
Loading
Loading