-
Notifications
You must be signed in to change notification settings - Fork 237
/
Copy pathconf.nu
58 lines (54 loc) · 1.73 KB
/
conf.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
use complete.nu *
export def 'kconf import' [name: string, path: string] {
let k = (kube-config)
mut d = $k.data
let i = cat $path | from yaml
let c = {
context: {
cluster: $name,
namespace: default,
user: $name
}
name: $name,
}
$d.clusters = (upsert_row $d.clusters name [] $name ($i.clusters.0 | upsert name $name))
$d.users = (upsert_row $d.users name [] $name ($i.users.0 | upsert name $name))
$d.contexts = (upsert_row $d.contexts name [] $name $c)
$d | to yaml
}
export def 'kconf delete' [name: string@"nu-complete kube ctx"] {
let kc = (kube-config)
let d = $kc.data
let ctx = $d | get contexts | where name == $name | get 0
let rctx = $d | get contexts | where name != $name
let user = if ($ctx.context.user in ($rctx | get context.user)) {
$d | get users
} else {
$d | get users | where name != $ctx.context.user
}
let cluster = if ($ctx.context.cluster in ($rctx | get context.cluster)) {
$d | get clusters
} else {
$d | get clusters | where name != $ctx.context.cluster
}
$d
| update contexts $rctx
| update users $user
| update clusters $cluster
| to yaml
}
export def 'kconf export' [name: string@"nu-complete kube ctx"] {
let d = (kube-config).data
let ctx = $d | get contexts | where name == $name | get 0
let user = $d | get users | where name == $ctx.context.user
let cluster = $d | get clusters | where name == $ctx.context.cluster
{
apiVersion: 'v1',
current-context: $ctx.name,
kind: Config,
clusters: $cluster,
preferences: {},
contexts: [$ctx],
users: $user,
} | to yaml
}