diff --git a/extra/completions/_stackablectl b/extra/completions/_stackablectl index e8717fbd..25c69764 100644 --- a/extra/completions/_stackablectl +++ b/extra/completions/_stackablectl @@ -659,9 +659,8 @@ repo\:"index.yaml-based repositories\: resolution (dev, test, stable) is based o case $line[1] in (credentials) _arguments "${_arguments_options[@]}" : \ -'-n+[Namespace in the cluster used to deploy the products]:PRODUCT_NAMESPACE: ' \ -'--product-namespace=[Namespace in the cluster used to deploy the products]:PRODUCT_NAMESPACE: ' \ -'--product-ns=[Namespace in the cluster used to deploy the products]:PRODUCT_NAMESPACE: ' \ +'-n+[Namespace in the cluster used to deploy the products]:NAMESPACE: ' \ +'--namespace=[Namespace in the cluster used to deploy the products]:NAMESPACE: ' \ '-l+[Log level this application uses]:LOG_LEVEL: ' \ '--log-level=[Log level this application uses]:LOG_LEVEL: ' \ '*-d+[Provide one or more additional (custom) demo file(s)]:DEMO_FILE:_files' \ diff --git a/extra/completions/stackablectl.bash b/extra/completions/stackablectl.bash index 5000e636..095ed06b 100644 --- a/extra/completions/stackablectl.bash +++ b/extra/completions/stackablectl.bash @@ -5567,17 +5567,13 @@ _stackablectl() { return 0 ;; stackablectl__stacklet__credentials) - opts="-n -l -d -s -r -h -V --product-ns --product-namespace --log-level --no-cache --demo-file --stack-file --release-file --helm-repo-stable --helm-repo-test --helm-repo-dev --chart-source --help --version " + opts="-n -l -d -s -r -h -V --namespace --log-level --no-cache --demo-file --stack-file --release-file --helm-repo-stable --helm-repo-test --helm-repo-dev --chart-source --help --version " if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 fi case "${prev}" in - --product-namespace) - COMPREPLY=($(compgen -f "${cur}")) - return 0 - ;; - --product-ns) + --namespace) COMPREPLY=($(compgen -f "${cur}")) return 0 ;; diff --git a/extra/completions/stackablectl.elv b/extra/completions/stackablectl.elv index e4a5694b..f943defe 100644 --- a/extra/completions/stackablectl.elv +++ b/extra/completions/stackablectl.elv @@ -475,8 +475,7 @@ set edit:completion:arg-completer[stackablectl] = {|@words| } &'stackablectl;stacklet;credentials'= { cand -n 'Namespace in the cluster used to deploy the products' - cand --product-namespace 'Namespace in the cluster used to deploy the products' - cand --product-ns 'Namespace in the cluster used to deploy the products' + cand --namespace 'Namespace in the cluster used to deploy the products' cand -l 'Log level this application uses' cand --log-level 'Log level this application uses' cand -d 'Provide one or more additional (custom) demo file(s)' diff --git a/extra/completions/stackablectl.fish b/extra/completions/stackablectl.fish index 79b9482f..7fe840ee 100644 --- a/extra/completions/stackablectl.fish +++ b/extra/completions/stackablectl.fish @@ -288,7 +288,7 @@ complete -c stackablectl -n "__fish_stackablectl_using_subcommand stacklet; and complete -c stackablectl -n "__fish_stackablectl_using_subcommand stacklet; and not __fish_seen_subcommand_from credentials list help" -f -a "credentials" -d 'Display credentials for a stacklet' complete -c stackablectl -n "__fish_stackablectl_using_subcommand stacklet; and not __fish_seen_subcommand_from credentials list help" -f -a "list" -d 'List deployed stacklets' complete -c stackablectl -n "__fish_stackablectl_using_subcommand stacklet; and not __fish_seen_subcommand_from credentials list help" -f -a "help" -d 'Print this message or the help of the given subcommand(s)' -complete -c stackablectl -n "__fish_stackablectl_using_subcommand stacklet; and __fish_seen_subcommand_from credentials" -s n -l product-namespace -l product-ns -d 'Namespace in the cluster used to deploy the products' -r +complete -c stackablectl -n "__fish_stackablectl_using_subcommand stacklet; and __fish_seen_subcommand_from credentials" -s n -l namespace -d 'Namespace in the cluster used to deploy the products' -r complete -c stackablectl -n "__fish_stackablectl_using_subcommand stacklet; and __fish_seen_subcommand_from credentials" -s l -l log-level -d 'Log level this application uses' -r complete -c stackablectl -n "__fish_stackablectl_using_subcommand stacklet; and __fish_seen_subcommand_from credentials" -s d -l demo-file -d 'Provide one or more additional (custom) demo file(s)' -r -F complete -c stackablectl -n "__fish_stackablectl_using_subcommand stacklet; and __fish_seen_subcommand_from credentials" -s s -l stack-file -d 'Provide one or more additional (custom) stack file(s)' -r -F diff --git a/extra/completions/stackablectl.nu b/extra/completions/stackablectl.nu index 5bb59dd6..448f1f63 100644 --- a/extra/completions/stackablectl.nu +++ b/extra/completions/stackablectl.nu @@ -493,8 +493,7 @@ module completions { export extern "stackablectl stacklet credentials" [ product_name: string # The name of the product, for example 'superset' stacklet_name: string # The name of the stacklet, for example 'superset' - --product-namespace(-n): string # Namespace in the cluster used to deploy the products - --product-ns: string # Namespace in the cluster used to deploy the products + --namespace(-n): string # Namespace in the cluster used to deploy the products --log-level(-l): string # Log level this application uses --no-cache # Do not cache the remote (default) demo, stack and release files --demo-file(-d): string # Provide one or more additional (custom) demo file(s) diff --git a/rust/stackable-cockpit/src/platform/demo/spec.rs b/rust/stackable-cockpit/src/platform/demo/spec.rs index 75847116..0d8ca246 100644 --- a/rust/stackable-cockpit/src/platform/demo/spec.rs +++ b/rust/stackable-cockpit/src/platform/demo/spec.rs @@ -97,18 +97,14 @@ impl DemoSpec { /// - Does the demo support to be installed in the requested namespace? /// - Does the cluster have enough resources available to run this demo? #[instrument(skip_all)] - pub async fn check_prerequisites( - &self, - client: &Client, - product_namespace: &str, - ) -> Result<(), Error> { + pub async fn check_prerequisites(&self, client: &Client, namespace: &str) -> Result<(), Error> { debug!("Checking prerequisites before installing demo"); // Returns an error if the demo doesn't support to be installed in the // requested namespace - if !self.supports_namespace(product_namespace) { + if !self.supports_namespace(namespace) { return Err(Error::UnsupportedNamespace { - requested: product_namespace.to_string(), + requested: namespace.to_owned(), supported: self.supported_namespaces.clone(), }); } diff --git a/rust/stackable-cockpit/src/platform/manifests.rs b/rust/stackable-cockpit/src/platform/manifests.rs index b92814c1..7a5df63a 100644 --- a/rust/stackable-cockpit/src/platform/manifests.rs +++ b/rust/stackable-cockpit/src/platform/manifests.rs @@ -62,18 +62,23 @@ pub enum Error { pub trait InstallManifestsExt { // TODO (Techassi): This step shouldn't care about templating the manifests nor fetching them from remote - #[instrument(skip_all, fields(%product_namespace))] + #[instrument(skip_all, fields(%namespace))] #[allow(async_fn_in_trait)] async fn install_manifests( manifests: &[ManifestSpec], parameters: &HashMap, - product_namespace: &str, + namespace: &str, labels: Labels, client: &Client, transfer_client: &xfer::Client, ) -> Result<(), Error> { debug!("Installing manifests"); + let mut parameters = parameters.clone(); + // We add the NAMESPACE parameter, so that stacks/demos can use that to render e.g. the + // fqdn service names [which contain the namespace]. + parameters.insert("NAMESPACE".to_owned(), namespace.to_owned()); + for manifest in manifests { match manifest { ManifestSpec::HelmChart(helm_file) => { @@ -85,7 +90,7 @@ pub trait InstallManifestsExt { })?; let helm_chart: helm::Chart = transfer_client - .get(&helm_file, &Template::new(parameters).then(Yaml::new())) + .get(&helm_file, &Template::new(¶meters).then(Yaml::new())) .await .context(FileTransferSnafu)?; @@ -111,7 +116,7 @@ pub trait InstallManifestsExt { chart_version: Some(&helm_chart.version), }, Some(&values_yaml), - product_namespace, + namespace, true, ) .context(InstallHelmReleaseSnafu { @@ -130,12 +135,12 @@ pub trait InstallManifestsExt { })?; let manifests = transfer_client - .get(&path_or_url, &Template::new(parameters)) + .get(&path_or_url, &Template::new(¶meters)) .await .context(FileTransferSnafu)?; client - .deploy_manifests(&manifests, product_namespace, labels.clone()) + .deploy_manifests(&manifests, namespace, labels.clone()) .await .context(DeployManifestSnafu)? } diff --git a/rust/stackable-cockpit/src/platform/stack/spec.rs b/rust/stackable-cockpit/src/platform/stack/spec.rs index 7e2c87e1..5bba6224 100644 --- a/rust/stackable-cockpit/src/platform/stack/spec.rs +++ b/rust/stackable-cockpit/src/platform/stack/spec.rs @@ -111,21 +111,17 @@ impl StackSpec { /// - Does the stack support to be installed in the requested namespace? /// - Does the cluster have enough resources available to run this stack? #[instrument(skip_all)] - pub async fn check_prerequisites( - &self, - client: &Client, - product_namespace: &str, - ) -> Result<(), Error> { + pub async fn check_prerequisites(&self, client: &Client, namespace: &str) -> Result<(), Error> { debug!("Checking prerequisites before installing stack"); // Returns an error if the stack doesn't support to be installed in the // requested product namespace. When installing a demo, this check is // already done on the demo spec level, however we still need to check // here, as stacks can be installed on their own. - if !self.supports_namespace(product_namespace) { + if !self.supports_namespace(namespace) { return Err(Error::UnsupportedNamespace { supported: self.supported_namespaces.clone(), - requested: product_namespace.to_string(), + requested: namespace.to_owned(), }); } @@ -204,7 +200,7 @@ impl StackSpec { &self, release_list: release::ReleaseList, operator_namespace: &str, - _product_namespace: &str, // TODO (@NickLarsenNZ): remove this field + _namespace: &str, // TODO (@NickLarsenNZ): remove this field chart_source: &ChartSourceType, ) -> Result<(), Error> { info!(self.release, "Trying to install release"); diff --git a/rust/stackablectl/CHANGELOG.md b/rust/stackablectl/CHANGELOG.md index 019f653e..8daf172d 100644 --- a/rust/stackablectl/CHANGELOG.md +++ b/rust/stackablectl/CHANGELOG.md @@ -4,9 +4,14 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +### Added + +- Pass the stack/demo namespace as a templating variable `NAMESPACE` to manifests. + This should unblock demos to run in all namespaces, as they can template the namespace e.g. for the FQDN of services ([#355]). + ### Changed -- Renamed `--product-namespace` argument to `--namespace` ([#373]). +- Renamed `--product-namespace` argument to `--namespace` ([#373], [#355]). - Kept `--product-namespace` as a hidden alias to be removed in a later release. ### Fixed @@ -25,6 +30,7 @@ All notable changes to this project will be documented in this file. - Improve tracing and log output ([#365]). [#351]: https://github.com/stackabletech/stackable-cockpit/pull/351 +[#355]: https://github.com/stackabletech/stackable-cockpit/pull/355 [#364]: https://github.com/stackabletech/stackable-cockpit/pull/364 [#365]: https://github.com/stackabletech/stackable-cockpit/pull/365 diff --git a/rust/stackablectl/src/cmds/stacklet.rs b/rust/stackablectl/src/cmds/stacklet.rs index eed7edcf..ab87abb8 100644 --- a/rust/stackablectl/src/cmds/stacklet.rs +++ b/rust/stackablectl/src/cmds/stacklet.rs @@ -48,10 +48,10 @@ pub struct StackletCredentialsArgs { short = 'n', global = true, default_value = DEFAULT_NAMESPACE, - visible_aliases(["product-ns"]), + aliases(["product-ns", "product-namespace"]), long_help = "Namespace in the cluster used to deploy the products. Use this to select a different namespace for credential lookup.")] - pub product_namespace: String, + pub namespace: String, } #[derive(Debug, Args)] @@ -211,7 +211,7 @@ async fn credentials_cmd(args: &StackletCredentialsArgs) -> Result Result, post_hints: Vec, @@ -20,10 +20,10 @@ impl ContextExt for ResultContext { let mut ctx = tera::Context::new(); ctx.insert("default_operator_namespace", DEFAULT_OPERATOR_NAMESPACE); - ctx.insert("default_product_namespace", DEFAULT_NAMESPACE); + ctx.insert("default_namespace", DEFAULT_NAMESPACE); ctx.insert("used_operator_namespace", &self.used_operator_namespace); - ctx.insert("used_product_namespace", &self.used_product_namespace); + ctx.insert("used_namespace", &self.used_namespace); ctx.insert("command_hints", &self.command_hints); ctx.insert("post_hints", &self.post_hints);