Skip to content

Commit

Permalink
fix(ctl): Skip creating operator-namespace when passing `--skip-relea…
Browse files Browse the repository at this point in the history
…se` in stack/demo command (#106)

* Initial commit

* Apply suggestion
  • Loading branch information
Techassi authored Sep 12, 2023
1 parent 1b65f88 commit dd42d58
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 65 deletions.
17 changes: 7 additions & 10 deletions rust/stackable-cockpit/src/platform/demo/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,13 @@ impl DemoSpecV2 {
.context(StackSnafu)?;
self.check_prerequisites(product_namespace).await?;

// Install release
stack_spec
.install_release(
release_list,
operator_namespace,
product_namespace,
skip_release,
)
.await
.context(StackSnafu)?;
// Install release if not opted out
if !skip_release {
stack_spec
.install_release(release_list, operator_namespace, product_namespace)
.await
.context(StackSnafu)?;
}

// Install stack
stack_spec
Expand Down
8 changes: 1 addition & 7 deletions rust/stackable-cockpit/src/platform/stack/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,8 @@ impl StackSpecV2 {
release_list: ReleaseList,
operator_namespace: &str,
product_namespace: &str,
skip_release_install: bool,
) -> Result<(), StackError> {
info!("Installing release for stack");

if skip_release_install {
info!("Skipping release installation during stack installation process");
return Ok(());
}
info!("Trying to install release {}", self.release);

// Get the release by name
let release = release_list
Expand Down
14 changes: 8 additions & 6 deletions rust/stackablectl/src/cmds/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,18 +275,20 @@ async fn install_cmd(
.clone()
.unwrap_or(DEFAULT_OPERATOR_NAMESPACE.into());

namespace::create_if_needed(operator_namespace.clone())
.await
.context(NamespaceSnafu {
namespace: operator_namespace.clone(),
})?;

let product_namespace = args
.namespaces
.product_namespace
.clone()
.unwrap_or(DEFAULT_PRODUCT_NAMESPACE.into());

if !args.skip_release {
namespace::create_if_needed(operator_namespace.clone())
.await
.context(NamespaceSnafu {
namespace: operator_namespace.clone(),
})?;
}

namespace::create_if_needed(product_namespace.clone())
.await
.context(NamespaceSnafu {
Expand Down
36 changes: 26 additions & 10 deletions rust/stackablectl/src/cmds/release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ use tracing::{debug, info, instrument};
use stackable_cockpit::{
common::ListError,
constants::DEFAULT_OPERATOR_NAMESPACE,
platform::release::{ReleaseInstallError, ReleaseList, ReleaseUninstallError},
platform::{
namespace::{self, NamespaceError},
release::{ReleaseInstallError, ReleaseList, ReleaseUninstallError},
},
utils::path::PathOrUrlParseError,
xfer::{cache::Cache, FileTransferClient, FileTransferError},
};
Expand Down Expand Up @@ -117,6 +120,12 @@ pub enum ReleaseCmdError {

#[snafu(display("transfer error"))]
TransferError { source: FileTransferError },

#[snafu(display("failed to create namespace '{namespace}'"))]
NamespaceError {
source: NamespaceError,
namespace: String,
},
}

impl ReleaseArgs {
Expand Down Expand Up @@ -235,14 +244,21 @@ async fn install_cmd(
) -> Result<String, ReleaseCmdError> {
info!("Installing release");

// Install local cluster if needed
args.local_cluster
.install_if_needed(None)
.await
.context(CommonClusterArgsSnafu)?;

match release_list.get(&args.release) {
Some(release) => {
// Install local cluster if needed
args.local_cluster
.install_if_needed(None)
.await
.context(CommonClusterArgsSnafu)?;

// Create operator namespace if needed
namespace::create_if_needed(args.operator_namespace.clone())
.await
.context(NamespaceSnafu {
namespace: args.operator_namespace.clone(),
})?;

release
.install(
&args.included_products,
Expand All @@ -251,7 +267,7 @@ async fn install_cmd(
)
.context(ReleaseInstallSnafu)?;

Ok("Installed release".into())
Ok(format!("Installed release {}", args.release))
}
None => Ok("No such release".into()),
}
Expand All @@ -261,15 +277,15 @@ async fn uninstall_cmd(
args: &ReleaseUninstallArgs,
release_list: ReleaseList,
) -> Result<String, ReleaseCmdError> {
info!("Installing release");
info!("Uninstalling release");

match release_list.get(&args.release) {
Some(release) => {
release
.uninstall(&args.operator_namespace)
.context(ReleaseUninstallSnafu)?;

Ok("Installed release".into())
Ok(format!("Uninstalled release {}", args.release))
}
None => Ok("No such release".into()),
}
Expand Down
64 changes: 32 additions & 32 deletions rust/stackablectl/src/cmds/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,54 +242,54 @@ async fn install_cmd(
.await
.context(ListSnafu)?;

// Install local cluster if needed
args.local_cluster
.install_if_needed(None)
.await
.context(CommonClusterArgsSnafu)?;

let operator_namespace = args
.namespaces
.operator_namespace
.clone()
.unwrap_or(DEFAULT_OPERATOR_NAMESPACE.into());

namespace::create_if_needed(operator_namespace.clone())
.await
.context(NamespaceSnafu {
namespace: operator_namespace.clone(),
})?;

let product_namespace = args
.namespaces
.product_namespace
.clone()
.unwrap_or(DEFAULT_PRODUCT_NAMESPACE.into());

namespace::create_if_needed(product_namespace.clone())
.await
.context(NamespaceSnafu {
namespace: product_namespace.clone(),
})?;
let operator_namespace = args
.namespaces
.operator_namespace
.clone()
.unwrap_or(DEFAULT_OPERATOR_NAMESPACE.into());

match stack_list.get(&args.stack_name) {
Some(stack_spec) => {
// Install local cluster if needed
args.local_cluster
.install_if_needed(None)
.await
.context(CommonClusterArgsSnafu)?;

// Check perquisites
stack_spec
.check_prerequisites(&product_namespace)
.await
.context(StackSnafu)?;

// Install release
stack_spec
.install_release(
release_list,
&operator_namespace,
&product_namespace,
args.skip_release,
)
// Install release if not opted out
if !args.skip_release {
namespace::create_if_needed(operator_namespace.clone())
.await
.context(NamespaceSnafu {
namespace: operator_namespace.clone(),
})?;

stack_spec
.install_release(release_list, &operator_namespace, &product_namespace)
.await
.context(StackSnafu)?;
} else {
info!("Skipping release installation during stack installation process");
}

// Create product namespace if needed
namespace::create_if_needed(product_namespace.clone())
.await
.context(StackSnafu)?;
.context(NamespaceSnafu {
namespace: product_namespace.clone(),
})?;

// Install stack
stack_spec
Expand Down

0 comments on commit dd42d58

Please sign in to comment.