Skip to content

[Feature Request] Recreate Pod when Sandbox PodTemplate.Spec is updated #581

@kincoy

Description

@kincoy

What's the problem?

Right now, if you update spec.podTemplate.spec on a Sandbox — say, changing the container image or bumping resource limits — nothing happens. The running Pod keeps its old spec.

The controller's reconcilePod finds the existing Pod and updates its labels and ownerReference, but never checks whether the Pod spec has drifted from what the Sandbox declares. There's a TODO about this:

https://github.com/kubernetes-sigs/agent-sandbox/blob/main/controllers/sandbox_controller.go#L602

// TODO - Do we enforce (change) spec if a pod exists ?
// r.Patch(ctx, pod, client.Apply, client.ForceOwnership, ...)

The commented-out code suggests SSA Force Patch, but most Pod spec fields (image, command, resources, etc.) are immutable, so in-place patching won't work. The right approach would be to detect the change and recreate the Pod, similar to how Deployment and StatefulSet handle Pod template updates.

Current workaround

Scale to 0 and back to 1:

kubectl patch sandbox <name> -p '{"spec":{"replicas":0}}'
# wait for the pod to be deleted
kubectl patch sandbox <name> -p '{"spec":{"replicas":1}}'

This works but is not obvious and a bit clunky.

What I'd expect

When spec.podTemplate.spec changes, the controller should:

  1. Detect the change (a hash annotation on the Pod would work — the WarmPool controller already does this via computePodTemplateHash)
  2. Delete the old Pod
  3. Create a new Pod from the updated spec
  4. Preserve existing PVCs (the Sandbox CR still owns them)

This is a recreate strategy, not a rolling update — consistent with the pattern used in SandboxWarmPool (#323).

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions