Skip to content

Commit 863b169

Browse files
committed
feat: Support coffee operator
1 parent a78def7 commit 863b169

1 file changed

Lines changed: 38 additions & 4 deletions

File tree

rust/stackablectl/src/cmds/operator.rs

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ const INSTALL_AFTER_HELP_TEXT: &str = "Examples:
3838
3939
Use \"stackablectl operator install <OPERATOR> -c <OPTION>\" to create a local cluster";
4040

41+
const COFFEE_ASCII_ART: &str = r#"
42+
) )
43+
( (
44+
.------.
45+
| |]
46+
\ /
47+
`----'
48+
49+
Psst... "coffee" is not an operator, but we get it.
50+
Stackable runs on coffee too. Have a great day! ☕
51+
"#;
52+
4153
#[derive(Debug, Args)]
4254
pub struct OperatorArgs {
4355
#[command(subcommand)]
@@ -98,7 +110,7 @@ Possible valid values are:
98110
99111
Use \"stackablectl operator list\" to list available versions for all operators
100112
Use \"stackablectl operator describe <OPERATOR>\" to get available versions for one operator")]
101-
operators: Vec<operator::OperatorSpec>,
113+
operators: Vec<String>,
102114

103115
/// Namespace in the cluster used to deploy the operators
104116
#[arg(long, default_value = DEFAULT_OPERATOR_NAMESPACE, visible_aliases(["operator-ns"]))]
@@ -169,6 +181,9 @@ pub enum CmdError {
169181

170182
#[snafu(display("OCI error"))]
171183
OciError { source: oci::Error },
184+
185+
#[snafu(display("failed to parse operator spec"))]
186+
ParseOperatorSpec { source: operator::SpecParseError },
172187
}
173188

174189
/// This list contains a list of operator version grouped by stable, test and
@@ -315,6 +330,25 @@ async fn install_cmd(args: &OperatorInstallArgs, cli: &Cli) -> Result<String, Cm
315330
info!("Installing operator(s)");
316331
Span::current().pb_set_message("Installing operator(s)");
317332

333+
let operators: Vec<operator::OperatorSpec> = args
334+
.operators
335+
.iter()
336+
.filter_map(|operator| match operator.as_str() {
337+
"coffee" | "coffe" => {
338+
indicatif_println!("{COFFEE_ASCII_ART}");
339+
None
340+
}
341+
_ => Some(operator),
342+
})
343+
.map(|s| s.parse().context(ParseOperatorSpecSnafu))
344+
.collect::<Result<_, _>>()?;
345+
346+
// In case no operators need to be installed (e.g. coffee was already installed), there is no
347+
// need to connect to Kubernetes and potentially produce error messages.
348+
if operators.is_empty() {
349+
return Ok(String::new());
350+
}
351+
318352
args.local_cluster
319353
.install_if_needed()
320354
.await
@@ -328,7 +362,7 @@ async fn install_cmd(args: &OperatorInstallArgs, cli: &Cli) -> Result<String, Cm
328362
namespace: args.operator_namespace.clone(),
329363
})?;
330364

331-
for operator in &args.operators {
365+
for operator in &operators {
332366
operator
333367
.install(
334368
&args.operator_namespace,
@@ -349,8 +383,8 @@ async fn install_cmd(args: &OperatorInstallArgs, cli: &Cli) -> Result<String, Cm
349383
)
350384
.with_output(format!(
351385
"Installed {num_of_operators} {suffix}",
352-
num_of_operators = args.operators.len(),
353-
suffix = if args.operators.len() == 1 {
386+
num_of_operators = operators.len(),
387+
suffix = if operators.len() == 1 {
354388
"operator"
355389
} else {
356390
"operators"

0 commit comments

Comments
 (0)