From 420eb47583506c47301138a484eb9714bc476cf7 Mon Sep 17 00:00:00 2001 From: Digital Date: Tue, 17 Dec 2024 09:59:52 +0300 Subject: [PATCH] Switch to default namespace of context if namespaces list is forbidden --- kls | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kls b/kls index d49c5a4..cce8457 100755 --- a/kls +++ b/kls @@ -222,7 +222,11 @@ def init_menus(): api_resources = list( dict.fromkeys(TOP_API_RESOURCES + api_resources_kubectl)) # so top api resources are at the top 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("Resources", [], width_unit * 3, WIDTH - width_unit * 3, ROWS_HEIGHT)] selected_menu = menus[0]