Skip to content

[Python SDK] Prioritize IPv4 and normalize Pod IPs in dual-stack environments #915

@moficodes

Description

@moficodes

Description

Currently, the Go SDK client has been refactored (following PR #910) to use a deterministic IP selection rule when connecting to a Sandbox via the Router. In dual-stack environments, the Go client scans the Pod IPs list, prioritizes IPv4 addresses, and normalizes mapped IPv6 formats (e.g. ::ffff:10.0.0.1 to 10.0.0.1) for maximum compatibility with the downstream router's routing handler.

In contrast, the Python SDK (specifically k8s_agent_sandbox/sandbox.py:get_pod_ip) simply returns the first element of the status IPs (pod_ips[0]) without any family-specific prioritization or normalization. This can cause routing issues in dual-stack environments or when encountering mapped IPv6 addresses.

Proposed Changes

Align the Python SDK with the Go SDK's implementation of selectPodIP:

  1. Iterate over the status podIPs list.
  2. Validate each IP string and prefer IPv4 addresses over IPv6.
  3. Normalize mapped IPv6 addresses (e.g. ::ffff:10.0.0.1 -> 10.0.0.1).
  4. Fall back to the first valid IP if no IPv4 is present.
  5. Add unit tests covering dual-stack IP prioritization and normalization cases in test_sandbox.py.

Metadata

Metadata

Assignees

Labels

priority/important-longtermImportant over the long term, but may not be staffed and/or may need multiple releases to complete.

Type

No type
No fields configured for issues without a type.

Projects

Status
Backlog

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions