Change proportions and add pods' nodes

This commit is contained in:
Digital Studium 2024-04-18 21:14:35 +03:00
parent a702b924d7
commit 6f98dcb010
1 changed files with 4 additions and 4 deletions

8
kls
View File

@ -16,9 +16,9 @@ SCREEN = curses.initscr() # инициализация экрана
execute_cmd = lambda command: subprocess.check_output(command, shell=True).decode().rstrip().split("\n") # вывод команды преобразуем в list
api_resources_top = ["pods", "services", "deployments", "statefulsets", "daemonsets", "ingresses", "configmaps", "secrets", "persistentvolumes", "persistentvolumeclaims", "nodes", "storageclasses"]
api_resources_kubectl = execute_cmd("kubectl api-resources --no-headers --verbs=get | awk '{print $1}'")
MENUS = [Menu("Namespaces", execute_cmd("kubectl get ns --no-headers | awk '{print $1}'"), 0, curses.COLS // 6),
Menu("API resources", api_resources_top + sorted(list(set(api_resources_kubectl) - set(api_resources_top))), curses.COLS // 6, curses.COLS // 4),
Menu("Resources", [], curses.COLS // 6 + curses.COLS // 4, curses.COLS - (curses.COLS // 6 + curses.COLS // 4))]
MENUS = [Menu("Namespaces", execute_cmd("kubectl get ns --no-headers | awk '{print $1}'"), 0, curses.COLS // 8),
Menu("API resources", api_resources_top + sorted(list(set(api_resources_kubectl) - set(api_resources_top))), curses.COLS // 8, curses.COLS // 4),
Menu("Resources", [], curses.COLS // 8 + curses.COLS // 4, curses.COLS - (curses.COLS // 8 + curses.COLS // 4))]
SELECTED_MENU = MENUS[0]
HELP_TEXT = "q: exit, /: enter filter mode, Esc: exit filter mode, 1: get yaml, 2: describe, 3: edit, 4: pod logs, arrows/TAB: navigation"
ROWS_NUMBER = curses.LINES - 9 # максимальное число видимых строк меню, начиная с 0
@ -26,7 +26,7 @@ ROWS_NUMBER = curses.LINES - 9 # максимальное число видим
def update_menu3():
if not MENUS[0].filtered_rows() or not MENUS[1].filtered_rows(): MENUS[2].rows = ["No namespace or API resource selected"]
elif MENUS[1].selected_row() == "pods": MENUS[2].rows = execute_cmd(f"kubectl -n {MENUS[0].selected_row()} get pods --no-headers | awk '{{ printf \"%-65s %-20s\\n\", $1,$3 }}'")
elif MENUS[1].selected_row() == "pods": MENUS[2].rows = execute_cmd(f"kubectl -n {MENUS[0].selected_row()} get pods -o wide --no-headers | awk '{{ printf \"%-65s %-16s %-10s\\n\", $1,$3,$(NF - 2) }}'")
else: MENUS[2].rows = execute_cmd(f"kubectl -n {MENUS[0].selected_row()} get {MENUS[1].selected_row()} --no-headers | awk '{{printf \"%-85s\\n\", $1}}'")
if MENUS[2].rows == ['']: MENUS[2].rows = [f"No {MENUS[1].selected_row()} found in {MENUS[0].selected_row()} namespace."]
MENUS[2].selected_row_index = 0 # перед перерисовкой сбрасываем выбранную строку на 0