Skip to content

Commit 2a9d9d5

Browse files
authored
feat: Add STACK and DEMO templating parameters (#432)
* feat: Add `STACK` and `DEMO` templating parameters Co-authored-by: Xenia Fischer<xenia.fischer@stackable.tech> * changelog * clippy * Consitently list stack before demo
1 parent 944fa47 commit 2a9d9d5

File tree

9 files changed

+45
-8
lines changed

9 files changed

+45
-8
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,11 @@ hooks are:
7777
[pre-commit]: https://pre-commit.com/
7878
[web-readme]: ./web/README.md
7979
[lib-readme]: ./rust/stackable-cockpit/README.md
80+
81+
### Templating variables
82+
83+
| Variable | Availability | Content |
84+
| ----------- | --------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- |
85+
| `NAMESPACE` | Always | The namespace where the stack and demo (not the operators!) are deployed into |
86+
| `STACK` | Always (both in stack and demo manifests) | The name of the stack |
87+
| `DEMO` | In demos manifests: Always<br>In stack manifests: Only when deployed as part of a demo! | The name of the demo |

rust/stackable-cockpit/src/platform/demo/params.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ use stackable_operator::kvp::Labels;
44
use crate::platform::operator::ChartSourceType;
55

66
pub struct DemoInstallParameters {
7+
/// Name of the stack, which is always present, as a demo builds on top of a stack
8+
pub stack_name: String,
9+
10+
/// Name of the demo, which is always present
11+
pub demo_name: String,
12+
713
pub operator_namespace: String,
814
pub demo_namespace: String,
915

rust/stackable-cockpit/src/platform/demo/spec.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,13 @@ impl DemoSpec {
153153
.await?;
154154

155155
let stack_install_parameters = StackInstallParameters {
156+
stack_name: self.stack.clone(),
157+
demo_name: Some(install_parameters.demo_name.clone()),
156158
operator_namespace: install_parameters.operator_namespace.clone(),
157159
stack_namespace: install_parameters.demo_namespace.clone(),
158160
parameters: install_parameters.stack_parameters.clone(),
159161
labels: install_parameters.stack_labels.clone(),
160162
skip_release: install_parameters.skip_release,
161-
stack_name: self.stack.clone(),
162-
demo_name: None,
163163
chart_source: install_parameters.chart_source.clone(),
164164
operator_values: install_parameters.operator_values.clone(),
165165
};
@@ -204,6 +204,8 @@ impl DemoSpec {
204204
&self.manifests,
205205
&params,
206206
&install_params.demo_namespace,
207+
&install_params.stack_name,
208+
Some(&install_params.demo_name),
207209
install_params.labels,
208210
client,
209211
transfer_client,

rust/stackable-cockpit/src/platform/manifests.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,13 @@ pub enum Error {
6565
pub trait InstallManifestsExt {
6666
// TODO (Techassi): This step shouldn't care about templating the manifests nor fetching them from remote
6767
#[instrument(skip_all, fields(%namespace, indicatif.pb_show = true))]
68-
#[allow(async_fn_in_trait)]
68+
#[allow(clippy::too_many_arguments, async_fn_in_trait)]
6969
async fn install_manifests(
7070
manifests: &[ManifestSpec],
7171
parameters: &HashMap<String, String>,
7272
namespace: &str,
73+
stack_name: &str,
74+
demo_name: Option<&str>,
7375
labels: Labels,
7476
client: &Client,
7577
transfer_client: &xfer::Client,
@@ -80,9 +82,13 @@ pub trait InstallManifestsExt {
8082
Span::current().pb_set_length(manifests.len() as u64);
8183

8284
let mut parameters = parameters.clone();
83-
// We add the NAMESPACE parameter, so that stacks/demos can use that to render e.g. the
84-
// fqdn service names [which contain the namespace].
85+
// We need some additional templating capabilities, e.g. the namespace, so that stacks/demos
86+
// can use that to render e.g. the fqdn service names [which contain the namespace].
8587
parameters.insert("NAMESPACE".to_owned(), namespace.to_owned());
88+
parameters.insert("STACK".to_owned(), stack_name.into());
89+
if let Some(demo_name) = demo_name {
90+
parameters.insert("DEMO".to_owned(), demo_name.into());
91+
}
8692

8793
for manifest in manifests {
8894
let parameters = parameters.clone();

rust/stackable-cockpit/src/platform/stack/params.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ use crate::platform::operator::ChartSourceType;
55

66
#[derive(Debug)]
77
pub struct StackInstallParameters {
8-
pub demo_name: Option<String>,
8+
/// Name of the stack, which is always present
99
pub stack_name: String,
1010

11+
/// Optional name of the demo, which is only present in case this stack is installed as part of
12+
/// a demo. This is unset in case a stack is installed directly.
13+
pub demo_name: Option<String>,
14+
1115
pub operator_namespace: String,
1216
pub stack_namespace: String,
1317

rust/stackable-cockpit/src/platform/stack/spec.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ impl StackSpec {
249249
&self.manifests,
250250
&parameters,
251251
&install_params.stack_namespace,
252+
&install_params.stack_name,
253+
install_params.demo_name.as_deref(),
252254
install_params.labels,
253255
client,
254256
transfer_client,

rust/stackablectl/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 `STACK` and `DEMO` templating parameters. Have a look at the README for details ([#432]).
10+
11+
[#432]: https://github.com/stackabletech/stackable-cockpit/pull/432
12+
713
## [1.3.0] - 2026-03-16
814

915
### Added

rust/stackablectl/src/cmds/demo.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,8 @@ async fn install_cmd(
388388
.context(LoadOperatorValuesSnafu)?;
389389

390390
let install_parameters = DemoInstallParameters {
391+
stack_name: demo.stack.clone(),
392+
demo_name: args.demo_name.clone(),
391393
operator_namespace: args.namespaces.operator_namespace.clone(),
392394
demo_namespace: args.namespaces.namespace.clone(),
393395
stack_parameters: args.stack_parameters.clone(),

rust/stackablectl/src/cmds/stack.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,12 +359,13 @@ async fn install_cmd(
359359
.context(LoadOperatorValuesSnafu)?;
360360

361361
let install_parameters = StackInstallParameters {
362+
stack_name: args.stack_name.clone(),
363+
// There is no demo when installing only a stack
364+
demo_name: None,
362365
operator_namespace: args.namespaces.operator_namespace.clone(),
363366
stack_namespace: args.namespaces.namespace.clone(),
364-
stack_name: args.stack_name.clone(),
365367
parameters: args.parameters.clone(),
366368
skip_release: args.skip_release,
367-
demo_name: None,
368369
labels,
369370
chart_source: ChartSourceType::from(cli.chart_type()),
370371
operator_values,

0 commit comments

Comments
 (0)