fix
This commit is contained in:
parent
83ff9af4d6
commit
969a84f30f
@ -44,7 +44,8 @@ class K8sTool:
|
||||
"""Run the main application loop."""
|
||||
console.print(Panel.fit(
|
||||
"[bold cyan]K8s Tool[/bold cyan]\n"
|
||||
"[dim]Interactive kubectl helper[/dim]",
|
||||
"[dim]Interactive kubectl helper[/dim]\n"
|
||||
"[dim]Tip: Press Ctrl+C to cancel and go back[/dim]",
|
||||
border_style="cyan"
|
||||
))
|
||||
|
||||
@ -93,6 +94,10 @@ class K8sTool:
|
||||
style=custom_style
|
||||
).ask()
|
||||
|
||||
if not action:
|
||||
# User pressed Esc
|
||||
return
|
||||
|
||||
if action == "Manage Contexts":
|
||||
self._manage_contexts()
|
||||
elif action == "Select Namespace":
|
||||
@ -274,12 +279,19 @@ class K8sTool:
|
||||
default=False
|
||||
).ask()
|
||||
|
||||
if has_token is None:
|
||||
# User pressed Esc
|
||||
return
|
||||
|
||||
token = None
|
||||
if has_token:
|
||||
token = questionary.password(
|
||||
"Authentication token:",
|
||||
style=custom_style
|
||||
).ask()
|
||||
if token is None:
|
||||
# User pressed Esc
|
||||
return
|
||||
|
||||
# Optional: certificate
|
||||
has_cert = questionary.confirm(
|
||||
@ -288,12 +300,19 @@ class K8sTool:
|
||||
default=False
|
||||
).ask()
|
||||
|
||||
if has_cert is None:
|
||||
# User pressed Esc
|
||||
return
|
||||
|
||||
cert = None
|
||||
if has_cert:
|
||||
cert = questionary.text(
|
||||
"Certificate authority data (base64 encoded):",
|
||||
style=custom_style
|
||||
).ask()
|
||||
if not cert:
|
||||
# User pressed Esc
|
||||
return
|
||||
|
||||
# Confirm
|
||||
console.print("\n[bold]Review:[/bold]")
|
||||
@ -304,7 +323,8 @@ class K8sTool:
|
||||
console.print(f" Token: [cyan]{'***' if token else 'None'}[/cyan]")
|
||||
console.print(f" Certificate: [cyan]{'***' if cert else 'None (insecure)'}[/cyan]")
|
||||
|
||||
if questionary.confirm("\nAdd this context?", style=custom_style, default=False).ask():
|
||||
confirm = questionary.confirm("\nAdd this context?", style=custom_style, default=False).ask()
|
||||
if confirm:
|
||||
self.k8s_client.add_context(context_name, cluster_name, user_name, server, cert, token)
|
||||
|
||||
def _delete_context(self):
|
||||
@ -332,11 +352,13 @@ class K8sTool:
|
||||
if not context_name or context_name == "Cancel":
|
||||
return
|
||||
|
||||
if questionary.confirm(
|
||||
confirm = questionary.confirm(
|
||||
f"Are you sure you want to delete context '{context_name}'?",
|
||||
style=custom_style,
|
||||
default=False
|
||||
).ask():
|
||||
).ask()
|
||||
|
||||
if confirm:
|
||||
self.k8s_client.delete_context(context_name)
|
||||
|
||||
def _manage_favorites(self):
|
||||
@ -384,7 +406,8 @@ class K8sTool:
|
||||
self._remove_namespace_from_favorites()
|
||||
|
||||
elif action == "Clear all favorites":
|
||||
if questionary.confirm("Are you sure you want to clear all favorites?", style=custom_style, default=False).ask():
|
||||
confirm = questionary.confirm("Are you sure you want to clear all favorites?", style=custom_style, default=False).ask()
|
||||
if confirm:
|
||||
self.config.clear_favorites()
|
||||
|
||||
def _view_favorites(self):
|
||||
@ -466,7 +489,8 @@ class K8sTool:
|
||||
|
||||
self.k8s_client.display_deployments_table(deployments)
|
||||
|
||||
if questionary.confirm("View pods for a deployment?", style=custom_style, default=False).ask():
|
||||
view_pods = questionary.confirm("View pods for a deployment?", style=custom_style, default=False).ask()
|
||||
if view_pods:
|
||||
dep_names = [dep['name'] for dep in deployments]
|
||||
dep_name = questionary.select(
|
||||
"Select deployment:",
|
||||
@ -653,7 +677,8 @@ class K8sTool:
|
||||
|
||||
self.k8s_client.display_configmaps_table(configmaps)
|
||||
|
||||
if questionary.confirm("View ConfigMap data?", style=custom_style, default=False).ask():
|
||||
view_data = questionary.confirm("View ConfigMap data?", style=custom_style, default=False).ask()
|
||||
if view_data:
|
||||
cm_names = [cm['name'] for cm in configmaps]
|
||||
cm_name = questionary.select(
|
||||
"Select ConfigMap:",
|
||||
@ -784,7 +809,7 @@ class K8sTool:
|
||||
console.print("[yellow]No pods found[/yellow]")
|
||||
return
|
||||
|
||||
pod_names = [f"{pod['name']} ({pod['status']})" for pod in pods]
|
||||
pod_names = [f"{pod['name']} (Status: {pod['status']}, Age: {pod['age']})" for pod in pods]
|
||||
selected = questionary.select(
|
||||
"Select pod:",
|
||||
choices=pod_names,
|
||||
@ -794,7 +819,7 @@ class K8sTool:
|
||||
if not selected:
|
||||
return
|
||||
|
||||
pod_name = selected.split(" (")[0]
|
||||
pod_name = selected.split(" (Status:")[0]
|
||||
|
||||
# Check if pod has multiple containers
|
||||
containers = self.k8s_client.get_pod_containers(self.current_namespace, pod_name)
|
||||
@ -806,6 +831,9 @@ class K8sTool:
|
||||
choices=containers,
|
||||
style=custom_style
|
||||
).ask()
|
||||
if not container:
|
||||
# User pressed Esc
|
||||
return
|
||||
elif len(containers) == 1:
|
||||
container = containers[0]
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user