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
21 changes: 20 additions & 1 deletion crates/stackable-versioned-macros/src/attrs/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub struct ContainerSkipArguments {
/// cluster scoped resource.
/// - `crates`: Override specific crates.
/// - `status`: Set the specified struct as the status subresource.
/// - `scale`: Configure the scale subresource for horizontal pod autoscaling integration.
/// - `shortname`: Set a shortname for the CR object. This can be specified multiple
/// times.
/// - `skip`: Controls skipping parts of the generation.
Expand All @@ -64,7 +65,7 @@ pub struct StructCrdArguments {
pub status: Option<Path>,
// derive
// schema
// scale
pub scale: Option<Scale>,
// printcolumn
#[darling(multiple, rename = "shortname")]
pub shortnames: Vec<String>,
Expand All @@ -74,3 +75,21 @@ pub struct StructCrdArguments {
// annotation
// label
}

/// Scale subresource configuration for a CRD.
///
/// Mirrors the fields of [`k8s_openapi::CustomResourceSubresourceScale`][1] and what is present in
/// `kube_derive`.
///
/// [1]: k8s_openapi::apiextensions_apiserver::pkg::apis::apiextensions::v1::CustomResourceSubresourceScale
//
// TODO (@Techassi): This should eventually get replaced by directly using what `kube_derive` offers,
// but that requires an upstream restructure I'm planning to do soon(ish).
#[derive(Clone, Debug, FromMeta)]
pub struct Scale {
pub spec_replicas_path: String,
pub status_replicas_path: String,

#[darling(default)]
pub label_selector_path: Option<String>,
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use quote::quote;
use syn::{Generics, ItemStruct};

use crate::{
attrs::container::{ContainerAttributes, StructCrdArguments},
attrs::container::{ContainerAttributes, Scale, StructCrdArguments},
codegen::{
Direction, VersionContext, VersionDefinition,
changes::Neighbors,
Expand Down Expand Up @@ -272,6 +272,28 @@ impl Struct {
_ => None,
};

let scale = spec_gen_ctx
.kubernetes_arguments
.scale
.as_ref()
.map(|scale| {
let Scale {
spec_replicas_path,
status_replicas_path,
label_selector_path,
} = scale;

let label_selector_path = label_selector_path
.as_ref()
.map(|p| quote! { , label_selector_path = #p });

quote! { , scale(
spec_replicas_path = #spec_replicas_path,
status_replicas_path = #status_replicas_path
#label_selector_path
)}
});

let shortnames: TokenStream = spec_gen_ctx
.kubernetes_arguments
.shortnames
Expand All @@ -286,7 +308,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 #shortnames
#singular #plural #namespaced #crates #status #scale #shortnames
)]
})
}
Expand Down
28 changes: 28 additions & 0 deletions crates/stackable-versioned-macros/tests/inputs/pass/scale.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use stackable_versioned::versioned;
// ---
#[versioned(version(name = "v1alpha1"))]
// ---
pub(crate) mod versioned {
#[versioned(crd(
group = "stackable.tech",
scale(
spec_replicas_path = ".spec.replicas",
status_replicas_path = ".status.replicas",
label_selector_path = ".status.selector"
)
))]
#[derive(
Clone,
Debug,
serde::Deserialize,
serde::Serialize,
schemars::JsonSchema,
kube::CustomResource,
)]
struct FooSpec {
bar: usize,
baz: bool,
}
}
// ---
fn main() {}

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

1 change: 1 addition & 0 deletions crates/stackable-versioned-macros/tests/trybuild.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ mod inputs {
// mod module_preserve;
// mod renamed_field;
// mod renamed_kind;
// mod scale;
// mod shortnames;
// mod submodule;
}
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 to provide `#[versioned(crd(scale(...)))]` argument to enable the `/scale` subresource ([#1185]).

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

## [0.8.3] - 2025-10-23

### Fixed
Expand Down
Loading