Skip to content

Commit d6fd179

Browse files
authored
feat(channels): Kubernetes channels for deployments, pods and services (#688)
## 📺 PR Description Re-opened PR from #677 Added Channels for Kubernetes deployments, pods and services ## Checklist <!-- a quick pass through the following items to make sure you haven't forgotten anything --> - [x] my commits **and PR title** follow the [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/#summary) format - [ ] if this is a new feature, I have added tests to consolidate the feature and prevent regressions - [ ] if this is a bug fix, I have added a test that reproduces the bug (if applicable) - [ ] I have added a reasonable amount of documentation to the code where appropriate
1 parent 834a3cc commit d6fd179

File tree

8 files changed

+285
-13
lines changed

8 files changed

+285
-13
lines changed

assets/channels/k8s-deployments.png

498 KB
Loading

assets/channels/k8s-pods.png

557 KB
Loading

assets/channels/k8s-services.png

303 KB
Loading

cable/unix/git-reflog.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ requirements = ["git"]
55

66
[source]
77
command = "git reflog --decorate --color=always"
8-
output = "{strip_ansi|split: :0}"
8+
output = "{0|strip_ansi}"
99
ansi = true
1010

1111
[preview]
12-
command = "git show -p --stat --pretty=fuller --color=always '{strip_ansi|0}'"
12+
command = "git show -p --stat --pretty=fuller --color=always '{0|strip_ansi}'"

cable/unix/k8s-deployments.toml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
[metadata]
2+
name = "k8s-deployments"
3+
description = '''List and preview Deployments in a Kubernetes Cluster.
4+
5+
The first source lists only from the current namespace, while the second lists from all.
6+
7+
Keybindings
8+
9+
Press `ctrl-d` to delete the selected Deployment.
10+
'''
11+
requirements = ["kubectl"]
12+
13+
[source]
14+
command = [
15+
'''
16+
kubectl get deployments -o go-template --template '{{range .items}}{{.metadata.namespace}} {{.metadata.name}}{{"\n"}}{{end}}'
17+
''',
18+
'''
19+
kubectl get deployments -o go-template --template '{{range .items}}{{.metadata.namespace}} {{.metadata.name}}{{"\n"}}{{end}}' --all-namespaces
20+
''',
21+
]
22+
output = "{1}"
23+
24+
[preview]
25+
command = "kubectl describe -n {0} deployments/{1}"
26+
27+
[ui.preview_panel]
28+
size = 60
29+
30+
[keybindings]
31+
ctrl-d = "actions:delete"
32+
33+
[actions.delete]
34+
description = "Delete the selected Deployment"
35+
command = "kubectl delete -n {0} deployments/{1}"
36+
mode = "execute"

cable/unix/k8s-pods.toml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
[metadata]
2+
name = "k8s-pods"
3+
description = '''List and preview Pods in a Kubernetes Cluster.
4+
5+
The first source lists only from the current namespace, while the second lists from all.
6+
7+
Keybindings
8+
9+
Press `ctrl-e` to execute shell inside the selected Pod.
10+
Press `ctrl-d` to delete the selected Pod.
11+
Press `ctrl-l` to print and follow the logs of the selected Pod.
12+
'''
13+
requirements = ["kubectl"]
14+
15+
[source]
16+
command = [
17+
'''
18+
kubectl get pods -o go-template --template '{{range .items}}{{.metadata.namespace}} {{.metadata.name}}{{"\n"}}{{end}}'
19+
''',
20+
'''
21+
kubectl get pods -o go-template --template '{{range .items}}{{.metadata.namespace}} {{.metadata.name}}{{"\n"}}{{end}}' --all-namespaces
22+
''',
23+
]
24+
output = "{1}"
25+
26+
[preview]
27+
command = "kubectl describe -n {0} pods/{1}"
28+
29+
[ui.preview_panel]
30+
size = 60
31+
32+
[keybindings]
33+
ctrl-d = "actions:delete"
34+
ctrl-e = "actions:exec"
35+
ctrl-l = "actions:logs"
36+
37+
[actions.exec]
38+
description = "Execute shell inside the selected Pod"
39+
command = "kubectl exec -i -t -n {0} pods/{1} -- /bin/sh"
40+
mode = "execute"
41+
42+
[actions.delete]
43+
description = "Delete the selected Pod"
44+
command = "kubectl delete -n {0} pods/{1}"
45+
mode = "execute"
46+
47+
[actions.logs]
48+
description = "Follow logs of the selected Pod"
49+
command = "kubectl logs -f -n {0} pods/{1}"
50+
mode = "execute"

cable/unix/k8s-services.toml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
[metadata]
2+
name = "k8s-services"
3+
description = '''List and preview Services in a Kubernetes Cluster.
4+
5+
The first source lists only from the current namespace, while the second lists from all.
6+
7+
keybindings
8+
9+
Press `ctrl-d` to delete the selected Service.
10+
'''
11+
requirements = ["kubectl"]
12+
13+
[source]
14+
command = [
15+
'''
16+
kubectl get services -o go-template --template '{{range .items}}{{.metadata.namespace}} {{.metadata.name}}{{"\n"}}{{end}}'
17+
''',
18+
'''
19+
kubectl get services -o go-template --template '{{range .items}}{{.metadata.namespace}} {{.metadata.name}}{{"\n"}}{{end}}' --all-namespaces
20+
''',
21+
]
22+
output = "{1}"
23+
24+
[preview]
25+
command = "kubectl describe -n {0} services/{1}"
26+
27+
[ui.preview_panel]
28+
size = 60
29+
30+
[keybindings]
31+
ctrl-d = "actions:delete"
32+
33+
[actions.delete]
34+
description = "Delete the selected Service"
35+
command = "kubectl delete -n {0} services/{1}"
36+
mode = "execute"

docs/01-Users/10-community-channels-unix.md

Lines changed: 161 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -337,11 +337,12 @@ description = "A channel to select from git log entries"
337337
requirements = [ "git",]
338338

339339
[source]
340-
command = "git log --oneline --date=short --pretty=\"format:%h %s %an %cd\" \"$@\""
341-
output = "{split: :0}"
340+
command = "git log --graph --pretty=format:'%C(yellow)%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --color=always"
341+
output = "{strip_ansi|split: :1}"
342+
ansi = true
342343

343344
[preview]
344-
command = "git show -p --stat --pretty=fuller --color=always '{0}'"
345+
command = "git show -p --stat --pretty=fuller --color=always '{strip_ansi|split: :1}' | head -n 1000"
345346

346347
```
347348

@@ -364,11 +365,11 @@ requirements = [ "git",]
364365

365366
[source]
366367
command = "git reflog --decorate --color=always"
367-
output = "{strip_ansi|split: :0}"
368+
output = "{0|strip_ansi}"
368369
ansi = true
369370

370371
[preview]
371-
command = "git show -p --stat --pretty=fuller --color=always '{strip_ansi|0}'"
372+
command = "git show -p --stat --pretty=fuller --color=always '{0|strip_ansi}'"
372373

373374
```
374375

@@ -402,6 +403,155 @@ command = "cd '{}'; git log -n 200 --pretty=medium --all --graph --color"
402403
```
403404

404405

406+
---
407+
408+
### *k8s-deployments*
409+
410+
List and preview Deployments in a Kubernetes Cluster.
411+
412+
The first source lists only from the current namespace, while the second lists from all.
413+
414+
Keybindings
415+
416+
Press `ctrl-d` to delete the selected Deployment.
417+
418+
419+
![tv running the k8s-deployments channel](../../assets/channels/k8s-deployments.png)
420+
**Requirements:** `kubectl`
421+
422+
**Code:** *k8s-deployments.toml*
423+
424+
```toml
425+
[metadata]
426+
name = "k8s-deployments"
427+
description = "List and preview Deployments in a Kubernetes Cluster.\n\nThe first source lists only from the current namespace, while the second lists from all.\n\nKeybindings\n\nPress `ctrl-d` to delete the selected Deployment.\n"
428+
requirements = [ "kubectl",]
429+
430+
[source]
431+
command = [ " kubectl get deployments -o go-template --template '{{range .items}}{{.metadata.namespace}} {{.metadata.name}}{{\"\\n\"}}{{end}}'\n ", " kubectl get deployments -o go-template --template '{{range .items}}{{.metadata.namespace}} {{.metadata.name}}{{\"\\n\"}}{{end}}' --all-namespaces\n ",]
432+
output = "{1}"
433+
434+
[preview]
435+
command = "kubectl describe -n {0} deployments/{1}"
436+
437+
[keybindings]
438+
ctrl-d = "actions:delete"
439+
440+
[ui.preview_panel]
441+
size = 60
442+
443+
[actions.delete]
444+
description = "Delete the selected Deployment"
445+
command = "kubectl delete -n {0} deployments/{1}"
446+
mode = "execute"
447+
448+
```
449+
450+
451+
---
452+
453+
### *k8s-pods*
454+
455+
List and preview Pods in a Kubernetes Cluster.
456+
457+
The first source lists only from the current namespace, while the second lists from all.
458+
459+
Keybindings
460+
461+
Press `ctrl-e` to execute shell inside the selected Pod.
462+
Press `ctrl-d` to delete the selected Pod.
463+
Press `ctrl-l` to print and follow the logs of the selected Pod.
464+
465+
466+
![tv running the k8s-pods channel](../../assets/channels/k8s-pods.png)
467+
**Requirements:** `kubectl`
468+
469+
**Code:** *k8s-pods.toml*
470+
471+
```toml
472+
[metadata]
473+
name = "k8s-pods"
474+
description = "List and preview Pods in a Kubernetes Cluster.\n\nThe first source lists only from the current namespace, while the second lists from all.\n\nKeybindings\n\nPress `ctrl-e` to execute shell inside the selected Pod.\nPress `ctrl-d` to delete the selected Pod.\nPress `ctrl-l` to print and follow the logs of the selected Pod.\n"
475+
requirements = [ "kubectl",]
476+
477+
[source]
478+
command = [ " kubectl get pods -o go-template --template '{{range .items}}{{.metadata.namespace}} {{.metadata.name}}{{\"\\n\"}}{{end}}'\n ", " kubectl get pods -o go-template --template '{{range .items}}{{.metadata.namespace}} {{.metadata.name}}{{\"\\n\"}}{{end}}' --all-namespaces\n ",]
479+
output = "{1}"
480+
481+
[preview]
482+
command = "kubectl describe -n {0} pods/{1}"
483+
484+
[keybindings]
485+
ctrl-d = "actions:delete"
486+
ctrl-e = "actions:exec"
487+
ctrl-l = "actions:logs"
488+
489+
[ui.preview_panel]
490+
size = 60
491+
492+
[actions.exec]
493+
description = "Execute shell inside the selected Pod"
494+
command = "kubectl exec -i -t -n {0} pods/{1} -- /bin/sh"
495+
mode = "execute"
496+
497+
[actions.delete]
498+
description = "Delete the selected Pod"
499+
command = "kubectl delete -n {0} pods/{1}"
500+
mode = "execute"
501+
502+
[actions.logs]
503+
description = "Follow logs of the selected Pod"
504+
command = "kubectl logs -f -n {0} pods/{1}"
505+
mode = "execute"
506+
507+
```
508+
509+
510+
---
511+
512+
### *k8s-services*
513+
514+
List and preview Services in a Kubernetes Cluster.
515+
516+
The first source lists only from the current namespace, while the second lists from all.
517+
518+
keybindings
519+
520+
Press `ctrl-d` to delete the selected Service.
521+
522+
523+
![tv running the k8s-services channel](../../assets/channels/k8s-services.png)
524+
**Requirements:** `kubectl`
525+
526+
**Code:** *k8s-services.toml*
527+
528+
```toml
529+
[metadata]
530+
name = "k8s-services"
531+
description = "List and preview Services in a Kubernetes Cluster.\n\nThe first source lists only from the current namespace, while the second lists from all.\n\nkeybindings\n\nPress `ctrl-d` to delete the selected Service.\n"
532+
requirements = [ "kubectl",]
533+
534+
[source]
535+
command = [ " kubectl get services -o go-template --template '{{range .items}}{{.metadata.namespace}} {{.metadata.name}}{{\"\\n\"}}{{end}}'\n ", " kubectl get services -o go-template --template '{{range .items}}{{.metadata.namespace}} {{.metadata.name}}{{\"\\n\"}}{{end}}' --all-namespaces\n ",]
536+
output = "{1}"
537+
538+
[preview]
539+
command = "kubectl describe -n {0} services/{1}"
540+
541+
[keybindings]
542+
ctrl-d = "actions:delete"
543+
544+
[ui.preview_panel]
545+
size = 60
546+
547+
[actions.delete]
548+
description = "Delete the selected Service"
549+
command = "kubectl delete -n {0} services/{1}"
550+
mode = "execute"
551+
552+
```
553+
554+
405555
---
406556

407557
### *nu-history*
@@ -440,19 +590,19 @@ description = "A channel to find and select text from files"
440590
requirements = [ "rg", "bat",]
441591

442592
[source]
443-
command = "rg . --no-heading --line-number"
444-
display = "[{split:\\::..2}]\t{split:\\::2..}"
445-
output = "{split:\\::..2}"
593+
command = "rg . --no-heading --line-number --colors 'match:fg:white' --colors 'path:fg:blue' --color=always"
594+
ansi = true
595+
output = "{strip_ansi|split:\\::..2}"
446596

447597
[preview]
448-
command = "bat -n --color=always '{split:\\::0}'"
449-
offset = "{split:\\::1}"
598+
command = "bat -n --color=always '{strip_ansi|split:\\::0}'"
599+
offset = "{strip_ansi|split:\\::1}"
450600

451601
[preview.env]
452602
BAT_THEME = "ansi"
453603

454604
[ui.preview_panel]
455-
header = "{split:\\::..2}"
605+
header = "{strip_ansi|split:\\::..2}"
456606

457607
```
458608

0 commit comments

Comments
 (0)