Skip to content

Commit

Permalink
Revert "feat: use installation type in cli commands (#3675)" (#3682)
Browse files Browse the repository at this point in the history
This reverts commit 3d87bf1.

CI was unstable when this was merged, need to revert to get back to a stable master
  • Loading branch information
digikata authored Nov 10, 2023
1 parent 3d87bf1 commit 10bda30
Show file tree
Hide file tree
Showing 20 changed files with 148 additions and 293 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/cd_dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ jobs:
- name: Run diagnostics
if: ${{ !success() }}
timeout-minutes: 5
run: ~/.fluvio/bin/fluvio cluster diagnostics
run: ~/.fluvio/bin/fluvio cluster diagnostics --k8
- name: Upload diagnostics
uses: actions/upload-artifact@v3
timeout-minutes: 5
Expand Down Expand Up @@ -236,7 +236,7 @@ jobs:
- name: Run diagnostics
if: ${{ !success() }}
timeout-minutes: 5
run: fluvio cluster diagnostics
run: fluvio cluster diagnostics --k8
- 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
run: fluvio cluster diagnostics --local
- 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
run: fluvio cluster diagnostics --k8
- name: Upload diagnostics
timeout-minutes: 5
if: ${{ !success() }}
Expand Down Expand Up @@ -903,7 +903,7 @@ jobs:
- name: Run diagnostics
if: ${{ !success() }}
timeout-minutes: 5
run: ~/bin/fluvio cluster diagnostics
run: ~/bin/fluvio cluster diagnostics --k8
- name: Upload logs
timeout-minutes: 5
if: ${{ !success() }}
Expand Down Expand Up @@ -1075,7 +1075,7 @@ jobs:
- name: Run diagnostics
if: ${{ !success() }}
timeout-minutes: 5
run: fluvio cluster diagnostics
run: fluvio cluster diagnostics --k8
- name: Upload diagnostics
uses: actions/upload-artifact@v3
timeout-minutes: 5
Expand Down Expand Up @@ -1216,12 +1216,12 @@ jobs:

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

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

- 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
run: fluvio cluster diagnostics --k8
- name: Upload diagnostics
uses: actions/upload-artifact@v3
timeout-minutes: 5
Expand Down
18 changes: 9 additions & 9 deletions crates/fluvio-cli/src/profile/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@ use clap::Parser;
use anyhow::Result;

use fluvio::config::{ConfigFile, TlsPolicy};
use fluvio_cluster::InstallationType;

#[derive(Debug, Parser)]
pub struct ManualAddOpt {
/// Name of profile to add
profile_name: String,

/// Address of cluster, e.g. 127.0.0.1:9003
/// 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 @@ -27,10 +23,14 @@ impl ManualAddOpt {
&self.cluster_address,
&def_tls,
)?;
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);
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"));
}
}
Err(_) => println!("no profile can be found"),
}
Expand Down
18 changes: 5 additions & 13 deletions crates/fluvio-cli/src/profile/list.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::sync::Arc;

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

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

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

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

Row::from([active, profile_name, cluster, addr, tls, &installation_type])
Row::from([active, profile_name, cluster, addr, tls])
})
.collect()
}
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("Local Fluvio running")]
#[error("Loocal Fluvio running")]
LocalClusterExists,

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

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

Expand All @@ -11,50 +8,40 @@ 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 = "k8", conflicts_with = "sys_only")]
k8_only: bool,
#[arg(long, conflicts_with = "local", conflicts_with = "sys")]
k8: bool,

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

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

if self.sys_only {
if self.sys {
builder.uninstall_local(false);
builder.uninstall_k8(false);
builder.uninstall_sys(true);
} else if self.k8_only {
} else if self.local {
builder.uninstall_local(true);
builder.uninstall_k8(false);
builder.uninstall_sys(false);
} else if self.k8 {
builder.uninstall_local(false);
builder.uninstall_k8(true);
builder.uninstall_sys(false);
} else {
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);
}
}
builder.uninstall_local(true);
builder.uninstall_k8(true);
builder.uninstall_sys(true);
}

if let Some(namespace) = self.namespace {
Expand Down
78 changes: 44 additions & 34 deletions crates/fluvio-cluster/src/cli/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,36 @@ use fluvio::config::ConfigFile;
use fluvio::metadata::{topic::TopicSpec, partition::PartitionSpec, spg::SpuGroupSpec, spu::SpuSpec};
use fluvio_sc_schema::objects::Metadata;

use crate::InstallationType;
use crate::cli::ClusterCliError;
use crate::cli::start::get_log_directory;
use crate::start::local::{DEFAULT_DATA_DIR as DEFAULT_LOCAL_DIR, DEFAULT_METADATA_SUB_DIR};
use crate::start::local::DEFAULT_DATA_DIR as DEFAULT_LOCAL_DIR;

#[derive(Debug)]
enum ProfileType {
K8,
Local,
Cloud,
}

#[derive(Parser, Debug)]
pub struct DiagnosticsOpt {
#[arg(long)]
quiet: bool,

#[arg(long)]
k8: bool,

#[arg(long)]
local: bool,

#[arg(long)]
cloud: bool,
}

impl DiagnosticsOpt {
pub async fn process(self) -> Result<()> {
let installation_ty = self.get_installation_ty()?;
println!("Using installation: {installation_ty:#?}");
let profile_ty = self.get_profile_ty()?;
println!("Using profile type: {profile_ty:#?}");
let temp_dir = tempfile::Builder::new()
.prefix("fluvio-diagnostics")
.tempdir()?;
Expand All @@ -42,25 +57,21 @@ impl DiagnosticsOpt {
};

// write internal fluvio cluster internal state
match installation_ty {
match profile_ty {
// Local cluster
InstallationType::Local | InstallationType::ReadOnly => {
self.copy_local_logs(temp_path)?;
self.copy_local_metadata(temp_path)?;
for spu in spu_specs {
self.spu_disk_usage(None, temp_path, &spu.spec)?;
}
}
// Local cluster with k8 metadata
InstallationType::LocalK8 => {
ProfileType::Local => {
self.write_helm(temp_path)?;
self.copy_local_logs(temp_path)?;
for spu in spu_specs {
self.spu_disk_usage(None, temp_path, &spu.spec)?;
}
}
// Kubernetes cluster
InstallationType::K8 => {
// Cloud cluster
ProfileType::Cloud => {
println!("Cannot collect logs from Cloud, skipping");
}
// Guess Kubernetes cluster
ProfileType::K8 => {
let kubectl = match which("kubectl") {
Ok(kubectl) => kubectl,
Err(_) => {
Expand Down Expand Up @@ -99,11 +110,23 @@ impl DiagnosticsOpt {
Ok(())
}

fn get_installation_ty(&self) -> Result<InstallationType> {
let config = ConfigFile::load_default_or_new()?;
Ok(InstallationType::load_or_default(
config.config().current_cluster()?,
))
// get type of profile
fn get_profile_ty(&self) -> Result<ProfileType> {
if self.k8 {
Ok(ProfileType::K8)
} else if self.local {
Ok(ProfileType::Local)
} else if self.cloud {
Ok(ProfileType::Cloud)
} else {
let config = ConfigFile::load_default_or_new()?;
match config.config().current_profile_name() {
Some("local") => Ok(ProfileType::Local),
// Cloud cluster
Some(other) if other.contains("cloud") => Ok(ProfileType::Cloud),
_ => Ok(ProfileType::K8),
}
}
}

fn zip_files(&self, source: &Path, output: &mut std::fs::File) -> Result<(), std::io::Error> {
Expand Down Expand Up @@ -135,19 +158,6 @@ impl DiagnosticsOpt {
Ok(())
}

fn copy_local_metadata(&self, dest_dir: &Path) -> Result<()> {
let metadata_path = DEFAULT_LOCAL_DIR
.to_owned()
.unwrap_or_default()
.join(DEFAULT_METADATA_SUB_DIR);
if metadata_path.exists() {
println!("reading local metadata from {metadata_path:?}");
let mut metadata_file = std::fs::File::create(dest_dir.join("metadata.tar.gz"))?;
self.zip_files(&metadata_path, &mut metadata_file)?;
}
Ok(())
}

/// get logs from k8 pod
fn copy_kubernetes_logs(&self, kubectl: &Path, dest_dir: &Path) -> Result<()> {
let pods = cmd!(
Expand Down
Loading

0 comments on commit 10bda30

Please sign in to comment.