Skip to content

Commit

Permalink
feat: use installation type in cli commands (#3691)
Browse files Browse the repository at this point in the history
  • Loading branch information
galibey authored Nov 16, 2023
1 parent 0b6df6b commit 10cd5ac
Show file tree
Hide file tree
Showing 27 changed files with 303 additions and 153 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/cd_dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ jobs:
- name: Run diagnostics
if: ${{ !success() }}
timeout-minutes: 5
run: ~/.fluvio/bin/fluvio cluster diagnostics --k8
run: ~/.fluvio/bin/fluvio cluster diagnostics
- name: Upload diagnostics
uses: actions/upload-artifact@v3
timeout-minutes: 5
Expand Down Expand Up @@ -276,7 +276,7 @@ jobs:
- name: Run diagnostics
if: ${{ !success() }}
timeout-minutes: 5
run: fluvio cluster diagnostics --k8
run: fluvio cluster diagnostics
- name: Upload diagnostics
uses: actions/upload-artifact@v3
timeout-minutes: 5
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ jobs:
- name: Run diagnostics
if: ${{ !success() }}
timeout-minutes: 5
run: fluvio cluster diagnostics --local
run: fluvio cluster diagnostics
- name: Upload diagnostics
uses: actions/upload-artifact@v3
timeout-minutes: 5
Expand Down Expand Up @@ -840,7 +840,7 @@ jobs:
- name: Run diagnostics
if: ${{ !success() }}
timeout-minutes: 5
run: fluvio cluster diagnostics --k8
run: fluvio cluster diagnostics
- name: Upload diagnostics
timeout-minutes: 5
if: ${{ !success() }}
Expand Down Expand Up @@ -905,7 +905,7 @@ jobs:
- name: Run diagnostics
if: ${{ !success() }}
timeout-minutes: 5
run: fluvio cluster diagnostics --k8
run: fluvio cluster diagnostics
- name: Upload logs
timeout-minutes: 5
if: ${{ !success() }}
Expand Down Expand Up @@ -1078,7 +1078,7 @@ jobs:
- name: Run diagnostics
if: ${{ !success() }}
timeout-minutes: 5
run: ~/.fluvio/bin/fluvio cluster diagnostics --k8
run: ~/.fluvio/bin/fluvio cluster diagnostics
- name: Upload diagnostics
uses: actions/upload-artifact@v3
timeout-minutes: 5
Expand Down Expand Up @@ -1219,12 +1219,12 @@ jobs:

- name: Shutdown Fluvio cluster
timeout-minutes: 10
run: fluvio cluster shutdown --local
run: fluvio cluster shutdown

- name: Run diagnostics
if: ${{ !success() }}
timeout-minutes: 5
run: fluvio cluster diagnostics --local
run: fluvio cluster diagnostics

- name: Upload diagnostics
uses: actions/upload-artifact@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/hourly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ jobs:
- name: Run diagnostics
if: failure()
timeout-minutes: 5
run: fluvio cluster diagnostics --k8
run: fluvio cluster diagnostics
- name: Upload diagnostics
uses: actions/upload-artifact@v3
timeout-minutes: 5
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion crates/fluvio-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ fluvio = { workspace = true }
fluvio-socket = { workspace = true }
fluvio-command = { workspace = true }
fluvio-package-index = { workspace = true }
fluvio-extension-common = { workspace = true, features = ["target"] }
fluvio-extension-common = { workspace = true, features = ["target", "installation"] }
fluvio-channel = { workspace = true }
fluvio-cli-common = { workspace = true }
fluvio-hub-util = { workspace = true, features = ["connector-cmds"] }
Expand Down
16 changes: 8 additions & 8 deletions crates/fluvio-cli/src/profile/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use clap::Parser;
use anyhow::Result;

use fluvio::config::{ConfigFile, TlsPolicy};
use fluvio_extension_common::installation::InstallationType;

#[derive(Debug, Parser)]
pub struct ManualAddOpt {
Expand All @@ -10,6 +11,9 @@ pub struct ManualAddOpt {

/// address of cluster, e.g. 127.0.0.1:9003
cluster_address: String,

/// Installation type of cluster, e.g. local, local-k8, k8
installation_type: Option<InstallationType>,
}
// todo: p2 add tls config, p1 is default disabled for manual add

Expand All @@ -23,14 +27,10 @@ impl ManualAddOpt {
&self.cluster_address,
&def_tls,
)?;
if config_file
.mut_config()
.set_current_profile(&self.profile_name)
{
println!("Switched to profile {}", &self.profile_name);
} else {
return Err(anyhow::anyhow!("error creating profile"));
}
let config = config_file.mut_config().current_cluster_mut()?;
self.installation_type.unwrap_or_default().save_to(config)?;
config_file.save()?;
println!("Switched to profile {}", &self.profile_name);
}
Err(_) => println!("no profile can be found"),
}
Expand Down
18 changes: 13 additions & 5 deletions crates/fluvio-cli/src/profile/list.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::sync::Arc;

use fluvio_extension_common::installation::InstallationType;
use serde::Serialize;
use comfy_table::Row;
use clap::Parser;
Expand Down Expand Up @@ -50,7 +51,7 @@ fn format_tls(tls: &TlsPolicy) -> &'static str {

impl TableOutputHandler for ListConfig<'_> {
fn header(&self) -> Row {
Row::from(["", "PROFILE", "CLUSTER", "ADDRESS", "TLS"])
Row::from(["", "PROFILE", "CLUSTER", "ADDRESS", "TLS", "INSTALLATION"])
}

fn content(&self) -> Vec<Row> {
Expand All @@ -65,13 +66,20 @@ impl TableOutputHandler for ListConfig<'_> {
.map(|active| if active { "*" } else { "" })
.unwrap_or("");

let (cluster, addr, tls) = self
let (cluster, addr, tls, installation) = self
.0
.cluster(&profile.cluster)
.map(|it| (&*profile.cluster, &*it.endpoint, format_tls(&it.tls)))
.unwrap_or(("", "", ""));
.map(|it| {
(
&*profile.cluster,
&*it.endpoint,
format_tls(&it.tls),
InstallationType::load_or_default(it).to_string(),
)
})
.unwrap_or(("", "", "", String::new()));

Row::from([active, profile_name, cluster, addr, tls])
Row::from([active, profile_name, cluster, addr, tls, &installation])
})
.collect()
}
Expand Down
2 changes: 1 addition & 1 deletion crates/fluvio-cluster/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ fluvio-command = { workspace = true }
fluvio-future = { workspace = true }

fluvio = { workspace = true }
fluvio-extension-common = { workspace = true, optional = true }
fluvio-extension-common = { workspace = true, features = ["installation"] }
fluvio-controlplane-metadata = { workspace = true, features = ["k8",] }
fluvio-sc-schema = { workspace = true }
fluvio-types = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/fluvio-cluster/src/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub enum ClusterCheckError {
VersionError(#[from] semver::Error),

/// local fluvio exists
#[error("Loocal Fluvio running")]
#[error("Local Fluvio running")]
LocalClusterExists,

/// Other misc
Expand Down
49 changes: 31 additions & 18 deletions crates/fluvio-cluster/src/cli/delete.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use clap::Parser;
use fluvio::config::ConfigFile;
use tracing::debug;

use crate::InstallationType;
use crate::delete::ClusterUninstallConfig;
use crate::cli::ClusterCliError;

Expand All @@ -8,40 +11,50 @@ pub struct DeleteOpt {
#[arg(long, value_name = "Kubernetes namespace")]
namespace: Option<String>,

/// Remove only local spu/sc(custom) fluvio installation
#[arg(long, conflicts_with = "k8", conflicts_with = "sys")]
local: bool,

/// Remove only k8 fluvio installation
#[arg(long, conflicts_with = "local", conflicts_with = "sys")]
k8: bool,
#[arg(long = "k8", conflicts_with = "sys_only")]
k8_only: bool,

#[arg(long, conflicts_with = "k8", conflicts_with = "local")]
/// delete system chart
sys: bool,
#[arg(long = "sys", conflicts_with = "k8_only")]
/// Remove system chart only
sys_only: bool,
}

impl DeleteOpt {
pub async fn process(self) -> Result<(), ClusterCliError> {
let mut builder = ClusterUninstallConfig::builder();
builder.hide_spinner(false);

if self.sys {
if self.sys_only {
builder.uninstall_local(false);
builder.uninstall_k8(false);
builder.uninstall_sys(true);
} else if self.local {
builder.uninstall_local(true);
builder.uninstall_k8(false);
builder.uninstall_sys(false);
} else if self.k8 {
} else if self.k8_only {
builder.uninstall_local(false);
builder.uninstall_k8(true);
builder.uninstall_sys(false);
} else {
builder.uninstall_local(true);
builder.uninstall_k8(true);
builder.uninstall_sys(true);
let config_file = ConfigFile::load_default_or_new()?;
let installation_type =
InstallationType::load_or_default(config_file.config().current_cluster()?);
debug!(?installation_type);
match installation_type {
InstallationType::K8 => {
builder.uninstall_local(false);
builder.uninstall_k8(true);
builder.uninstall_sys(true);
}
InstallationType::LocalK8 => {
builder.uninstall_local(true);
builder.uninstall_k8(true);
builder.uninstall_sys(true);
}
InstallationType::Local | InstallationType::ReadOnly => {
builder.uninstall_local(true);
builder.uninstall_k8(false);
builder.uninstall_sys(false);
}
}
}

if let Some(namespace) = self.namespace {
Expand Down
Loading

0 comments on commit 10cd5ac

Please sign in to comment.