Skip to content

Commit

Permalink
look up ns only once (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
gsstuart committed Jul 1, 2024
1 parent badb6ef commit 5e0431e
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/cmd/namespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,26 @@ pub fn namespace(
return enter_namespace(settings, &mut session, recursive, None);
}

let namespaces = if settings.behavior.validate_namespaces {
kubectl::get_namespaces(None)?
} else {
vec![]
};

let namespace_name = match namespace_name {
Some(s) if s == "-" => Some(
session
.get_last_namespace()
.context("There is not previous namespace to switch to")?
.to_string(),
),
Some(s) if settings.behavior.validate_namespaces && !namespaces.contains(&s) => {
return Err(anyhow!("'{}' is not a valid namespace for the context", s))
Some(s) => {
if settings.behavior.validate_namespaces {
let namespaces = kubectl::get_namespaces(None)?;
if !namespaces.contains(&s) {
return Err(anyhow!("'{}' is not a valid namespace for the context", s))
}
}
Some(s)
}
None => match select_or_list_namespace(skim_options)? {
SelectResult::Selected(s) => Some(s),
_ => return Ok(()),
},
Some(_) => namespace_name,
};

enter_namespace(settings, &mut session, recursive, namespace_name)
Expand Down

0 comments on commit 5e0431e

Please sign in to comment.