Skip to content

fix(kubernetes): label allocated pool pods with sandbox identity - #1610

Open
Kavinjsir wants to merge 1 commit into
opensandbox-group:mainfrom
Kavinjsir:codex/mxk-sandbox-identity
Open

fix(kubernetes): label allocated pool pods with sandbox identity#1610
Kavinjsir wants to merge 1 commit into
opensandbox-group:mainfrom
Kavinjsir:codex/mxk-sandbox-identity

Conversation

@Kavinjsir

Copy link
Copy Markdown

Adds the existing BatchSandbox name label to warm Pool Pods before the allocation annotation is published, and removes it when Pods return idle. This gives pooled and direct-created Pods one stable identity for node-local telemetry without changing scheduling choices. Publication failures compensate labels to the allocator final state, disappearing Pods block publication, and label Patch concurrency is memory-bounded.\n\nValidation: Go 1.25 make test; Go 1.25 golangci-lint; focused race tests for ordering, deletion, partial failure, release, reassignment, no-op, and bounded concurrency.

@github-actions github-actions Bot added component/k8s For kubernetes runtime documentation Improvements or additions to documentation size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Aug 24, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5dfcdfd5a3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +568 to +569
if err := r.syncPodSandboxLabels(ctx, newlyAllocatedPods, newPodAllocation); err != nil {
return err

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Roll back labels when a batch patch partially fails

When several newly allocated Pods are patched and one patch fails after another succeeds, this return skips every SyncSandboxAllocation call but leaves the successful Pod labels in place. Until a later reconciliation completes, those idle Pods advertise an unpublished sandbox identity to telemetry and label-based snapshot lookups. Converge the Pods back to the allocator's current view before returning, as is already done for annotation-publication failures.

AGENTS.md reference: kubernetes/AGENTS.md:L166-L166

Useful? React with 👍 / 👎.

if updated.Labels == nil {
updated.Labels = make(map[string]string)
}
updated.Labels[LabelBatchSandboxNameKey] = sandboxName

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Handle BatchSandbox names longer than a label value

For a valid BatchSandbox whose metadata.name exceeds 63 characters, assigning the raw name here produces an invalid Kubernetes label value. The Pod patch is therefore rejected before the allocation annotation is published, leaving pooled sandboxes with such names permanently unschedulable even though Kubernetes resource names may be longer. Encode a label-safe identity or otherwise preserve lookup without using the full name as a label value.

AGENTS.md reference: kubernetes/AGENTS.md:L3-L3

Useful? React with 👍 / 👎.

Pangjiping

This comment was marked as outdated.

return toSyncMap, orphanPods
}

func (r *PoolReconciler) scheduleSandbox(ctx context.Context, pool *sandboxv1alpha1.Pool, batchSandboxes []*sandboxv1alpha1.BatchSandbox, pods []*corev1.Pod) (*ScheduleResult, error) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我这里有一些建议,可以参考下:
(1)在pod上打标这个事情会对性能有影响,因此应该作为pool级别的可选项(可以参考Recycle的设计)
(2)可以参考Recycle的设计,将这个功能设计成一个通用的Sandbox初始化功能,以在将Pod交付给Sandbox使用前对Pod做一些操作,这些操作可以拓展。
doAllocate: Allocate -> Init(本次新增,用于对pod做一些操作,命名可以再斟酌下) -> SyncToSandbox
doRelease: Recycle(你可以在这里拓展recycle的实现用于去掉pod标签) -> Release -> SyncToSandbox

Here are some suggestions for your reference:

  1. Since labeling Pods incurs a performance overhead, this should be implemented as an optional feature at the pool level (similar to the design of the Recycle mechanism).
  2. Drawing on the Recycle pattern, consider designing this functionality as a generic Sandbox initialization hook. This would allow for extensible pre-processing operations on Pods before they are handed over to the Sandbox.
    Suggested workflow:
    ● doAllocate: Allocate → Init (newly added step for Pod pre-processing; naming subject to refinement) → SyncToSandbox
    ● doRelease: Recycle (the implementation can be extended here to handle Pod label removal) → Release → SyncToSandbox

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component/k8s For kubernetes runtime documentation Improvements or additions to documentation size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants