Skip to content

Commit af6a213

Browse files
committed
feat(versioned): support crd(doc = "...") to override the CRD root description
1 parent 90d4a2f commit af6a213

6 files changed

Lines changed: 278 additions & 2 deletions

File tree

crates/stackable-versioned-macros/src/attrs/container.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ pub struct ContainerSkipArguments {
5353
/// - `scale`: Configure the scale subresource for horizontal pod autoscaling integration.
5454
/// - `shortname`: Set a shortname for the CR object. This can be specified multiple
5555
/// times.
56+
/// - `doc`: Override the root description of the generated CRD. If not set, kube
57+
/// generates a generic one automatically.
5658
/// - `skip`: Controls skipping parts of the generation.
5759
#[derive(Clone, Debug, FromMeta)]
5860
pub struct StructCrdArguments {
@@ -71,7 +73,7 @@ pub struct StructCrdArguments {
7173
pub shortnames: Vec<String>,
7274
// category
7375
// selectable
74-
// doc
76+
pub doc: Option<String>,
7577
// annotation
7678
// label
7779
}

crates/stackable-versioned-macros/src/codegen/container/struct/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,14 +302,20 @@ impl Struct {
302302
.map(|s| quote! { , shortname = #s })
303303
.collect();
304304

305+
let doc = spec_gen_ctx
306+
.kubernetes_arguments
307+
.doc
308+
.as_ref()
309+
.map(|d| quote! { , doc = #d });
310+
305311
quote! {
306312
// The end-developer needs to derive CustomResource and JsonSchema.
307313
// This is because we don't know if they want to use a re-exported or renamed import.
308314
#[kube(
309315
// These must be comma separated (except the last) as they always exist:
310316
group = #group, version = #version, kind = #kind
311317
// These fields are optional, and therefore the token stream must prefix each with a comma:
312-
#singular #plural #namespaced #crates #status #scale #shortnames
318+
#singular #plural #namespaced #crates #status #scale #shortnames #doc
313319
)]
314320
}
315321
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use stackable_versioned::versioned;
2+
// ---
3+
#[versioned(version(name = "v1alpha1"))]
4+
// ---
5+
pub(crate) mod versioned {
6+
#[versioned(crd(
7+
group = "stackable.tech",
8+
doc = "A FooCluster, deployed and managed by the example operator."
9+
))]
10+
#[derive(
11+
Clone,
12+
Debug,
13+
serde::Deserialize,
14+
serde::Serialize,
15+
schemars::JsonSchema,
16+
kube::CustomResource,
17+
)]
18+
pub(crate) struct FooSpec {}
19+
}
20+
// ---
21+
fn main() {}

crates/stackable-versioned-macros/tests/snapshots/stackable_versioned_macros__snapshots__pass@crd_doc.rs.snap

Lines changed: 238 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/stackable-versioned-macros/tests/trybuild.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ mod inputs {
2424
// mod conversion_tracking;
2525
// mod crate_overrides;
2626
// mod crate_overrides_only_kube;
27+
// mod crd_doc;
2728
// mod docs;
2829
// mod downgrade_with;
2930
// mod enum_fields;

crates/stackable-versioned/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
44

55
## [Unreleased]
66

7+
### Added
8+
9+
- Add support to provide a `#[versioned(crd(doc = "..."))]` argument to override the root
10+
description of the generated CRD, replacing the default `Auto-generated derived type for
11+
<Kind>Spec via `CustomResource`` ([#1228]).
12+
13+
[#1228]: https://github.com/stackabletech/operator-rs/pull/1228
14+
715
## [0.10.0] - 2026-04-27
816

917
### Added

0 commit comments

Comments
 (0)