Skip to content

Commit 55efb1c

Browse files
committed
feat(versioned): Add support to pass the scale argument
1 parent 380e4fb commit 55efb1c

2 files changed

Lines changed: 36 additions & 2 deletions

File tree

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ pub struct ContainerSkipArguments {
5050
/// cluster scoped resource.
5151
/// - `crates`: Override specific crates.
5252
/// - `status`: Set the specified struct as the status subresource.
53+
/// - `scale`: Configure the scale subresource for horizontal pod autoscaling integration.
5354
/// - `shortname`: Set a shortname for the CR object. This can be specified multiple
5455
/// times.
5556
/// - `skip`: Controls skipping parts of the generation.
@@ -64,7 +65,7 @@ pub struct StructCrdArguments {
6465
pub status: Option<Path>,
6566
// derive
6667
// schema
67-
// scale
68+
pub scale: Option<Scale>,
6869
// printcolumn
6970
#[darling(multiple, rename = "shortname")]
7071
pub shortnames: Vec<String>,
@@ -74,3 +75,21 @@ pub struct StructCrdArguments {
7475
// annotation
7576
// label
7677
}
78+
79+
/// Scale subresource configuration for a CRD.
80+
///
81+
/// Mirrors the fields of [`k8s_openapi::CustomResourceSubresourceScale`][1] and what is present in
82+
/// `kube_derive`.
83+
///
84+
/// [1]: k8s_openapi::apiextensions_apiserver::pkg::apis::apiextensions::v1::CustomResourceSubresourceScale
85+
//
86+
// TODO (@Techassi): This should eventually get replaced by directly using what `kube_derive` offers,
87+
// but that requires an upstream restructure I'm planning to do soon(ish).
88+
#[derive(Clone, Debug, FromMeta)]
89+
pub struct Scale {
90+
pub spec_replicas_path: String,
91+
pub status_replicas_path: String,
92+
93+
#[darling(default)]
94+
pub label_selector_path: Option<String>,
95+
}

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,21 @@ impl Struct {
272272
_ => None,
273273
};
274274

275+
let scale = spec_gen_ctx.kubernetes_arguments.scale.as_ref().map(|s| {
276+
let spec_replicas_path = &s.spec_replicas_path;
277+
let status_replicas_path = &s.status_replicas_path;
278+
let label_selector_path = s
279+
.label_selector_path
280+
.as_ref()
281+
.map(|p| quote! { , label_selector_path = #p });
282+
283+
quote! { , scale(
284+
spec_replicas_path = #spec_replicas_path,
285+
status_replicas_path = #status_replicas_path
286+
#label_selector_path
287+
)}
288+
});
289+
275290
let shortnames: TokenStream = spec_gen_ctx
276291
.kubernetes_arguments
277292
.shortnames
@@ -286,7 +301,7 @@ impl Struct {
286301
// These must be comma separated (except the last) as they always exist:
287302
group = #group, version = #version, kind = #kind
288303
// These fields are optional, and therefore the token stream must prefix each with a comma:
289-
#singular #plural #namespaced #crates #status #shortnames
304+
#singular #plural #namespaced #crates #status #scale #shortnames
290305
)]
291306
})
292307
}

0 commit comments

Comments
 (0)