-
Notifications
You must be signed in to change notification settings - Fork 238
/
Copy pathresources.nu
61 lines (56 loc) · 1.84 KB
/
resources.nu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use complete *
### refine kubernetes resources
export def kube-refine [
...namespace: string@"nu-complete kube ns"
--kind(-k): list<string@"nu-complete kube kind">
] {
use lg
let config = $env.KUBERNETES_REFINE
let nsf = if ($namespace | is-empty) {
{|x| $x not-in $config._namespace }
} else {
{|x| $x in $namespace}
}
let cns = kubectl get namespace
| from ssv -a
| get NAME
| filter $nsf
let resource = kubectl get crd | from ssv | get NAME
let resource = kubectl api-resources | from ssv -a | get NAME | append $resource
let resource = if ($kind | is-empty) {
$resource
} else {
$resource
| filter {|x| $x in $kind }
}
mut data = []
if ($namespace | is-empty) {
lg level 4 {stage: cluster}
for p in ($config.cluster_resources | transpose k v) {
if $p.k not-in $resource { continue }
lg level 3 {kind: $p.k} list
let rs = kubectl get $p.k | from ssv -a | get NAME
for r in $rs {
lg level 1 {kind: $p.k, name: $r} collect
let obj = kubectl get $p.k $r --output=json | from json
let pyl = refine $p.v $obj
$data ++= $pyl
}
}
}
lg level 4 {stage: namespace}
for p in ($config.resources | transpose k v) {
if $p.k not-in $resource { continue }
for ns in $cns {
lg level 2 {kind: $p.k, ns: $ns} list
let rs = kubectl get $p.k --namespace $ns | from ssv -a | get NAME
for r in $rs {
lg level 0 {kind: $p.k, ns: $ns, name: $r} collect
let obj = kubectl get $p.k --namespace $ns $r --output=json | from json
let pyl = refine $p.v $obj
$data ++= $pyl
}
}
}
$data
}