From 2cbd0de3d4c5d09f6840ba9864a13f7edee617c3 Mon Sep 17 00:00:00 2001 From: fj0r <82698591+fj0r@users.noreply.github.com> Date: Wed, 20 Sep 2023 19:30:48 +0800 Subject: [PATCH] kubernetes/kn: create namespace when it doesn't exist (#610) * kubernetes/kn: create namespace when it doesn't exist * upgrade to 0.85: decimal -> float --------- Co-authored-by: agent --- modules/kubernetes/kubernetes.nu | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/modules/kubernetes/kubernetes.nu b/modules/kubernetes/kubernetes.nu index 2d699e95..d07fa79d 100644 --- a/modules/kubernetes/kubernetes.nu +++ b/modules/kubernetes/kubernetes.nu @@ -320,6 +320,13 @@ export def kcc [ctx: string@"nu-complete kube ctx"] { # kubectl (change) namespace export def kn [ns: string@"nu-complete kube ns"] { + if not ($ns in (kubectl get namespace | from ssv -a | get NAME)) { + if ([no yes] | input list $"namespace '($ns)' doesn't exist, create it?") in [yes] { + kubectl create namespace $ns + } else { + return + } + } kubectl config set-context --current $"--namespace=($ns)" } @@ -883,8 +890,8 @@ export def ktp [ { namespace: $x.namespace name: $x.name - cpu: ($x.cpu| str substring ..-1 | into decimal) - mem: ($x.mem | str substring ..-2 | into decimal) + cpu: ($x.cpu| str substring ..-1 | into float) + mem: ($x.mem | str substring ..-2 | into float) } } } else { @@ -893,8 +900,8 @@ export def ktp [ | each {|x| { name: $x.name - cpu: ($x.cpu| str substring ..-1 | into decimal) - mem: ($x.mem | str substring ..-2 | into decimal) + cpu: ($x.cpu| str substring ..-1 | into float) + mem: ($x.mem | str substring ..-2 | into float) } } } @@ -905,10 +912,10 @@ export def ktno [] { kubectl top node | from ssv -a | rename name cpu pcpu mem pmem | each {|x| { name: $x.name - cpu: ($x.cpu| str substring ..-1 | into decimal) - cpu%: (($x.pcpu| str substring ..-1 | into decimal) / 100) - mem: ($x.mem | str substring ..-2 | into decimal) - mem%: (($x.pmem | str substring ..-1 | into decimal) / 100) + cpu: ($x.cpu| str substring ..-1 | into float) + cpu%: (($x.pcpu| str substring ..-1 | into float) / 100) + mem: ($x.mem | str substring ..-2 | into float) + mem%: (($x.pmem | str substring ..-1 | into float) / 100) } } }