diff --git a/k8s/plugin/src/main.rs b/k8s/plugin/src/main.rs index 0baa00e74..96fe964bb 100644 --- a/k8s/plugin/src/main.rs +++ b/k8s/plugin/src/main.rs @@ -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!())] @@ -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, + /// Use namespace from the current `kubeconfig` context. #[clap(global = true, long, hide = true, default_value = "false")] namespace_from_context: bool, @@ -28,10 +32,11 @@ struct CliArgs { impl CliArgs { async fn args() -> Result { 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() diff --git a/k8s/plugin/src/resources/mod.rs b/k8s/plugin/src/resources/mod.rs index da075cd27..0967c9331 100644 --- a/k8s/plugin/src/resources/mod.rs +++ b/k8s/plugin/src/resources/mod.rs @@ -24,8 +24,8 @@ pub struct CliArgs { pub rest: Option, /// Path to kubeconfig file. - #[clap(global = true, long, short = 'k')] - pub kube_config_path: Option, + #[clap(skip)] + pub kubeconfig: Option, /// Kubernetes namespace of mayastor service #[clap(skip)] @@ -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, ) @@ -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()