Skip to content

Commit 55d53d7

Browse files
author
datacore-bolt-ci
committed
ci(stability): merge the develop branch
2 parents 98cc999 + 7790337 commit 55d53d7

File tree

3 files changed

+46
-28
lines changed

3 files changed

+46
-28
lines changed

k8s/plugin/src/main.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ impl CliArgs {
3939
let mut args = CliArgs::parse();
4040
let path = args.kube_config_path.clone();
4141
args.args.kubeconfig = path.clone();
42-
if let Operations::Dump(ref mut dump_args) = args.operations {
43-
dump_args
44-
.args
45-
.set_kube_config(path.clone(), args.context.clone());
46-
}
4742
args.args.context = args.context.clone();
4843
args.args.namespace = if let Some(namespace) = &args.namespace {
4944
namespace.to_string()

k8s/plugin/src/resources/mod.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,19 @@ impl ExecuteOperation for Operations {
171171
Operations::Cordon(resource) => resource.execute(cli_args).await?,
172172
Operations::Uncordon(resource) => resource.execute(cli_args).await?,
173173
Operations::Dump(resources) => {
174-
// todo: build and pass arguments
175-
resources.execute(&()).await.inspect_err(|_| {
176-
// todo: check why is this here, can it be removed?
177-
println!("Partially collected dump information: ");
178-
})?
174+
resources
175+
.execute(&supportability::K8sCtxArgs {
176+
namespace: cli_args.namespace.clone(),
177+
kubeconfig: supportability::KubeConfigArgs {
178+
path: cli_args.kubeconfig.clone(),
179+
opts: Default::default(),
180+
},
181+
})
182+
.await
183+
.inspect_err(|_| {
184+
// todo: check why is this here, can it be removed?
185+
println!("Partially collected dump information: ");
186+
})?
179187
}
180188
Operations::Upgrade(resources) => {
181189
// todo: use generic execute trait

k8s/supportability/src/lib.rs

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,9 @@ pub struct SupportArgs {
3737
#[clap(global = true, long, short = 'd', default_value = "./")]
3838
output_directory_path: String,
3939

40-
/// Kubernetes namespace of mayastor service
41-
#[clap(global = true, long, short = 'n', default_value = "mayastor")]
42-
namespace: String,
43-
44-
/// Path to kubeconfig file.
40+
/// K8s connection context arguments.
4541
#[clap(skip)]
46-
kubeconfig: KubeConfigArgs,
42+
ctx: K8sCtxArgs,
4743

4844
/// The tenant id to be used to query loki logs.
4945
#[clap(global = true, long, default_value = "openebs")]
@@ -62,14 +58,18 @@ impl SupportArgs {
6258
/// * `path` - An optional `PathBuf` representing the kubeconfig path.
6359
/// * `context` - An optional context in the kubeconfig file.
6460
pub fn set_kube_config(&mut self, path: Option<std::path::PathBuf>, context: Option<String>) {
65-
self.kubeconfig = crate::KubeConfigArgs {
61+
self.ctx.kubeconfig = crate::KubeConfigArgs {
6662
path,
6763
opts: kube::config::KubeConfigOptions {
6864
context,
6965
..Default::default()
7066
},
7167
};
7268
}
69+
/// Sets the namespace of the target install.
70+
pub fn set_namespace(&mut self, namespace: String) {
71+
self.ctx.namespace = namespace;
72+
}
7373
}
7474

7575
/// Supportability - collects state & log information of services and dumps it to a tar file.
@@ -86,10 +86,15 @@ pub struct DumpArgs {
8686

8787
#[async_trait::async_trait(?Send)]
8888
impl ExecuteOperation for DumpArgs {
89-
type Args = ();
89+
type Args = K8sCtxArgs;
9090
type Error = anyhow::Error;
91-
async fn execute(&self, _cli_args: &Self::Args) -> Result<(), Self::Error> {
92-
self.resource.execute(&self.args).await
91+
async fn execute(&self, cli_args: &Self::Args) -> Result<(), Self::Error> {
92+
let args = SupportArgs {
93+
ctx: cli_args.clone(),
94+
..self.args.clone()
95+
};
96+
97+
self.resource.execute(&args).await
9398
}
9499
}
95100

@@ -99,7 +104,7 @@ impl ExecuteOperation for Resource {
99104
type Error = anyhow::Error;
100105

101106
async fn execute(&self, cli_args: &Self::Args) -> Result<(), Self::Error> {
102-
execute_resource_dump(cli_args.clone(), cli_args.kubeconfig.clone(), self.clone())
107+
execute_resource_dump(cli_args.clone(), self.clone())
103108
.await
104109
.map_err(|e| anyhow::anyhow!("{:?}", e))
105110
}
@@ -108,18 +113,14 @@ impl ExecuteOperation for Resource {
108113
// Holds prefix of archive file name
109114
pub(crate) const ARCHIVE_PREFIX: &str = "mayastor";
110115

111-
async fn execute_resource_dump(
112-
cli_args: SupportArgs,
113-
kubeconfig: crate::KubeConfigArgs,
114-
resource: Resource,
115-
) -> Result<(), Error> {
116+
async fn execute_resource_dump(cli_args: SupportArgs, resource: Resource) -> Result<(), Error> {
116117
let mut config = DumpConfig::new(
117118
cli_args.output_directory_path,
118-
cli_args.namespace,
119+
cli_args.ctx.namespace,
119120
cli_args.loki_endpoint,
120121
cli_args.etcd_endpoint,
121122
cli_args.since,
122-
kubeconfig,
123+
cli_args.ctx.kubeconfig,
123124
cli_args.timeout,
124125
OutputFormat::Tar,
125126
cli_args.tenant_id,
@@ -200,6 +201,20 @@ impl std::fmt::Debug for KubeConfigArgs {
200201
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
201202
f.debug_struct("KubeConfigOpts")
202203
.field("kubeconfig", &self.path)
204+
.field("cluster", &self.opts.cluster)
205+
.field("context", &self.opts.context)
206+
.field("user", &self.opts.user)
203207
.finish()
204208
}
205209
}
210+
211+
/// K8s contextual arguments.
212+
#[derive(Default, Debug, Clone)]
213+
pub struct K8sCtxArgs {
214+
/// The namespace where we're installed.
215+
pub namespace: String,
216+
/// Options used when loading the kubeconfig file.
217+
/// This is necessary because the existing code uses these directly, even though the
218+
/// initial connection and context namespace is retrieved at the start.
219+
pub kubeconfig: KubeConfigArgs,
220+
}

0 commit comments

Comments
 (0)