Switch to default namespace of context if namespaces list is forbidden

This commit is contained in:
Digital 2024-12-17 09:59:52 +03:00
parent 8251b99614
commit 420eb47583
1 changed files with 5 additions and 1 deletions

6
kls
View File

@ -222,7 +222,11 @@ def init_menus():
api_resources = list( api_resources = list(
dict.fromkeys(TOP_API_RESOURCES + api_resources_kubectl)) # so top api resources are at the top dict.fromkeys(TOP_API_RESOURCES + api_resources_kubectl)) # so top api resources are at the top
width_unit = WIDTH // 8 width_unit = WIDTH // 8
menus = [Menu("Namespaces", kubectl("get ns --no-headers -o custom-columns=NAME:.metadata.name"), 0, width_unit, ROWS_HEIGHT), try:
namespaces = kubectl("get ns --no-headers -o custom-columns=NAME:.metadata.name")
except:
namespaces = kubectl("config view --minify --output 'jsonpath={..namespace}'") # if it is forbidden to list all namespaces
menus = [Menu("Namespaces", namespaces, 0, width_unit, ROWS_HEIGHT),
Menu("API resources", api_resources, width_unit, width_unit * 2, ROWS_HEIGHT), Menu("API resources", api_resources, width_unit, width_unit * 2, ROWS_HEIGHT),
Menu("Resources", [], width_unit * 3, WIDTH - width_unit * 3, ROWS_HEIGHT)] Menu("Resources", [], width_unit * 3, WIDTH - width_unit * 3, ROWS_HEIGHT)]
selected_menu = menus[0] selected_menu = menus[0]