Skip to content

Commit

Permalink
chore(bors): merge pull request #641
Browse files Browse the repository at this point in the history
641: chrry-pick: #640 r=abhilashshetty04 a=abhilashshetty04



Co-authored-by: Abhilash Shetty <[email protected]>
  • Loading branch information
mayastor-bors and abhilashshetty04 committed Feb 27, 2025
2 parents 4c4d091 + 58ae7e9 commit 992d763
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
9 changes: 7 additions & 2 deletions k8s/plugin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use plugin::ExecuteOperation;
use resources::{init_rest, Error, Operations};
pub mod resources;

use std::{env, ops::Deref};
use std::{env, ops::Deref, path::PathBuf};

#[derive(Parser, Debug)]
#[clap(name = utils::package_description!(), version = utils::version_info_str!())]
Expand All @@ -20,6 +20,10 @@ struct CliArgs {
#[clap(flatten)]
args: resources::CliArgs,

/// Path to kubeconfig file.
#[clap(global = true, long, short = 'k')]
kube_config_path: Option<PathBuf>,

/// Use namespace from the current `kubeconfig` context.
#[clap(global = true, long, hide = true, default_value = "false")]
namespace_from_context: bool,
Expand All @@ -28,10 +32,11 @@ struct CliArgs {
impl CliArgs {
async fn args() -> Result<Self, anyhow::Error> {
let mut args = CliArgs::parse();
args.args.kubeconfig = args.kube_config_path.clone();
args.args.namespace = if let Some(namespace) = &args.namespace {
namespace.to_string()
} else if args.namespace_from_context {
let client = kube_proxy::client_from_kubeconfig(args.args.kube_config_path.clone())
let client = kube_proxy::client_from_kubeconfig(args.kube_config_path.clone())
.await
.map_err(|err| anyhow::anyhow!("{err}"))?;
client.default_namespace().to_string()
Expand Down
8 changes: 4 additions & 4 deletions k8s/plugin/src/resources/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ pub struct CliArgs {
pub rest: Option<Url>,

/// Path to kubeconfig file.
#[clap(global = true, long, short = 'k')]
pub kube_config_path: Option<PathBuf>,
#[clap(skip)]
pub kubeconfig: Option<PathBuf>,

/// Kubernetes namespace of mayastor service
#[clap(skip)]
Expand Down Expand Up @@ -115,7 +115,7 @@ impl ExecuteOperation for Operations {
// todo: use generic execute trait
preflight_validations::preflight_check(
&cli_args.namespace,
cli_args.kube_config_path.clone(),
cli_args.kubeconfig.clone(),
cli_args.timeout,
resources,
)
Expand Down Expand Up @@ -180,7 +180,7 @@ pub async fn init_rest(cli_args: &CliArgs) -> Result<(), Error> {
Some(url) => RestClient::init(url, false, *cli_args.timeout).map_err(Error::RestClient),
None => {
let config = kube_proxy::ConfigBuilder::default_api_rest()
.with_kube_config(cli_args.kube_config_path.clone())
.with_kube_config(cli_args.kubeconfig.clone())
.with_timeout(*cli_args.timeout)
.with_target_mod(|t| t.with_namespace(&cli_args.namespace))
.build()
Expand Down

0 comments on commit 992d763

Please sign in to comment.