mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-08-02 15:17:47 +00:00
kubernetes: fix -n
in completion context (#523)
Co-authored-by: agent <agent@nuc>
This commit is contained in:
parent
140f556049
commit
09f6d2a473
1 changed files with 59 additions and 42 deletions
|
@ -501,37 +501,37 @@ export def kg [
|
||||||
export def kd [
|
export def kd [
|
||||||
r: string@"nu-complete kube kind"
|
r: string@"nu-complete kube kind"
|
||||||
i: string@"nu-complete kube res"
|
i: string@"nu-complete kube res"
|
||||||
-n: string@"nu-complete kube ns"
|
--namespace (-n): string@"nu-complete kube ns"
|
||||||
] {
|
] {
|
||||||
kubectl describe (spr [-n $n]) $r $i
|
kubectl describe (spr [-n $namespace]) $r $i
|
||||||
}
|
}
|
||||||
|
|
||||||
# kubectl create
|
# kubectl create
|
||||||
export def kc [
|
export def kc [
|
||||||
r: string@"nu-complete kube kind"
|
r: string@"nu-complete kube kind"
|
||||||
-n: string@"nu-complete kube ns"
|
--namespace (-n): string@"nu-complete kube ns"
|
||||||
name:string
|
name:string
|
||||||
] {
|
] {
|
||||||
kubectl create (spr [-n $n]) $r $name
|
kubectl create (spr [-n $namespace]) $r $name
|
||||||
}
|
}
|
||||||
|
|
||||||
# kubectl get -o yaml
|
# kubectl get -o yaml
|
||||||
export def ky [
|
export def ky [
|
||||||
r: string@"nu-complete kube kind"
|
r: string@"nu-complete kube kind"
|
||||||
i: string@"nu-complete kube res"
|
i: string@"nu-complete kube res"
|
||||||
-n: string@"nu-complete kube ns"
|
--namespace (-n): string@"nu-complete kube ns"
|
||||||
] {
|
] {
|
||||||
kubectl get (spr [-n $n]) -o yaml $r $i
|
kubectl get (spr [-n $namespace]) -o yaml $r $i
|
||||||
}
|
}
|
||||||
|
|
||||||
# kubectl edit
|
# kubectl edit
|
||||||
export def ke [
|
export def ke [
|
||||||
k: string@"nu-complete kube kind"
|
k: string@"nu-complete kube kind"
|
||||||
r?: string@"nu-complete kube res"
|
r?: string@"nu-complete kube res"
|
||||||
-n: string@"nu-complete kube ns"
|
--namespace (-n): string@"nu-complete kube ns"
|
||||||
--selector(-l): string
|
--selector(-l): string
|
||||||
] {
|
] {
|
||||||
let n = (spr [-n $n])
|
let n = (spr [-n $namespace])
|
||||||
let r = if ($selector | is-empty) { $r } else {
|
let r = if ($selector | is-empty) { $r } else {
|
||||||
let res = (kubectl get $k $n -l $selector | from ssv -a | each {|x| $x.NAME})
|
let res = (kubectl get $k $n -l $selector | from ssv -a | each {|x| $x.NAME})
|
||||||
if ($res | length) == 1 {
|
if ($res | length) == 1 {
|
||||||
|
@ -549,10 +549,10 @@ export def ke [
|
||||||
export def kdel [
|
export def kdel [
|
||||||
r: string@"nu-complete kube kind"
|
r: string@"nu-complete kube kind"
|
||||||
i: string@"nu-complete kube res"
|
i: string@"nu-complete kube res"
|
||||||
-n: string@"nu-complete kube ns"
|
--namespace (-n): string@"nu-complete kube ns"
|
||||||
--force(-f): bool
|
--force(-f): bool
|
||||||
] {
|
] {
|
||||||
kubectl delete (spr [-n $n]) (sprb $force [--grace-period=0 --force]) $r $i
|
kubectl delete (spr [-n $namespace]) (sprb $force [--grace-period=0 --force]) $r $i
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -564,16 +564,16 @@ export def kgno [] {
|
||||||
|
|
||||||
def "nu-complete kube pods" [context: string, offset: int] {
|
def "nu-complete kube pods" [context: string, offset: int] {
|
||||||
let ctx = ($context | parse cmd)
|
let ctx = ($context | parse cmd)
|
||||||
let ns = (do -i { $ctx | get '-n' })
|
let ns = (do -i { $ctx | get namespace })
|
||||||
let ns = (spr [-n $ns])
|
let ns = (spr [-n $ns])
|
||||||
kubectl get $ns pods | from ssv -a | get NAME
|
kubectl get $ns pods | from ssv -a | get NAME
|
||||||
}
|
}
|
||||||
|
|
||||||
def "nu-complete kube ctns" [context: string, offset: int] {
|
def "nu-complete kube ctns" [context: string, offset: int] {
|
||||||
let ctx = ($context | parse cmd)
|
let ctx = ($context | parse cmd)
|
||||||
let ns = (do -i { $ctx | get '-n' })
|
let ns = (do -i { $ctx | get namespace })
|
||||||
let ns = (spr [-n $ns])
|
let ns = (spr [-n $ns])
|
||||||
let ctn = (do -i { $ctx | get '-c' })
|
let ctn = (do -i { $ctx | get container })
|
||||||
let ctn = (spr [-c $ctn])
|
let ctn = (spr [-c $ctn])
|
||||||
let pod = ($ctx | get args.1)
|
let pod = ($ctx | get args.1)
|
||||||
kubectl get $ns pod $pod -o jsonpath={.spec.containers[*].name} | split row ' '
|
kubectl get $ns pod $pod -o jsonpath={.spec.containers[*].name} | split row ' '
|
||||||
|
@ -605,27 +605,30 @@ export def kgpw [
|
||||||
|
|
||||||
# kubectl edit pod
|
# kubectl edit pod
|
||||||
export def kep [
|
export def kep [
|
||||||
-n: string@"nu-complete kube ns"
|
--namespace (-n): string@"nu-complete kube ns"
|
||||||
pod?: string@"nu-complete kube res via name"
|
pod?: string@"nu-complete kube res via name"
|
||||||
--selector (-l): string
|
--selector (-l): string
|
||||||
] {
|
] {
|
||||||
ke -n $n pod -l $selector $pod
|
ke -n $namespace pod -l $selector $pod
|
||||||
}
|
}
|
||||||
|
|
||||||
# kubectl describe pod
|
# kubectl describe pod
|
||||||
export def kdp [-n: string@"nu-complete kube ns", pod: string@"nu-complete kube res via name"] {
|
export def kdp [
|
||||||
kd -n $n pod $pod
|
--namespace (-n): string@"nu-complete kube ns"
|
||||||
|
pod: string@"nu-complete kube res via name"
|
||||||
|
] {
|
||||||
|
kd -n $namespace pod $pod
|
||||||
}
|
}
|
||||||
|
|
||||||
# kubectl attach (exec -it)
|
# kubectl attach (exec -it)
|
||||||
export def ka [
|
export def ka [
|
||||||
pod?: string@"nu-complete kube pods"
|
pod?: string@"nu-complete kube pods"
|
||||||
-n: string@"nu-complete kube ns"
|
--namespace (-n): string@"nu-complete kube ns"
|
||||||
--container(-c): string@"nu-complete kube ctns"
|
--container(-c): string@"nu-complete kube ctns"
|
||||||
--selector(-l): string
|
--selector(-l): string
|
||||||
...args
|
...args
|
||||||
] {
|
] {
|
||||||
let n = (spr [-n $n])
|
let n = (spr [-n $namespace])
|
||||||
let pod = if ($selector | is-empty) { $pod } else {
|
let pod = if ($selector | is-empty) { $pod } else {
|
||||||
let pods = (
|
let pods = (
|
||||||
kubectl get pods $n -o wide -l $selector
|
kubectl get pods $n -o wide -l $selector
|
||||||
|
@ -697,9 +700,9 @@ export def kpf [
|
||||||
target: string@"nu-complete kube res"
|
target: string@"nu-complete kube res"
|
||||||
port: string@"nu-complete kube port"
|
port: string@"nu-complete kube port"
|
||||||
--local (-l): string
|
--local (-l): string
|
||||||
-n: string@"nu-complete kube ns"
|
--namespace (-n): string@"nu-complete kube ns"
|
||||||
] {
|
] {
|
||||||
let n = (spr [-n $n])
|
let n = (spr [-n $namespace])
|
||||||
let port = if ($local | is-empty) { $port } else { $"($local):($port)" }
|
let port = if ($local | is-empty) { $port } else { $"($local):($port)" }
|
||||||
kubectl port-forward $n $"($res)/($target)" $port
|
kubectl port-forward $n $"($res)/($target)" $port
|
||||||
}
|
}
|
||||||
|
@ -707,9 +710,9 @@ export def kpf [
|
||||||
def "nu-complete kube cp" [cmd: string, offset: int] {
|
def "nu-complete kube cp" [cmd: string, offset: int] {
|
||||||
let ctx = ($cmd | str substring ..$offset | parse cmd)
|
let ctx = ($cmd | str substring ..$offset | parse cmd)
|
||||||
let p = ($ctx.args | get (($ctx.args | length) - 1))
|
let p = ($ctx.args | get (($ctx.args | length) - 1))
|
||||||
let ns = (do -i { $ctx | get '-n' })
|
let ns = (do -i { $ctx | get namespace })
|
||||||
let ns = (spr [-n $ns])
|
let ns = (spr [-n $ns])
|
||||||
let c = (do -i { $ctx | get '-c' })
|
let c = (do -i { $ctx | get container })
|
||||||
let c = (spr [-c $c])
|
let c = (spr [-c $c])
|
||||||
let ctn = (kubectl get pod $ns | from ssv -a | each {|x| {description: $x.READY value: $"($x.NAME):" }})
|
let ctn = (kubectl get pod $ns | from ssv -a | each {|x| {description: $x.READY value: $"($x.NAME):" }})
|
||||||
let n = ($p | split row ':')
|
let n = ($p | split row ':')
|
||||||
|
@ -728,10 +731,10 @@ def "nu-complete kube cp" [cmd: string, offset: int] {
|
||||||
export def kcp [
|
export def kcp [
|
||||||
lhs: string@"nu-complete kube cp"
|
lhs: string@"nu-complete kube cp"
|
||||||
rhs: string@"nu-complete kube cp"
|
rhs: string@"nu-complete kube cp"
|
||||||
-c: string@"nu-complete kube ctns"
|
--container (-c): string@"nu-complete kube ctns"
|
||||||
-n: string@"nu-complete kube ns"
|
--namespace (-n): string@"nu-complete kube ns"
|
||||||
] {
|
] {
|
||||||
kubectl cp (spr [-n $n]) $lhs (spr [-c $c]) $rhs
|
kubectl cp (spr [-n $namespace]) $lhs (spr [-c $container]) $rhs
|
||||||
}
|
}
|
||||||
|
|
||||||
# kubectl get services
|
# kubectl get services
|
||||||
|
@ -747,15 +750,18 @@ export def kgs [
|
||||||
# kubectl edit service
|
# kubectl edit service
|
||||||
export def kes [
|
export def kes [
|
||||||
svc?: string@"nu-complete kube res via name"
|
svc?: string@"nu-complete kube res via name"
|
||||||
-n: string@"nu-complete kube ns"
|
--namespace (-n): string@"nu-complete kube ns"
|
||||||
--selector (-l): string
|
--selector (-l): string
|
||||||
] {
|
] {
|
||||||
ke -n $n service -l $selector $svc
|
ke -n $namespace service -l $selector $svc
|
||||||
}
|
}
|
||||||
|
|
||||||
# kubectl delete service
|
# kubectl delete service
|
||||||
export def kdels [svc: string@"nu-complete kube res via name", -n: string@"nu-complete kube ns"] {
|
export def kdels [
|
||||||
kdel -n $n service $svc
|
svc: string@"nu-complete kube res via name"
|
||||||
|
--namespace (-n): string@"nu-complete kube ns"
|
||||||
|
] {
|
||||||
|
kdel -n $namespace service $svc
|
||||||
}
|
}
|
||||||
|
|
||||||
# kubectl get deployments
|
# kubectl get deployments
|
||||||
|
@ -771,10 +777,10 @@ export def kgd [
|
||||||
# kubectl edit deployment
|
# kubectl edit deployment
|
||||||
export def ked [
|
export def ked [
|
||||||
d?: string@"nu-complete kube res via name"
|
d?: string@"nu-complete kube res via name"
|
||||||
-n: string@"nu-complete kube ns"
|
--namespace (-n): string@"nu-complete kube ns"
|
||||||
--selector (-l): string
|
--selector (-l): string
|
||||||
] {
|
] {
|
||||||
ke -n $n deployments -l $selector $d
|
ke -n $namespace deployments -l $selector $d
|
||||||
}
|
}
|
||||||
|
|
||||||
def "nu-complete num9" [] { [0 1 2 3] }
|
def "nu-complete num9" [] { [0 1 2 3] }
|
||||||
|
@ -782,12 +788,12 @@ def "nu-complete num9" [] { [0 1 2 3] }
|
||||||
export def ksd [
|
export def ksd [
|
||||||
d: string@"nu-complete kube res via name"
|
d: string@"nu-complete kube res via name"
|
||||||
num: string@"nu-complete num9"
|
num: string@"nu-complete num9"
|
||||||
-n: string@"nu-complete kube ns"
|
--namespace (-n): string@"nu-complete kube ns"
|
||||||
] {
|
] {
|
||||||
if ($num | into int) > 9 {
|
if ($num | into int) > 9 {
|
||||||
"too large"
|
"too large"
|
||||||
} else {
|
} else {
|
||||||
let n = (spr [-n $n])
|
let n = (spr [-n $namespace])
|
||||||
kubectl scale $n deployments $d --replicas $num
|
kubectl scale $n deployments $d --replicas $num
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -795,14 +801,14 @@ export def ksd [
|
||||||
export def ksdr [
|
export def ksdr [
|
||||||
d: string@"nu-complete kube res via name"
|
d: string@"nu-complete kube res via name"
|
||||||
num: int@"nu-complete num9"
|
num: int@"nu-complete num9"
|
||||||
-n: string@"nu-complete kube ns"
|
--namespace (-n): string@"nu-complete kube ns"
|
||||||
] {
|
] {
|
||||||
if $num > 9 {
|
if $num > 9 {
|
||||||
"too large"
|
"too large"
|
||||||
} else if $num <= 0 {
|
} else if $num <= 0 {
|
||||||
"too small"
|
"too small"
|
||||||
} else {
|
} else {
|
||||||
let n = (spr [-n $n])
|
let n = (spr [-n $namespace])
|
||||||
kubectl scale $n deployments $d --replicas 0
|
kubectl scale $n deployments $d --replicas 0
|
||||||
kubectl scale $n deployments $d --replicas $num
|
kubectl scale $n deployments $d --replicas $num
|
||||||
}
|
}
|
||||||
|
@ -814,15 +820,23 @@ export alias krsd = kubectl rollout status deployment
|
||||||
export alias kgrs = kubectl get rs
|
export alias kgrs = kubectl get rs
|
||||||
|
|
||||||
# kubectl rollout history
|
# kubectl rollout history
|
||||||
export def krhd [-n: string@"nu-complete kube ns", --revision (-v): int, dpl: string@"nu-complete kube res via name"] {
|
export def krhd [
|
||||||
let n = (spr [-n $n])
|
--namespace (-n): string@"nu-complete kube ns"
|
||||||
|
--revision (-v): int
|
||||||
|
dpl: string@"nu-complete kube res via name"
|
||||||
|
] {
|
||||||
|
let n = (spr [-n $namespace])
|
||||||
let v = if ($revision|is-empty) { [] } else { [ $"--revision=($revision)" ] }
|
let v = if ($revision|is-empty) { [] } else { [ $"--revision=($revision)" ] }
|
||||||
kubectl $n rollout history $"deployment/($dpl)" $v
|
kubectl $n rollout history $"deployment/($dpl)" $v
|
||||||
}
|
}
|
||||||
|
|
||||||
# kubectl rollout undo
|
# kubectl rollout undo
|
||||||
export def krud [-n: string@"nu-complete kube ns", --revision (-v): int, dpl: string@"nu-complete kube res via name"] {
|
export def krud [
|
||||||
let n = (spr [-n $n])
|
--namespace (-n): string@"nu-complete kube ns"
|
||||||
|
--revision (-v): int
|
||||||
|
dpl: string@"nu-complete kube res via name"
|
||||||
|
] {
|
||||||
|
let n = (spr [-n $namespace])
|
||||||
let v = if ($revision|is-empty) { [] } else { [ $"--to-revision=($revision)" ] }
|
let v = if ($revision|is-empty) { [] } else { [ $"--to-revision=($revision)" ] }
|
||||||
kubectl $n rollout undo $"deployment/($dpl)" $v
|
kubectl $n rollout undo $"deployment/($dpl)" $v
|
||||||
}
|
}
|
||||||
|
@ -830,7 +844,10 @@ export alias ksss = kubectl scale statefulset
|
||||||
export alias krsss = kubectl rollout status statefulset
|
export alias krsss = kubectl rollout status statefulset
|
||||||
|
|
||||||
# kubectl top pod
|
# kubectl top pod
|
||||||
export def ktp [-n: string@"nu-complete kube ns" --all(-a): bool] {
|
export def ktp [
|
||||||
|
--namespace (-n): string@"nu-complete kube ns"
|
||||||
|
--all(-a): bool
|
||||||
|
] {
|
||||||
if $all {
|
if $all {
|
||||||
kubectl top pod -A | from ssv -a | rename namespace name cpu mem
|
kubectl top pod -A | from ssv -a | rename namespace name cpu mem
|
||||||
| each {|x|
|
| each {|x|
|
||||||
|
@ -842,7 +859,7 @@ export def ktp [-n: string@"nu-complete kube ns" --all(-a): bool] {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let n = (spr [-n $n])
|
let n = (spr [-n $namespace])
|
||||||
kubectl top pod $n | from ssv -a | rename name cpu mem
|
kubectl top pod $n | from ssv -a | rename name cpu mem
|
||||||
| each {|x|
|
| each {|x|
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue