From 1374935d2dd7d05fa5cf5a66ba569b261996c365 Mon Sep 17 00:00:00 2001 From: "vy.boyko" Date: Sun, 26 Oct 2025 03:12:08 +0300 Subject: [PATCH] update --- k8s_tool/k8s_client.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/k8s_tool/k8s_client.py b/k8s_tool/k8s_client.py index bca4b70..597f4ce 100644 --- a/k8s_tool/k8s_client.py +++ b/k8s_tool/k8s_client.py @@ -56,6 +56,26 @@ class K8sClient: def switch_context(self, context_name: str) -> bool: """Switch to a different context.""" try: + # Load kubeconfig + kubeconfig = self._load_kubeconfig() + if not kubeconfig: + return False + + # Check if context exists + contexts = kubeconfig.get('contexts', []) + context_names = [ctx['name'] for ctx in contexts] + + if context_name not in context_names: + console.print(f"[yellow]Context '{context_name}' not found[/yellow]") + return False + + # Update current-context in kubeconfig file + kubeconfig['current-context'] = context_name + + # Save updated kubeconfig + if not self._save_kubeconfig(kubeconfig): + return False + # Load the new context config.load_kube_config(context=context_name) # Reinitialize API clients