Skip to content

Commit

Permalink
feat(fluvio-cluster): prompt when deleting cluster (#4034)
Browse files Browse the repository at this point in the history
* feat(fluvio-cluster): prompt when deleting cluster

* fix: add log that verifies cluster deletion

* chore: test fixup cluster deletes and --local

* fix: change cluster-delete script to fallback logic

---------

Co-authored-by: Alan Chen <alan@infinyon.com>
  • Loading branch information
PanGan21 and digikata committed Jun 3, 2024
1 parent f3ab403 commit 06017c2
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 13 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/fluvio-cluster/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ fluvio-controlplane-metadata = { workspace = true, features = ["k8",] }
fluvio-sc-schema = { workspace = true }
fluvio-types = { workspace = true }
fluvio-channel = { workspace = true }
dialoguer.workspace = true

[dev-dependencies]
fluvio-future = { workspace = true, features = ["task", "fixture"] }
38 changes: 37 additions & 1 deletion crates/fluvio-cluster/src/cli/delete.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use anyhow::bail;
use anyhow::Result;
use clap::Parser;
use dialoguer::Input;
use tracing::debug;
use dialoguer::theme::ColorfulTheme;

use crate::{InstallationType, cli::get_installation_type};
use crate::delete::ClusterUninstallConfig;
use crate::cli::ClusterCliError;
use crate::cli::{ClusterCliError, ConfigFile};

#[derive(Debug, Parser)]
pub struct DeleteOpt {
Expand All @@ -19,10 +21,44 @@ pub struct DeleteOpt {
#[arg(long = "sys", conflicts_with = "k8_only")]
/// Remove system chart only
sys_only: bool,

/// Do not prompt for confirmation
#[arg(long)]
force: bool,
}

impl DeleteOpt {
pub async fn process(self) -> Result<()> {
let config_file = ConfigFile::load_default_or_new()?;

let (current_cluster, current_profile) = {
let config = config_file.config();
(config.current_cluster()?, config.current_profile()?)
};

if !self.force {
let mut user_input: String = Input::with_theme(&ColorfulTheme::default()).with_prompt(&format!(
"WARNING: You are about to delete {cluster}/{endpoint}. This operation is irreversible \
and the data stored in your cluster will be permanently lost. \
\nPlease type the cluster name to confirm: {cluster} <enter> (to confirm) / or CTRL-C (to cancel)",
cluster= current_profile.cluster,
endpoint = current_cluster.endpoint,
)).interact_text()?;

user_input = user_input.trim().to_string();

if user_input != current_profile.cluster {
println!("Confirmation failed. Aborting.");
return Ok(());
}
}

println!(
"Deleting {cluster}/{endpoint}",
cluster = current_profile.cluster,
endpoint = current_cluster.endpoint,
);

let mut builder = ClusterUninstallConfig::builder();
builder.hide_spinner(false);

Expand Down
2 changes: 1 addition & 1 deletion crates/fluvio-spu/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fluvio:

# make -f src/spu/Makefile test_replica
test_replica: fluvio
$(FLUVIO_BIN) cluster delete
$(FLUVIO_BIN) cluster delete --force
$(FLUVIO_BIN) cluster start --spu $(SPU) --local --develop --rust-log=fluvio_spu=debug
$(FLUVIO_BIN) topic create test --replication $(REPLICATION)
echo "hello world" | $(FLUVIO_BIN) produce test
Expand Down
2 changes: 1 addition & 1 deletion makefiles/test.mk
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ clean_cluster:
else
clean_cluster:
echo "clean up previous installation"
$(FLUVIO_BIN) cluster delete
$(FLUVIO_BIN) cluster delete --force
endif

test-setup: build-test-ci clean_cluster
Expand Down
6 changes: 3 additions & 3 deletions tests/cli/cli-platform-cross-version.bats
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ setup_file() {
if [[ -z "$CI" ]];
then
echo "# Deleting cluster" >&3
"$FLUVIO_BIN" cluster delete --local || "$FLUVIO_BIN" cluster delete
"$FLUVIO_BIN" cluster delete --force"
else
echo "# [CI MODE] Skipping initial cleanup" >&3
fi;
Expand All @@ -57,7 +57,7 @@ teardown_file() {
if [[ -z "$SKIP_CLEANUP" ]];
then
echo "# Deleting cluster" >&3
"$FLUVIO_BIN" cluster delete --local || "$FLUVIO_BIN" cluster delete
"$FLUVIO_BIN" cluster delete --force"
else
echo "# Skipping cleanup" >&3
fi
Expand All @@ -72,7 +72,7 @@ teardown_file() {
assert_success
}

# Produce message
# Produce message
@test "Produce message" {
run bash -c 'echo "$MESSAGE" | timeout 15s "$FLUVIO_BIN" produce "$TOPIC_NAME"'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ setup_file() {
skip "don't run on stable cluster version and dev cli version" # remove this when installation type is available on stable
fi

run bash -c "$FLUVIO_BIN cluster delete --local || $FLUVIO_BIN cluster delete"
run bash -c "$FLUVIO_BIN cluster delete --force || $FLUVIO_BIN cluster delete"
assert_success

run test -d $FLUVIO_METADATA_DIR
Expand Down
12 changes: 6 additions & 6 deletions tls/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ install-local-tls:
--tls --server-cert tls/certs/server.crt --server-key tls/certs/server.key \
--ca-cert tls/certs/ca.crt --client-cert tls/certs/client-root.crt \
--client-key tls/certs/client-root.key --domain fluvio.local

uninstall-local:
$(FLUVIO_BIN) cluster delete

Expand All @@ -38,14 +38,14 @@ install-k8-tls:
--client-key tls/certs/client-root.key --domain fluvio.local

uninstall-k8:
$(FLUVIO_BIN) cluster delete
$(FLUVIO_BIN) cluster delete --force




generate-certs: clean-cert generate-ca-crt generate-server-crt generate-client-crts

generate-ca-key:
generate-ca-key:
openssl genrsa -out certs/ca.key 4096


Expand All @@ -55,14 +55,14 @@ generate-ca-crt: generate-ca-key
-subj /C=US/ST=CA/L=Sunnyvale/O=Fluvio/OU=Eng/CN=fluvio.io


generate-server-key:
generate-server-key:
openssl genrsa -out certs/server.key 4096


generate-server-csr: generate-server-key
openssl req -new -key certs/server.key \
-out certs/server.csr \
-config cert.conf
-config cert.conf


verify-csr:
Expand Down Expand Up @@ -135,7 +135,7 @@ test-mac-curl:
MAKE_DIR = $(dir $(realpath $(firstword $(MAKEFILE_LIST))))

start-nginx:
nginx -c $(MAKE_DIR)/nginx.conf
nginx -c $(MAKE_DIR)/nginx.conf

stop-nginx:
nginx -s quit
Expand Down

0 comments on commit 06017c2

Please sign in to comment.