update
This commit is contained in:
parent
8496ef86ca
commit
1374935d2d
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user