Skip to content

feat(stackable-versioned): Add support for multiple k8s shortname arguments #958

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

Merged
merged 6 commits into from
Feb 14, 2025
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#[versioned(
version(name = "v1alpha1"),
k8s(group = "stackable.tech", shortname = "f", shortname = "fo",)
)]
// ---
#[derive(
Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema, kube::CustomResource,
)]
pub(crate) struct FooSpec {}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 14 additions & 10 deletions crates/stackable-versioned-macros/src/attrs/k8s.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@ use syn::Path;
///
/// Supported arguments are:
///
/// - `group`, which sets the CRD group, usually the domain of the company.
/// - `kind`, which allows overwriting the kind field of the CRD. This defaults to the struct name
/// (without the 'Spec' suffix).
/// - `singular`, to specify the singular name of the CR object.
/// - `plural`, to specify the plural name of the CR object.
/// - `namespaced`, to specify that this is a namespaced resource rather than cluster level.
/// - `group`: Set the group of the CR object, usually the domain of the company.
/// This argument is Required.
/// - `kind`: Override the kind field of the CR object. This defaults to the struct
/// name (without the 'Spec' suffix).
/// - `singular`: Set the singular name of the CR object.
/// - `plural`: Set the plural name of the CR object.
/// - `namespaced`: Indicate that this is a namespaced scoped resource rather than a
/// cluster scoped resource.
/// - `crates`: Override specific crates.
/// - `status`: Sets the specified struct as the status subresource.
/// - `shortname`: Sets the shortname of the CRD.
/// - `skip`, which controls skipping parts of the generation.
/// - `status`: Set the specified struct as the status subresource.
/// - `shortname`: Set a shortname for the CR object. This can be specified multiple
/// times.
/// - `skip`: Controls skipping parts of the generation.
#[derive(Clone, Debug, FromMeta)]
pub(crate) struct KubernetesArguments {
pub(crate) group: String,
Expand All @@ -32,7 +35,8 @@ pub(crate) struct KubernetesArguments {
// schema
// scale
// printcolumn
pub(crate) shortname: Option<String>,
#[darling(multiple, rename = "shortname")]
pub(crate) shortnames: Vec<String>,
// category
// selectable
// doc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ pub(crate) struct KubernetesOptions {
// schema
// scale
// printcolumn
pub(crate) shortname: Option<String>,
pub(crate) shortnames: Vec<String>,
// category
// selectable
// doc
Expand All @@ -301,7 +301,7 @@ impl From<KubernetesArguments> for KubernetesOptions {
.crates
.map_or_else(KubernetesCrateOptions::default, |crates| crates.into()),
status: args.status,
shortname: args.shortname,
shortnames: args.shortnames,
skip_merged_crd: args.skip.map_or(false, |s| s.merged_crd.is_present()),
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,11 @@ impl Struct {
.status
.as_ref()
.map(|s| quote! { , status = #s });
let shortname = kubernetes_options
.shortname
.as_ref()
.map(|s| quote! { , shortname = #s });
let shortnames: TokenStream = kubernetes_options
.shortnames
.iter()
.map(|s| quote! { , shortname = #s })
.collect();

Some(quote! {
// The end-developer needs to derive CustomResource and JsonSchema.
Expand All @@ -294,7 +295,7 @@ impl Struct {
// These must be comma separated (except the last) as they always exist:
group = #group, version = #version, kind = #kind
// These fields are optional, and therefore the token stream must prefix each with a comma:
#singular #plural #namespaced #crates #status #shortname
#singular #plural #namespaced #crates #status #shortnames
)]
})
}
Expand Down
20 changes: 11 additions & 9 deletions crates/stackable-versioned-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,16 +603,18 @@ println!("{}", serde_yaml::to_string(&merged_crd).unwrap());

Currently, the following arguments are supported:

- `group`: Sets the CRD group, usually the domain of the company.
- `kind`: Allows overwriting the kind field of the CRD. This defaults
to the struct name (without the 'Spec' suffix).
- `singular`: Sets the singular name.
- `plural`: Sets the plural name.
- `namespaced`: Specifies that this is a namespaced resource rather than
a cluster scoped.
- `group`: Set the group of the CR object, usually the domain of the company.
This argument is Required.
- `kind`: Override the kind field of the CR object. This defaults to the struct
name (without the 'Spec' suffix).
- `singular`: Set the singular name of the CR object.
- `plural`: Set the plural name of the CR object.
- `namespaced`: Indicate that this is a namespaced scoped resource rather than a
cluster scoped resource.
- `crates`: Override specific crates.
- `status`: Sets the specified struct as the status subresource.
- `shortname`: Sets the shortname of the CRD.
- `status`: Set the specified struct as the status subresource.
- `shortname`: Set a shortname for the CR object. This can be specified multiple
times.

### Versioning Items in a Module

Expand Down
6 changes: 6 additions & 0 deletions crates/stackable-versioned/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

### Added

- Add support for multiple k8s `shortname` arguments ([#958]).

[#958]: https://github.com/stackabletech/operator-rs/pull/958

## [0.5.0] - 2024-12-03

### Added
Expand Down
Loading