Kubernetes pod port forwarder tool - forwards local ports to pods matching a name pattern.
-
class ml_research_tools.kube.pod_forward_tool.PodForwardTool(services)[source]
Bases: BaseTool
Tool for forwarding ports to Kubernetes pods matching a name pattern.
Initialize the tool with default values.
-
name:
str = 'kube-pod-forward'
-
description:
str = 'Forward port to a Kubernetes pod with a specific name pattern.'
-
__init__(services)[source]
Initialize the tool with default values.
- Return type:
None
-
classmethod add_arguments(parser)[source]
Add tool-specific arguments to the parser.
- Return type:
None
- Parameters:
parser (ArgumentParser)
-
run_kubectl_command(args)[source]
Run a kubectl command and return the results.
- Parameters:
args (List[str]) – Arguments to pass to kubectl
- Return type:
Tuple[bool, str, str]
- Returns:
Tuple of (success, stdout, stderr)
-
get_running_pods(namespace)[source]
Get list of running pods in a namespace.
- Parameters:
namespace (str) – Kubernetes namespace
- Return type:
List[str]
- Returns:
List of pod names
-
find_pod_by_pattern(namespace, pattern)[source]
Find a pod by pattern in a namespace.
- Parameters:
-
- Return type:
Optional[str]
- Returns:
Matched pod name or None
-
forward_port(namespace, pod_name, local_port, remote_port)[source]
Forward a local port to the pod.
- Parameters:
namespace (str) – Kubernetes namespace
pod_name (str) – Name of the pod to forward to
local_port (int) – Local port to forward
remote_port (int) – Remote port on the pod
- Return type:
int
- Returns:
0 for success, non-zero for error
-
display_pod_table(all_pods, matching_pod=None)[source]
Display a table of available pods with the matching one highlighted.
- Parameters:
-
-
execute(config, args)[source]
Execute the port forwarding with the provided arguments.
- Parameters:
args (Namespace) – Parsed command-line arguments
- Return type:
int
- Returns:
Exit code (0 for success, non-zero for error)