Skip to content

Commit

Permalink
handle output of default namespace change
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramilito committed Oct 19, 2024
1 parent 8661765 commit fa607de
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
3 changes: 2 additions & 1 deletion scripts/fish/functions/knd.fish
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ function knd --argument-names context --description "Switch global kubernetes na
if test -n "$argv"
set -a cmd -v $context
end
command $cmd
set -l config (command $cmd) || return $status
set -gx KUBECONFIG $config
end
2 changes: 1 addition & 1 deletion scripts/sh/kubesess.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ kn() {
}

knd() {
kubesess ${1:+"-v "$1} default-namespace;
__kubesess_export ${1:+"-v "$1} default-namespace
}
16 changes: 13 additions & 3 deletions src/modes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,11 @@ pub fn namespace(args: Cli) -> Result<(), Error> {
}

pub fn default_namespace(args: Cli) -> Result<(), Error> {
let config = config::get();
let ctx = commands::get_current_context();
let config = config::get_current_session();
let ctx = &config
.current_context
.as_deref()
.unwrap_or("No current context set");

if args.current {
if let Some(ctx) = config.contexts.iter().find(|x| {
Expand Down Expand Up @@ -168,7 +171,14 @@ pub fn default_namespace(args: Cli) -> Result<(), Error> {
};

commands::set_default_namespace(&ns, &ctx);
commands::set_namespace(&ctx, &ns, &DEST, &config);
let result = commands::set_namespace(&ctx, &ns, &DEST, &config);
println!(
"{}/{}:{}",
&DEST.as_str(),
str::replace(&result, ":", "_"),
*KUBECONFIG
);

Ok(())
}

Expand Down

0 comments on commit fa607de

Please sign in to comment.