Skip to content

Commit 5a9a655

Browse files
sbernauerNickLarsenNZTechassi
authored
feat: Support templating the namespace in manifests (#355)
* feat: Support templating the namespace * changelog * changelog * changelog * changelog * Rename product_namespace to namespace * changelog * Apply suggestions from code review Co-authored-by: Techassi <git@techassi.dev> * chore: Update shell completions They seemed to have been missed in #373 --------- Co-authored-by: Nick <10092581+NickLarsenNZ@users.noreply.github.com> Co-authored-by: Techassi <git@techassi.dev> Co-authored-by: Nick Larsen <nick.larsen@stackable.tech>
1 parent 765f6da commit 5a9a655

File tree

12 files changed

+40
-44
lines changed

12 files changed

+40
-44
lines changed

extra/completions/_stackablectl

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extra/completions/stackablectl.bash

Lines changed: 2 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extra/completions/stackablectl.elv

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extra/completions/stackablectl.fish

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extra/completions/stackablectl.nu

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,14 @@ impl DemoSpec {
9797
/// - Does the demo support to be installed in the requested namespace?
9898
/// - Does the cluster have enough resources available to run this demo?
9999
#[instrument(skip_all)]
100-
pub async fn check_prerequisites(
101-
&self,
102-
client: &Client,
103-
product_namespace: &str,
104-
) -> Result<(), Error> {
100+
pub async fn check_prerequisites(&self, client: &Client, namespace: &str) -> Result<(), Error> {
105101
debug!("Checking prerequisites before installing demo");
106102

107103
// Returns an error if the demo doesn't support to be installed in the
108104
// requested namespace
109-
if !self.supports_namespace(product_namespace) {
105+
if !self.supports_namespace(namespace) {
110106
return Err(Error::UnsupportedNamespace {
111-
requested: product_namespace.to_string(),
107+
requested: namespace.to_owned(),
112108
supported: self.supported_namespaces.clone(),
113109
});
114110
}

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,23 @@ pub enum Error {
6262

6363
pub trait InstallManifestsExt {
6464
// TODO (Techassi): This step shouldn't care about templating the manifests nor fetching them from remote
65-
#[instrument(skip_all, fields(%product_namespace))]
65+
#[instrument(skip_all, fields(%namespace))]
6666
#[allow(async_fn_in_trait)]
6767
async fn install_manifests(
6868
manifests: &[ManifestSpec],
6969
parameters: &HashMap<String, String>,
70-
product_namespace: &str,
70+
namespace: &str,
7171
labels: Labels,
7272
client: &Client,
7373
transfer_client: &xfer::Client,
7474
) -> Result<(), Error> {
7575
debug!("Installing manifests");
7676

77+
let mut parameters = parameters.clone();
78+
// We add the NAMESPACE parameter, so that stacks/demos can use that to render e.g. the
79+
// fqdn service names [which contain the namespace].
80+
parameters.insert("NAMESPACE".to_owned(), namespace.to_owned());
81+
7782
for manifest in manifests {
7883
match manifest {
7984
ManifestSpec::HelmChart(helm_file) => {
@@ -85,7 +90,7 @@ pub trait InstallManifestsExt {
8590
})?;
8691

8792
let helm_chart: helm::Chart = transfer_client
88-
.get(&helm_file, &Template::new(parameters).then(Yaml::new()))
93+
.get(&helm_file, &Template::new(&parameters).then(Yaml::new()))
8994
.await
9095
.context(FileTransferSnafu)?;
9196

@@ -111,7 +116,7 @@ pub trait InstallManifestsExt {
111116
chart_version: Some(&helm_chart.version),
112117
},
113118
Some(&values_yaml),
114-
product_namespace,
119+
namespace,
115120
true,
116121
)
117122
.context(InstallHelmReleaseSnafu {
@@ -130,12 +135,12 @@ pub trait InstallManifestsExt {
130135
})?;
131136

132137
let manifests = transfer_client
133-
.get(&path_or_url, &Template::new(parameters))
138+
.get(&path_or_url, &Template::new(&parameters))
134139
.await
135140
.context(FileTransferSnafu)?;
136141

137142
client
138-
.deploy_manifests(&manifests, product_namespace, labels.clone())
143+
.deploy_manifests(&manifests, namespace, labels.clone())
139144
.await
140145
.context(DeployManifestSnafu)?
141146
}

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,21 +111,17 @@ impl StackSpec {
111111
/// - Does the stack support to be installed in the requested namespace?
112112
/// - Does the cluster have enough resources available to run this stack?
113113
#[instrument(skip_all)]
114-
pub async fn check_prerequisites(
115-
&self,
116-
client: &Client,
117-
product_namespace: &str,
118-
) -> Result<(), Error> {
114+
pub async fn check_prerequisites(&self, client: &Client, namespace: &str) -> Result<(), Error> {
119115
debug!("Checking prerequisites before installing stack");
120116

121117
// Returns an error if the stack doesn't support to be installed in the
122118
// requested product namespace. When installing a demo, this check is
123119
// already done on the demo spec level, however we still need to check
124120
// here, as stacks can be installed on their own.
125-
if !self.supports_namespace(product_namespace) {
121+
if !self.supports_namespace(namespace) {
126122
return Err(Error::UnsupportedNamespace {
127123
supported: self.supported_namespaces.clone(),
128-
requested: product_namespace.to_string(),
124+
requested: namespace.to_owned(),
129125
});
130126
}
131127

@@ -204,7 +200,7 @@ impl StackSpec {
204200
&self,
205201
release_list: release::ReleaseList,
206202
operator_namespace: &str,
207-
_product_namespace: &str, // TODO (@NickLarsenNZ): remove this field
203+
_namespace: &str, // TODO (@NickLarsenNZ): remove this field
208204
chart_source: &ChartSourceType,
209205
) -> Result<(), Error> {
210206
info!(self.release, "Trying to install release");

rust/stackablectl/CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@ All notable changes to this project will be documented in this file.
44

55
## [Unreleased]
66

7+
### Added
8+
9+
- Pass the stack/demo namespace as a templating variable `NAMESPACE` to manifests.
10+
This should unblock demos to run in all namespaces, as they can template the namespace e.g. for the FQDN of services ([#355]).
11+
712
### Changed
813

9-
- Renamed `--product-namespace` argument to `--namespace` ([#373]).
14+
- Renamed `--product-namespace` argument to `--namespace` ([#373], [#355]).
1015
- Kept `--product-namespace` as a hidden alias to be removed in a later release.
1116

1217
### Fixed
@@ -25,6 +30,7 @@ All notable changes to this project will be documented in this file.
2530
- Improve tracing and log output ([#365]).
2631

2732
[#351]: https://github.com/stackabletech/stackable-cockpit/pull/351
33+
[#355]: https://github.com/stackabletech/stackable-cockpit/pull/355
2834
[#364]: https://github.com/stackabletech/stackable-cockpit/pull/364
2935
[#365]: https://github.com/stackabletech/stackable-cockpit/pull/365
3036

rust/stackablectl/src/cmds/stacklet.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ pub struct StackletCredentialsArgs {
4848
short = 'n',
4949
global = true,
5050
default_value = DEFAULT_NAMESPACE,
51-
visible_aliases(["product-ns"]),
51+
aliases(["product-ns", "product-namespace"]),
5252
long_help = "Namespace in the cluster used to deploy the products. Use this to select
5353
a different namespace for credential lookup.")]
54-
pub product_namespace: String,
54+
pub namespace: String,
5555
}
5656

5757
#[derive(Debug, Args)]
@@ -211,7 +211,7 @@ async fn credentials_cmd(args: &StackletCredentialsArgs) -> Result<String, CmdEr
211211

212212
match get_credentials_for_product(
213213
&client,
214-
&args.product_namespace,
214+
&args.namespace,
215215
&args.stacklet_name,
216216
&args.product_name,
217217
)
@@ -229,7 +229,7 @@ async fn credentials_cmd(args: &StackletCredentialsArgs) -> Result<String, CmdEr
229229

230230
let output = format!(
231231
"Credentials for {} ({}) in namespace '{}':",
232-
args.product_name, args.stacklet_name, args.product_namespace
232+
args.product_name, args.stacklet_name, args.namespace
233233
);
234234

235235
Ok(format!("{}\n\n{}", output, table))

0 commit comments

Comments
 (0)