Remove "all" api resource
This commit is contained in:
parent
6fbe3d1e24
commit
2bd5a8664f
13
kls
13
kls
|
@ -15,7 +15,7 @@ KEY_BINDINGS = { # can be extended
|
||||||
BATCAT_STYLE = " --paging always --style numbers"
|
BATCAT_STYLE = " --paging always --style numbers"
|
||||||
# which api resources are on the top of menu?
|
# which api resources are on the top of menu?
|
||||||
TOP_API_RESOURCES = ["pods", "services", "configmaps", "secrets", "persistentvolumeclaims", "ingresses", "nodes",
|
TOP_API_RESOURCES = ["pods", "services", "configmaps", "secrets", "persistentvolumeclaims", "ingresses", "nodes",
|
||||||
"deployments", "statefulsets", "daemonsets", "storageclasses", "all"]
|
"deployments", "statefulsets", "daemonsets", "storageclasses"]
|
||||||
HELP_TEXT = ("letters: filter mode, Esc: exit filter mode or exit kls, 1/Enter: get yaml, 2: describe, 3: edit, "
|
HELP_TEXT = ("letters: filter mode, Esc: exit filter mode or exit kls, 1/Enter: get yaml, 2: describe, 3: edit, "
|
||||||
"4: logs, 5: exec, 6: debug, arrows/TAB/PgUp/PgDn: navigation")
|
"4: logs, 5: exec, 6: debug, arrows/TAB/PgUp/PgDn: navigation")
|
||||||
MOUSE_ENABLED = True
|
MOUSE_ENABLED = True
|
||||||
|
@ -79,11 +79,6 @@ def refresh_third_menu(namespace: str, api_resource: str):
|
||||||
menu = menus[2]
|
menu = menus[2]
|
||||||
previous_menu_rows = menu.rows
|
previous_menu_rows = menu.rows
|
||||||
if api_resource and namespace:
|
if api_resource and namespace:
|
||||||
if api_resource == "all":
|
|
||||||
cmd = ("api-resources --verbs=get --namespaced -o name | grep -v events | xargs -n 1 kubectl get"
|
|
||||||
f" --show-kind --namespace {namespace} --ignore-not-found --no-headers -o name")
|
|
||||||
menu.rows = kubectl(cmd)
|
|
||||||
else:
|
|
||||||
menu.rows = kubectl(f"-n {namespace} get {api_resource} --no-headers --ignore-not-found")
|
menu.rows = kubectl(f"-n {namespace} get {api_resource} --no-headers --ignore-not-found")
|
||||||
index_before_update = menu.filtered_rows.index
|
index_before_update = menu.filtered_rows.index
|
||||||
menu.filtered_rows = CircularList([x for x in menu.rows if menu.filter in x]) # update filtered rows
|
menu.filtered_rows = CircularList([x for x in menu.rows if menu.filter in x]) # update filtered rows
|
||||||
|
@ -99,14 +94,11 @@ def refresh_third_menu(namespace: str, api_resource: str):
|
||||||
def handle_key_bindings(key: str, namespace: str, api_resource: str, resource: str):
|
def handle_key_bindings(key: str, namespace: str, api_resource: str, resource: str):
|
||||||
if not resource:
|
if not resource:
|
||||||
return
|
return
|
||||||
if key in ("4", "5", "6"):
|
if key in ("4", "5", "6") and api_resource != "pods" and not resource.startswith("pod/"):
|
||||||
if api_resource not in ["pods", "all"] or (api_resource == "all" and not resource.startswith("pod/")):
|
|
||||||
return
|
return
|
||||||
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)
|
||||||
if api_resource == "all":
|
|
||||||
command = command.replace(" all", "")
|
|
||||||
if "batcat" in command:
|
if "batcat" in command:
|
||||||
command += BATCAT_STYLE
|
command += BATCAT_STYLE
|
||||||
subprocess.call(command, shell=True)
|
subprocess.call(command, shell=True)
|
||||||
|
@ -258,3 +250,4 @@ def main(screen):
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
curses.wrapper(main)
|
curses.wrapper(main)
|
||||||
subprocess.run("tput reset", shell=True)
|
subprocess.run("tput reset", shell=True)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue