Add exec/delete

This commit is contained in:
Digital Studium 2024-04-23 21:16:34 +03:00
parent 0bda789c98
commit fc899eec12
2 changed files with 8 additions and 4 deletions

View File

@ -7,10 +7,12 @@ It is lightweight and easy to customize
- `2` - describe resource - `2` - describe resource
- `3` - edit resource - `3` - edit resource
- `4` - logs of pod - `4` - logs of pod
- `5` - exec to pod
- `delete` - delete resource
You can customize these bindings or add extra bindings in `KEY_BINDINGS` variable of `kls` (in a row #4). You can customize these bindings or add extra bindings in `KEY_BINDINGS` variable of `kls` (in a row #4).
Also you can add additional columns for different api resources in `EXTRA_COLUMNS` variable (in a row #11). Also you can add additional columns for different api resources in `EXTRA_COLUMNS` variable (in a row #13).
![kls in action](./images/kls.gif) ![kls in action](./images/kls.gif)
## Dependencies ## Dependencies

8
kls
View File

@ -5,11 +5,13 @@ KEY_BINDINGS = { # can be extended
"1": 'kubectl -n {namespace} get {api_resource} {resource} -o yaml | batcat -l yaml --paging always --style numbers', "1": 'kubectl -n {namespace} get {api_resource} {resource} -o yaml | batcat -l yaml --paging always --style numbers',
"2": 'kubectl -n {namespace} describe {api_resource} {resource} | batcat -l yaml --paging always --style numbers', "2": 'kubectl -n {namespace} describe {api_resource} {resource} | batcat -l yaml --paging always --style numbers',
"3": 'kubectl -n {namespace} edit {api_resource} {resource}', "3": 'kubectl -n {namespace} edit {api_resource} {resource}',
"4": 'kubectl -n {namespace} logs {resource} | batcat -l log --paging always --style numbers' "4": 'kubectl -n {namespace} logs {resource} | batcat -l log --paging always --style numbers',
"5": 'kubectl -n {namespace} exec -it {resource} sh',
"KEY_DC": 'kubectl -n {namespace} delete {api_resource} {resource}' # delete key
} }
EXTRA_COLUMNS = { # By default, only the NAME column is displayed. Any api resource can be added here EXTRA_COLUMNS = { # By default, only the NAME column is displayed. Any api resource can be added here
"pods": ',STATUS:.status.phase,NODE:.spec.nodeName', "pods": ',STATUS:.status.phase,NODE:.spec.nodeName,AGE:.metadata.creationTimestamp',
"nodes": ',STATUS:.status.conditions[-1].type,CAPACITY_CPU:.status.capacity.cpu,CAPACITY_MEM:.status.capacity.memory', "nodes": ',STATUS:.status.conditions[-1].type,CAPACITY_CPU:.status.capacity.cpu,CAPACITY_MEM:.status.capacity.memory',
"services": ',TYPE:.spec.type,CLUSTER_IP:.spec.clusterIP', "services": ',TYPE:.spec.type,CLUSTER_IP:.spec.clusterIP',
"ingresses": ',HOSTS:.spec.rules[*].host', "ingresses": ',HOSTS:.spec.rules[*].host',
@ -85,7 +87,7 @@ def update_menu3():
def run_command(key): def run_command(key):
if not (key == "4" and api_resource() != "pods"): if not (key == "4" and api_resource() != "pods") and not (key == "5" and api_resource() != "pods"):
curses.def_prog_mode() # save the previous terminal state curses.def_prog_mode() # save the previous terminal state
curses.endwin() # without this, there are problems after exiting vim curses.endwin() # without this, there are problems after exiting vim
command = KEY_BINDINGS[key].format(namespace=namespace(), api_resource=api_resource(), resource=resource()) command = KEY_BINDINGS[key].format(namespace=namespace(), api_resource=api_resource(), resource=resource())