1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
mod install;
mod uninstall;
mod minikube;
mod util;
mod check;
mod releases;
pub use process::process_cluster;
use structopt::StructOpt;
use util::*;
use minikube::SetMinikubeContext;
pub use install::InstallCommand;
use uninstall::UninstallCommand;
use check::CheckCommand;
use releases::ReleasesCommand;
#[allow(clippy::large_enum_variant)]
#[derive(Debug, StructOpt)]
#[structopt(about = "Available Commands")]
pub enum ClusterCommands {
#[structopt(name = "set-minikube-context")]
SetMinikubeContext(SetMinikubeContext),
#[structopt(name = "install")]
Install(InstallCommand),
#[structopt(name = "uninstall")]
Uninstall(UninstallCommand),
#[structopt(name = "check")]
Check(CheckCommand),
#[structopt(name = "releases")]
Releases(ReleasesCommand),
}
mod process {
use crate::CliError;
use crate::Terminal;
use super::*;
use install::process_install;
use uninstall::process_uninstall;
use minikube::process_minikube_context;
use check::run_checks;
use releases::process_releases;
pub async fn process_cluster<O>(
out: std::sync::Arc<O>,
cmd: ClusterCommands,
) -> Result<String, CliError>
where
O: Terminal,
{
match cmd {
ClusterCommands::SetMinikubeContext(ctx) => process_minikube_context(ctx),
ClusterCommands::Install(install) => process_install(out, install).await,
ClusterCommands::Uninstall(uninstall) => process_uninstall(out, uninstall).await,
ClusterCommands::Check(check) => run_checks(check).await,
ClusterCommands::Releases(releases) => process_releases(releases),
}
}
}
mod k8_util {
use std::time::Duration;
use k8_client::SharedK8Client;
use k8_obj_metadata::InputObjectMeta;
use k8_metadata_client::MetadataClient;
use k8_obj_metadata::Spec;
use fluvio_future::timer::sleep;
use k8_client::ClientError as K8ClientError;
pub async fn wait_for_delete<S: Spec>(client: SharedK8Client, input: &InputObjectMeta) {
use k8_client::http::StatusCode;
for i in 0..100u16 {
println!("checking to see if {} is deleted, count: {}", S::label(), i);
match client.retrieve_item::<S, _>(input).await {
Ok(_) => {
println!("sc {} still exists, sleeping 10 second", S::label());
sleep(Duration::from_millis(10000)).await;
}
Err(err) => match err {
K8ClientError::Client(status) if status == StatusCode::NOT_FOUND => {
println!("no sc {} found, can proceed to setup ", S::label());
return;
}
_ => panic!("error: {}", err),
},
};
}
panic!("waiting too many times, failing")
}
}