Simplify sandbox pod match

Open
#277 8 comments 0 reactions 2 assignees View on GitHub

@safiya2610 is already working on this.

Since Jun 28, 2026.

Assessment

This issue has not been assessed yet.

Description

kind/enhancement

After
https://github.com/kubernetes-sigs/agent-sandbox/pull/272 merged, each sanbox will have an annotation pointed to the pod.

So we donot need to do label selector matching, not this depend on agent-sandbox v0.3.10

// GetSandboxPodIP gets the IP address of the pod corresponding to the Sandbox
func (c *K8sClient) GetSandboxPodIP(_ context.Context, namespace, sandboxName, podName string) (string, error) {
	// If podName is provided, try to get it directly from cache first
	if podName != "" {
		pod, err := c.podLister.Pods(namespace).Get(podName)
		if err == nil && pod != nil {
			return validateAndGetPodIP(pod)
		}
		klog.Infof("failed to get sandbox pod %s/%s: %v, try get pod by sandbox-name label", namespace, podName, err)
	}
	// Find pod through label selector (sandbox-name label we set)
	pods, err := c.podLister.Pods(namespace).List(labels.SelectorFromSet(map[string]string{SandboxNameLabelKey: sandboxName}))
	if err != nil {
		return "", fmt.Errorf("failed to list pods from cache: %w", err)
	}
	// Find the pod that belongs to this sandbox by checking ownerReferences
	for _, pod := range pods {
		for _, ownerRef := range pod.OwnerReferences {
			if ownerRef.Kind == "Sandbox" && ownerRef.Name == sandboxName {
				if ownerRef.Controller == nil || *ownerRef.Controller {
					return validateAndGetPodIP(pod)
				}
			}
		}
	}

	return "", fmt.Errorf("no pod found for sandbox %s", sandboxName)
}```
Dominant language
Go
Stars
167
Forks
88
Avg merge
1d 11h
Merged PRs (30d)
2

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from volcano-sh/agentcube

All issues in volcano-sh/agentcube

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.