Skip to content

Commit 0bb3551

Browse files
authored
feat(stackable-versioned): Add support for multiple k8s shortname arguments (#958)
* feat(stackable-versioned): Add support for multiple k8s `shortname` arguments * chore(stackable-versioned): Update changelog * chore(stackable-versioned): Remove commented out code * chore(stackable-versioned): Update doc-comment for shortname * docs(stackable-versioned): Improve CRD shortname argument description * docs(stackable-versioned): Make k8s argument descriptions consistent. I copy/pasted from the module docs to keep wrapping new-lines consistent.
1 parent 3dc437e commit 0bb3551

File tree

7 files changed

+103
-26
lines changed

7 files changed

+103
-26
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#[versioned(
2+
version(name = "v1alpha1"),
3+
k8s(group = "stackable.tech", shortname = "f", shortname = "fo",)
4+
)]
5+
// ---
6+
#[derive(
7+
Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema, kube::CustomResource,
8+
)]
9+
pub(crate) struct FooSpec {}

crates/stackable-versioned-macros/fixtures/snapshots/stackable_versioned_macros__test__k8s_snapshots@shortnames.rs.snap

Lines changed: 55 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/src/attrs/k8s.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,19 @@ use syn::Path;
88
///
99
/// Supported arguments are:
1010
///
11-
/// - `group`, which sets the CRD group, usually the domain of the company.
12-
/// - `kind`, which allows overwriting the kind field of the CRD. This defaults to the struct name
13-
/// (without the 'Spec' suffix).
14-
/// - `singular`, to specify the singular name of the CR object.
15-
/// - `plural`, to specify the plural name of the CR object.
16-
/// - `namespaced`, to specify that this is a namespaced resource rather than cluster level.
11+
/// - `group`: Set the group of the CR object, usually the domain of the company.
12+
/// This argument is Required.
13+
/// - `kind`: Override the kind field of the CR object. This defaults to the struct
14+
/// name (without the 'Spec' suffix).
15+
/// - `singular`: Set the singular name of the CR object.
16+
/// - `plural`: Set the plural name of the CR object.
17+
/// - `namespaced`: Indicate that this is a namespaced scoped resource rather than a
18+
/// cluster scoped resource.
1719
/// - `crates`: Override specific crates.
18-
/// - `status`: Sets the specified struct as the status subresource.
19-
/// - `shortname`: Sets the shortname of the CRD.
20-
/// - `skip`, which controls skipping parts of the generation.
20+
/// - `status`: Set the specified struct as the status subresource.
21+
/// - `shortname`: Set a shortname for the CR object. This can be specified multiple
22+
/// times.
23+
/// - `skip`: Controls skipping parts of the generation.
2124
#[derive(Clone, Debug, FromMeta)]
2225
pub(crate) struct KubernetesArguments {
2326
pub(crate) group: String,
@@ -32,7 +35,8 @@ pub(crate) struct KubernetesArguments {
3235
// schema
3336
// scale
3437
// printcolumn
35-
pub(crate) shortname: Option<String>,
38+
#[darling(multiple, rename = "shortname")]
39+
pub(crate) shortnames: Vec<String>,
3640
// category
3741
// selectable
3842
// doc

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ pub(crate) struct KubernetesOptions {
280280
// schema
281281
// scale
282282
// printcolumn
283-
pub(crate) shortname: Option<String>,
283+
pub(crate) shortnames: Vec<String>,
284284
// category
285285
// selectable
286286
// doc
@@ -301,7 +301,7 @@ impl From<KubernetesArguments> for KubernetesOptions {
301301
.crates
302302
.map_or_else(KubernetesCrateOptions::default, |crates| crates.into()),
303303
status: args.status,
304-
shortname: args.shortname,
304+
shortnames: args.shortnames,
305305
skip_merged_crd: args.skip.map_or(false, |s| s.merged_crd.is_present()),
306306
}
307307
}

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,10 +282,11 @@ impl Struct {
282282
.status
283283
.as_ref()
284284
.map(|s| quote! { , status = #s });
285-
let shortname = kubernetes_options
286-
.shortname
287-
.as_ref()
288-
.map(|s| quote! { , shortname = #s });
285+
let shortnames: TokenStream = kubernetes_options
286+
.shortnames
287+
.iter()
288+
.map(|s| quote! { , shortname = #s })
289+
.collect();
289290

290291
Some(quote! {
291292
// The end-developer needs to derive CustomResource and JsonSchema.
@@ -294,7 +295,7 @@ impl Struct {
294295
// These must be comma separated (except the last) as they always exist:
295296
group = #group, version = #version, kind = #kind
296297
// These fields are optional, and therefore the token stream must prefix each with a comma:
297-
#singular #plural #namespaced #crates #status #shortname
298+
#singular #plural #namespaced #crates #status #shortnames
298299
)]
299300
})
300301
}

crates/stackable-versioned-macros/src/lib.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -603,16 +603,18 @@ println!("{}", serde_yaml::to_string(&merged_crd).unwrap());
603603
604604
Currently, the following arguments are supported:
605605
606-
- `group`: Sets the CRD group, usually the domain of the company.
607-
- `kind`: Allows overwriting the kind field of the CRD. This defaults
608-
to the struct name (without the 'Spec' suffix).
609-
- `singular`: Sets the singular name.
610-
- `plural`: Sets the plural name.
611-
- `namespaced`: Specifies that this is a namespaced resource rather than
612-
a cluster scoped.
606+
- `group`: Set the group of the CR object, usually the domain of the company.
607+
This argument is Required.
608+
- `kind`: Override the kind field of the CR object. This defaults to the struct
609+
name (without the 'Spec' suffix).
610+
- `singular`: Set the singular name of the CR object.
611+
- `plural`: Set the plural name of the CR object.
612+
- `namespaced`: Indicate that this is a namespaced scoped resource rather than a
613+
cluster scoped resource.
613614
- `crates`: Override specific crates.
614-
- `status`: Sets the specified struct as the status subresource.
615-
- `shortname`: Sets the shortname of the CRD.
615+
- `status`: Set the specified struct as the status subresource.
616+
- `shortname`: Set a shortname for the CR object. This can be specified multiple
617+
times.
616618
617619
### Versioning Items in a Module
618620

crates/stackable-versioned/CHANGELOG.md

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

55
## [Unreleased]
66

7+
### Added
8+
9+
- Add support for multiple k8s `shortname` arguments ([#958]).
10+
11+
[#958]: https://github.com/stackabletech/operator-rs/pull/958
12+
713
## [0.5.0] - 2024-12-03
814

915
### Added

0 commit comments

Comments
 (0)