AS AgentScopeAPI 手册 / API Reference

K8sHelper

public class K8sHelper
源码Source io/agentscope/extensions/sandbox/kubernetes/client/internal/K8sHelper.java:50–407

K 8 s Helper,在隔离环境中安全执行代码和工具。位于 io.agentscope.extensions.sandbox.kubernetes.client.internal 包。核心成员包括 getClient、createSandboxClaim、deleteSandboxClaim、getSandboxClaim、listSandboxClaims、getSandbox。

Encapsulates Kubernetes CRD operations for agent-sandbox lifecycle management. Mirrors the Python SDK's K8sHelper.

构造器摘要Constructor Summary

构造器Constructor说明Description
public K8sHelper(KubernetesClient client)
初始化 `K8sHelper` 实例。
Creates a new instance.

方法摘要Method Summary

方法Method说明Description
public KubernetesClient getClient()
获取客户端。
Returns the client.
public SandboxClaim createSandboxClaim(String name, String warmPool, String namespace, Map<String, String> labels, Long shutdownAfterSeconds, Map<String, String> podLabels, Map<String, String> podAnnotations)
创建 `createSandboxClaim`。
Creates a SandboxClaim referencing the given warm pool.
public void deleteSandboxClaim(String name, String namespace)
删除 `deleteSandboxClaim`。
Deletes a SandboxClaim.
public SandboxClaim getSandboxClaim(String name, String namespace)
获取 `getSandboxClaim`。
Gets a SandboxClaim, or null if not found.
public List<String> listSandboxClaims(String namespace, String labelSelector)
列出 `listSandboxClaims`。
Lists SandboxClaim names in a namespace, optionally filtered by label selector.
public SandboxResource getSandbox(String name, String namespace)
获取沙箱。
Gets a Sandbox resource, or null if not found.
public String resolveSandboxName(String claimName, String namespace, long timeoutSeconds) throws Exception
解析沙箱名称。
Watches the SandboxClaim until the sandbox name is resolved in its status.
public SandboxResource.SandboxIdentity waitForSandboxReady(String sandboxName, String namespace, long timeoutSeconds) throws Exception
等待用于沙箱就绪。
Waits for a Sandbox resource to become Ready.
public static String selectPodIp(List<String> podIPs)
static
设置该参数。
Selects a preferred pod IP (first IPv4 if present, otherwise first entry).

构造器详情Constructor Detail

K8sHelper

public K8sHelper(KubernetesClient client)

初始化 K8sHelper 实例。

Creates a new instance.

参数Parameters
名称Name类型Type说明Description
clientKubernetesClient客户端(类型 `KubernetesClient`)。The client.
源码Source io/agentscope/extensions/sandbox/kubernetes/client/internal/K8sHelper.java:56–58

方法详情Method Detail

getClient

public KubernetesClient getClient()

获取客户端。

Returns the client.

返回Returns KubernetesClient
返回KubernetesClient。Returns kubernetes client.
源码Source io/agentscope/extensions/sandbox/kubernetes/client/internal/K8sHelper.java:60–62

createSandboxClaim

public SandboxClaim createSandboxClaim(String name, String warmPool, String namespace, Map<String, String> labels, Long shutdownAfterSeconds, Map<String, String> podLabels, Map<String, String> podAnnotations)

创建 createSandboxClaim。

Creates a SandboxClaim referencing the given warm pool.

参数Parameters
名称Name类型Type说明Description
nameString名称(类型 `String`)。claim name
warmPoolStringwarm 连接池(类型 `String`)。warm pool name
namespaceString命名空间(类型 `String`)。Kubernetes namespace
labelsMap<String, String>labels(类型 `Map`)。optional claim labels
shutdownAfterSecondsLongshutdown 之后秒(类型 `Long`)。optional TTL; when set, populates `spec.lifecycle`
podLabelsMap<String, String>pod Labels(类型 `Map`)。optional labels for `spec.additionalPodMetadata`
podAnnotationsMap<String, String>用于`spec.additionalPodMetadata`的可选注解。optional annotations for `spec.additionalPodMetadata`
返回Returns SandboxClaim
返回SandboxClaim。the created claim
源码Source io/agentscope/extensions/sandbox/kubernetes/client/internal/K8sHelper.java:76–125

deleteSandboxClaim

public void deleteSandboxClaim(String name, String namespace)

删除 deleteSandboxClaim。

Deletes a SandboxClaim.

参数Parameters
名称Name类型Type说明Description
nameString名称(类型 `String`)。claim name
namespaceString命名空间(类型 `String`)。namespace
源码Source io/agentscope/extensions/sandbox/kubernetes/client/internal/K8sHelper.java:133–146

getSandboxClaim

public SandboxClaim getSandboxClaim(String name, String namespace)

获取 getSandboxClaim。

Gets a SandboxClaim, or null if not found.

参数Parameters
名称Name类型Type说明Description
nameString名称(类型 `String`)。claim name
namespaceString命名空间(类型 `String`)。namespace
返回Returns SandboxClaim
返回SandboxClaim。claim or null
源码Source io/agentscope/extensions/sandbox/kubernetes/client/internal/K8sHelper.java:155–157

listSandboxClaims

public List<String> listSandboxClaims(String namespace, String labelSelector)

列出 listSandboxClaims。

Lists SandboxClaim names in a namespace, optionally filtered by label selector.

参数Parameters
名称Name类型Type说明Description
namespaceString命名空间(类型 `String`)。namespace
labelSelectorString标签 Selector(类型 `String`)。optional label selector
返回Returns List<String>
返回列出。claim names
源码Source io/agentscope/extensions/sandbox/kubernetes/client/internal/K8sHelper.java:166–181

getSandbox

public SandboxResource getSandbox(String name, String namespace)

获取沙箱。

Gets a Sandbox resource, or null if not found.

参数Parameters
名称Name类型Type说明Description
nameString名称(类型 `String`)。sandbox name
namespaceString命名空间(类型 `String`)。namespace
返回Returns SandboxResource
返回SandboxResource。sandbox or null
源码Source io/agentscope/extensions/sandbox/kubernetes/client/internal/K8sHelper.java:190–192

resolveSandboxName

public String resolveSandboxName(String claimName, String namespace, long timeoutSeconds) throws Exception

解析沙箱名称。

Watches the SandboxClaim until the sandbox name is resolved in its status.

参数Parameters
名称Name类型Type说明Description
claimNameStringclaim 名称(类型 `String`)。claim name
namespaceString命名空间(类型 `String`)。namespace
timeoutSecondslong超时秒(类型 `long`)。timeout
返回Returns String
返回字符串结果。resolved sandbox name
抛出Throws
  • Exception 可能抛出 `Exception`。Thrown when the operation cannot be completed.
源码Source io/agentscope/extensions/sandbox/kubernetes/client/internal/K8sHelper.java:202–264

waitForSandboxReady

public SandboxResource.SandboxIdentity waitForSandboxReady(String sandboxName, String namespace, long timeoutSeconds) throws Exception

等待用于沙箱就绪。

Waits for a Sandbox resource to become Ready.

参数Parameters
名称Name类型Type说明Description
sandboxNameString沙箱名称(类型 `String`)。sandbox name
namespaceString命名空间(类型 `String`)。namespace
timeoutSecondslong超时秒(类型 `long`)。timeout
返回Returns SandboxResource.SandboxIdentity
返回SandboxResource.SandboxIdentity。sandbox identity metadata
抛出Throws
  • Exception 可能抛出 `Exception`。Thrown when the operation cannot be completed.
源码Source io/agentscope/extensions/sandbox/kubernetes/client/internal/K8sHelper.java:274–321

selectPodIp

public static String selectPodIp(List<String> podIPs)
static

设置该参数。

Selects a preferred pod IP (first IPv4 if present, otherwise first entry).

参数Parameters
名称Name类型Type说明Description
podIPsList<String>pod I Ps(类型 `List`)。pod IP list
返回Returns String
返回字符串结果。selected IP or null
源码Source io/agentscope/extensions/sandbox/kubernetes/client/internal/K8sHelper.java:329–340
基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.