Skip to content

Commit

Permalink
Return error on no matching context
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Olivier authored and sbstp committed Mar 7, 2021
1 parent 16ed6ce commit ef02b82
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/cmd/exec.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::process::Command;
use std::thread;

use anyhow::Result;
use anyhow::{anyhow, Result};
use signal_hook::iterator::Signals;

use crate::kubeconfig::{self, KubeConfig};
Expand Down Expand Up @@ -64,8 +64,13 @@ pub fn exec(
}

let installed = kubeconfig::get_installed_contexts(settings)?;
let matching = installed.get_contexts_matching(&context_name);

for context_src in installed.get_contexts_matching(&context_name) {
if matching.len() == 0 {
return Err(anyhow!("No context matching {}", context_name));
}

for context_src in matching {
let kubeconfig = installed.make_kubeconfig_for_context(&context_src.item.name, Some(&namespace_name))?;
let return_code = run_in_context(&kubeconfig, &args)?;

Expand Down

0 comments on commit ef02b82

Please sign in to comment.