Skip to content

Commit aec6be2

Browse files
author
datacore-bolt-ci
committed
ci(stability): merge the develop branch
2 parents 514da0a + 314baed commit aec6be2

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

k8s/plugin/src/main.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ struct CliArgs {
1818
#[clap(global = true, long, short = 'n')]
1919
namespace: Option<String>,
2020

21+
/// Kubernetes context to use.
22+
#[clap(global = true, long)]
23+
context: Option<String>,
24+
2125
#[clap(flatten)]
2226
args: resources::CliArgs,
2327

@@ -38,10 +42,15 @@ impl CliArgs {
3842
if let Operations::Dump(ref mut dump_args) = args.operations {
3943
dump_args.args.set_kube_config_path(path);
4044
}
45+
args.args.context = args.context.clone();
4146
args.args.namespace = if let Some(namespace) = &args.namespace {
4247
namespace.to_string()
4348
} else if args.namespace_from_context {
44-
let client = kube_proxy::client_from_kubeconfig(args.kube_config_path.clone()).await?;
49+
let client = kube_proxy::client_from_kubeconfig(
50+
args.kube_config_path.clone(),
51+
args.context.clone(),
52+
)
53+
.await?;
4554
client.default_namespace().to_string()
4655
} else {
4756
constants::DEFAULT_PLUGIN_NAMESPACE.to_string()

k8s/plugin/src/resources/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,19 @@ pub struct CliArgs {
3535
#[clap(skip)]
3636
pub namespace: String,
3737

38+
/// Kubernetes context in the kubeconfig file.
39+
#[clap(skip)]
40+
pub context: Option<String>,
41+
3842
#[clap(flatten)]
3943
pub cli_args: plugin::CliArgs,
4044
}
4145

4246
impl CliArgs {
4347
/// The kube client, with the correct install namespace.
4448
pub async fn client(&self) -> anyhow::Result<kube::Client> {
45-
let mut config = kube_proxy::config_from_kubeconfig(self.kubeconfig.clone()).await?;
49+
let opts = kube_proxy::kubeconfig_options_from_context(self.context.clone());
50+
let mut config = kube_proxy::config_from_kubeconfig(self.kubeconfig.clone(), opts).await?;
4651
// If taking namespace from context, we already know self.namespace has been set
4752
// from the context.
4853
config.default_namespace = self.namespace.clone();
@@ -294,6 +299,7 @@ pub async fn init_rest(cli_args: &CliArgs) -> Result<(), Error> {
294299
None => {
295300
let config = kube_proxy::ConfigBuilder::default_api_rest()
296301
.with_kube_config(cli_args.kubeconfig.clone())
302+
.with_context(cli_args.context.clone())
297303
.with_timeout(*cli_args.timeout)
298304
.with_target_mod(|t| t.with_namespace(&cli_args.namespace))
299305
.build()

0 commit comments

Comments
 (0)