Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions docs/modules/stackablectl/partials/commands/cache.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ Options:
Cached files are saved at '$XDG_CACHE_HOME/stackablectl', which is usually
'$HOME/.cache/stackablectl' when not explicitly set.

--offline
Do not request any remote files via the network

-h, --help
Print help (see a summary with '-h')

Expand Down
3 changes: 0 additions & 3 deletions docs/modules/stackablectl/partials/commands/completions.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ Options:
Cached files are saved at '$XDG_CACHE_HOME/stackablectl', which is usually
'$HOME/.cache/stackablectl' when not explicitly set.

--offline
Do not request any remote files via the network

-h, --help
Print help (see a summary with '-h')

Expand Down
4 changes: 2 additions & 2 deletions docs/modules/stackablectl/partials/commands/demo.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ Options:
Cached files are saved at '$XDG_CACHE_HOME/stackablectl', which is usually
'$HOME/.cache/stackablectl' when not explicitly set.

--offline
Do not request any remote files via the network
--release <RELEASE>
Target a specific Stackable release

-h, --help
Print help (see a summary with '-h')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ Options:

Defaults to the image of the target container if not specified.

--offline
Do not request any remote files via the network

-h, --help
Print help (see a summary with '-h')

Expand Down
3 changes: 0 additions & 3 deletions docs/modules/stackablectl/partials/commands/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ Options:
Cached files are saved at '$XDG_CACHE_HOME/stackablectl', which is usually
'$HOME/.cache/stackablectl' when not explicitly set.

--offline
Do not request any remote files via the network

-h, --help
Print help (see a summary with '-h')

Expand Down
3 changes: 0 additions & 3 deletions docs/modules/stackablectl/partials/commands/operator.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ Options:
Cached files are saved at '$XDG_CACHE_HOME/stackablectl', which is usually
'$HOME/.cache/stackablectl' when not explicitly set.

--offline
Do not request any remote files via the network

-h, --help
Print help (see a summary with '-h')

Expand Down
3 changes: 0 additions & 3 deletions docs/modules/stackablectl/partials/commands/release.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ Options:
Cached files are saved at '$XDG_CACHE_HOME/stackablectl', which is usually
'$HOME/.cache/stackablectl' when not explicitly set.

--offline
Do not request any remote files via the network

-h, --help
Print help (see a summary with '-h')

Expand Down
3 changes: 0 additions & 3 deletions docs/modules/stackablectl/partials/commands/stack.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ Options:
Cached files are saved at '$XDG_CACHE_HOME/stackablectl', which is usually
'$HOME/.cache/stackablectl' when not explicitly set.

--offline
Do not request any remote files via the network

-h, --help
Print help (see a summary with '-h')

Expand Down
3 changes: 0 additions & 3 deletions docs/modules/stackablectl/partials/commands/stacklet.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ Options:
Cached files are saved at '$XDG_CACHE_HOME/stackablectl', which is usually
'$HOME/.cache/stackablectl' when not explicitly set.

--offline
Do not request any remote files via the network

-h, --help
Print help (see a summary with '-h')

Expand Down
37 changes: 4 additions & 33 deletions extra/completions/_stackablectl

Large diffs are not rendered by default.

82 changes: 49 additions & 33 deletions extra/completions/stackablectl.bash

Large diffs are not rendered by default.

37 changes: 4 additions & 33 deletions extra/completions/stackablectl.elv

Large diffs are not rendered by default.

39 changes: 5 additions & 34 deletions extra/completions/stackablectl.fish

Large diffs are not rendered by default.

37 changes: 4 additions & 33 deletions extra/completions/stackablectl.nu

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions extra/man/stackablectl.1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions rust/stackablectl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ Options:
Cached files are saved at '$XDG_CACHE_HOME/stackablectl', which is usually
'$HOME/.cache/stackablectl' when not explicitly set.

--offline
Do not request any remote files via the network

-h, --help
Print help (see a summary with '-h')

Expand Down
36 changes: 18 additions & 18 deletions rust/stackablectl/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,19 @@ use tracing::{debug, instrument, Level};
use stackable_cockpit::{
constants::{HELM_REPO_NAME_DEV, HELM_REPO_NAME_STABLE, HELM_REPO_NAME_TEST},
helm,
platform::demo::List,
utils::path::{
IntoPathOrUrl, IntoPathsOrUrls, ParsePathsOrUrls, PathOrUrl, PathOrUrlParseError,
},
xfer::{cache::Settings, Client},
xfer::cache::Settings,
};

use crate::{
args::{CommonFileArgs, CommonRepoArgs},
cmds::{cache, completions, debug, demo, operator, release, stack, stacklet},
constants::{
ENV_KEY_DEMO_FILES, ENV_KEY_RELEASE_FILES, ENV_KEY_STACK_FILES, REMOTE_DEMO_FILE,
REMOTE_RELEASE_FILE, REMOTE_STACK_FILE, USER_DIR_APPLICATION_NAME,
USER_DIR_ORGANIZATION_NAME, USER_DIR_QUALIFIER,
DEMOS_REPOSITORY_URL_BASE, ENV_KEY_DEMO_FILES, ENV_KEY_RELEASE_FILES, ENV_KEY_STACK_FILES,
REMOTE_RELEASE_FILE, USER_DIR_APPLICATION_NAME, USER_DIR_ORGANIZATION_NAME,
USER_DIR_QUALIFIER,
},
output::{ErrorContext, Output, ResultContext},
};
Expand Down Expand Up @@ -74,10 +73,6 @@ Cached files are saved at '$XDG_CACHE_HOME/stackablectl', which is usually
)]
pub no_cache: bool,

/// Do not request any remote files via the network
#[arg(long, global = true)]
pub offline: bool,

#[command(flatten)]
pub files: CommonFileArgs,

Expand All @@ -92,25 +87,30 @@ impl Cli {
/// Returns a list of demo files, consisting of entries which are either a path or URL. The list of files combines
/// the default demo file URL, [`REMOTE_DEMO_FILE`], files provided by the ENV variable [`ENV_KEY_DEMO_FILES`], and
/// lastly, files provided by the CLI argument `--demo-file`.
pub fn get_demo_files(&self) -> Result<Vec<PathOrUrl>, PathOrUrlParseError> {
let mut files = get_files(REMOTE_DEMO_FILE, ENV_KEY_DEMO_FILES)?;
pub fn get_demo_files(&self, branch: &str) -> Result<Vec<PathOrUrl>, PathOrUrlParseError> {
let branch_url = format!(
"{base}/{branch}/demos/demos-v2.yaml",
base = DEMOS_REPOSITORY_URL_BASE
);

let mut files = get_files(&branch_url, ENV_KEY_DEMO_FILES)?;

let arg_files = self.files.demo_files.clone().into_paths_or_urls()?;
files.extend(arg_files);

Ok(files)
}

pub async fn get_demo_list(&self, transfer_client: &Client) -> List {
let files = self.get_demo_files().unwrap();
List::build(&files, transfer_client).await.unwrap()
}

/// Returns a list of stack files, consisting of entries which are either a path or URL. The list of files combines
/// the default stack file URL, [`REMOTE_STACK_FILE`], files provided by the ENV variable [`ENV_KEY_STACK_FILES`],
/// and lastly, files provided by the CLI argument `--stack-file`.
pub fn get_stack_files(&self) -> Result<Vec<PathOrUrl>, PathOrUrlParseError> {
let mut files = get_files(REMOTE_STACK_FILE, ENV_KEY_STACK_FILES)?;
pub fn get_stack_files(&self, branch: &str) -> Result<Vec<PathOrUrl>, PathOrUrlParseError> {
let branch_url = format!(
"{base}/{branch}/stacks/stacks-v2.yaml",
base = DEMOS_REPOSITORY_URL_BASE
);

let mut files = get_files(&branch_url, ENV_KEY_STACK_FILES)?;

let arg_files = self.files.stack_files.clone().into_paths_or_urls()?;
files.extend(arg_files);
Expand Down
51 changes: 46 additions & 5 deletions rust/stackablectl/src/cmds/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use comfy_table::{
presets::{NOTHING, UTF8_FULL},
ContentArrangement, Row, Table,
};
use snafu::{ResultExt, Snafu};
use snafu::{OptionExt, ResultExt, Snafu};
use stackable_operator::kvp::{LabelError, Labels};
use tracing::{debug, info, instrument};

Expand All @@ -30,6 +30,10 @@ use crate::{
pub struct DemoArgs {
#[command(subcommand)]
subcommand: DemoCommands,

/// Target a specific Stackable release
#[arg(long, global = true)]
release: Option<String>,
}

#[derive(Debug, Subcommand)]
Expand Down Expand Up @@ -126,6 +130,12 @@ pub enum CmdError {
#[snafu(display("no stack with name '{name}'"))]
NoSuchStack { name: String },

#[snafu(display("no release with name '{name}'"))]
NoSuchRelease { name: String },

#[snafu(display("empty release list"))]
EmptyReleaseList,

#[snafu(display("failed to build demo/stack/release list"))]
BuildList { source: list::Error },

Expand Down Expand Up @@ -155,18 +165,46 @@ impl DemoArgs {

let transfer_client = xfer::Client::new_with(cache);

let release_files = cli.get_release_files().context(PathOrUrlParseSnafu)?;
let release_list = release::ReleaseList::build(&release_files, &transfer_client)
.await
.context(BuildListSnafu)?;

let release_branch = match &self.release {
Some(release) => {
if release == "dev" {
"main".to_string()
} else {
format!("release-{release}")
}
}
None => {
let release = release_list
.inner()
.first()
.context(EmptyReleaseListSnafu)?
.0;

format!("release-{release}")
}
};

// Build demo list based on the (default) remote demo file, and additional files provided by the
// STACKABLE_DEMO_FILES env variable or the --demo-files CLI argument.
let files = cli.get_demo_files().context(PathOrUrlParseSnafu)?;
let demo_files = cli
.get_demo_files(&release_branch)
.context(PathOrUrlParseSnafu)?;

let list = demo::List::build(&files, &transfer_client)
let list = demo::List::build(&demo_files, &transfer_client)
.await
.context(BuildListSnafu)?;

match &self.subcommand {
DemoCommands::List(args) => list_cmd(args, cli, list).await,
DemoCommands::Describe(args) => describe_cmd(args, cli, list).await,
DemoCommands::Install(args) => install_cmd(args, cli, list, &transfer_client).await,
DemoCommands::Install(args) => {
install_cmd(args, cli, list, &transfer_client, &release_branch).await
}
}
}
}
Expand Down Expand Up @@ -278,6 +316,7 @@ async fn install_cmd(
cli: &Cli,
list: demo::List,
transfer_client: &xfer::Client,
release_branch: &str,
) -> Result<String, CmdError> {
info!("Installing demo {}", args.demo_name);

Expand All @@ -289,7 +328,9 @@ async fn install_cmd(
})?;

// TODO (Techassi): Try to move all this boilerplate code to build the lists out of here
let files = cli.get_stack_files().context(PathOrUrlParseSnafu)?;
let files = cli
.get_stack_files(release_branch)
.context(PathOrUrlParseSnafu)?;
let stack_list = stack::StackList::build(&files, transfer_client)
.await
.context(BuildListSnafu)?;
Expand Down
38 changes: 36 additions & 2 deletions rust/stackablectl/src/cmds/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use comfy_table::{
presets::{NOTHING, UTF8_FULL},
ContentArrangement, Table,
};
use snafu::{ResultExt, Snafu};
use snafu::{OptionExt, ResultExt, Snafu};
use stackable_operator::kvp::{LabelError, Labels};
use tracing::{debug, info, instrument};

Expand All @@ -30,6 +30,10 @@ use crate::{
pub struct StackArgs {
#[command(subcommand)]
subcommand: StackCommands,

/// Target a specific Stackable release
#[arg(long, global = true)]
release: Option<String>,
}

#[derive(Debug, Subcommand)]
Expand Down Expand Up @@ -116,6 +120,9 @@ pub enum CmdError {
#[snafu(display("failed to serialize JSON output"))]
SerializeJsonOutput { source: serde_json::Error },

#[snafu(display("empty release list"))]
EmptyReleaseList,

#[snafu(display("failed to build stack/release list"))]
BuildList { source: list::Error },

Expand All @@ -140,7 +147,34 @@ impl StackArgs {
debug!("Handle stack args");

let transfer_client = xfer::Client::new_with(cache);
let files = cli.get_stack_files().context(PathOrUrlParseSnafu)?;

let release_files = cli.get_release_files().context(PathOrUrlParseSnafu)?;
let release_list = release::ReleaseList::build(&release_files, &transfer_client)
.await
.context(BuildListSnafu)?;

let release_branch = match &self.release {
Some(release) => {
if release == "dev" {
"main".to_string()
} else {
format!("release-{release}")
}
}
None => {
let release = release_list
.inner()
.first()
.context(EmptyReleaseListSnafu)?
.0;

format!("release-{release}")
}
};

let files = cli
.get_stack_files(&release_branch)
.context(PathOrUrlParseSnafu)?;
let stack_list = stack::StackList::build(&files, &transfer_client)
.await
.context(BuildListSnafu)?;
Expand Down
2 changes: 2 additions & 0 deletions rust/stackablectl/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ pub const ENV_KEY_RELEASE_FILES: &str = "STACKABLE_RELEASE_FILES";
pub const ENV_KEY_STACK_FILES: &str = "STACKABLE_STACK_FILES";
pub const ENV_KEY_DEMO_FILES: &str = "STACKABLE_DEMO_FILES";

pub const DEMOS_REPOSITORY_URL_BASE: &str = "https://raw.githubusercontent.com/stackabletech/demos";

pub const REMOTE_DEMO_FILE: &str =
"https://raw.githubusercontent.com/stackabletech/demos/main/demos/demos-v2.yaml";

Expand Down
5 changes: 0 additions & 5 deletions rust/stackablectl/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ async fn main() -> Result<(), Error> {
// Parse the CLI args and commands
let app = Cli::parse();

// Catch if --offline is used for now
if app.offline {
todo!()
}

// Construct the tracing subscriber
let format = fmt::format()
.with_ansi(true)
Expand Down
Loading