Skip to content

fix(kubernetes): recover BatchSandbox after Pod restart - #1523

Open
luffy0x wants to merge 2 commits into
opensandbox-group:mainfrom
luffy0x:fix/1497-batchsandbox-recovery
Open

fix(kubernetes): recover BatchSandbox after Pod restart#1523
luffy0x wants to merge 2 commits into
opensandbox-group:mainfrom
luffy0x:fix/1497-batchsandbox-recovery

Conversation

@luffy0x

@luffy0x luffy0x commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Testing

  • Unit tests
  • Documentation build (cd docs && pnpm docs:build)
  • Integration tests (envtest asset download timed out against GitHub during make test)
  • e2e / manual verification (requires the Kind/Docker environment)

Breaking Changes

  • None
  • Yes (describe impact and migration path)

Checklist

  • Linked Issue or clearly described motivation
  • Added/updated docs (if needed)
  • Added/updated tests (if needed)
  • Security impact considered
  • Backward compatibility considered

Persist failed Pod UIDs so a recovered original Pod can clear a stale Failed phase without treating a replacement Pod as recovery.

Fixes opensandbox-group#1497
@github-actions github-actions Bot added component/k8s For kubernetes runtime documentation Improvements or additions to documentation size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Aug 14, 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: 1e29c5ea28

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

}
}

status.FailedPodUIDs = nil

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 Clear failedPodUIDs in the merge patch

When a failed pod recovers, setting FailedPodUIDs to nil is not enough to remove the persisted status field because updateStatus marshals the struct into a JSON merge patch and the field is tagged omitempty, so failedPodUIDs is omitted rather than sent as null. After recovery, the API server keeps the old UID list, the desired status keeps comparing unequal to the stored status, and the reconciler will keep trying to patch the same object instead of becoming idempotent.

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

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Confirmed against the current head (1e29c5e). This is more than a stale-status cosmetic issue: applyResumingRuntimePhase intentionally clears this provenance so resume failures remain terminal, but the merge patch omits the key. On the next steady reconcile, the stale UID can satisfy failedPodsRecovered and incorrectly move that lifecycle failure back to Succeed. Please serialize an explicit deletion/null (or use a status update) and add a persistence-level test that round-trips the API patch, rather than checking only the in-memory runtime view.

// current Failed phase. The controller uses these UIDs to distinguish an
// in-place recovery from a replacement Pod that reuses the same name.
// +optional
FailedPodUIDs []types.UID `json:"failedPodUIDs,omitempty"`

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 Keep the Helm CRD schema in sync

This status field is added to the Go type and the Kustomize CRD, but the bundled Helm CRD copy at kubernetes/charts/opensandbox-controller/templates/crds/batchsandboxes.yaml still lacks status.failedPodUIDs. In Helm-installed clusters, that unknown status field is pruned by the CRD schema, so the controller cannot persist pod UID provenance and the transient Pod recovery path remains ineffective for Helm users.

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

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Confirmed by rendering the chart: the Helm CRD contains pauseObservedGeneration but not failedPodUIDs. With the status schema missing this property, Kubernetes prunes the UID provenance, so the next reconciliation sees no recorded identity and the recovery path remains terminal for Helm-installed clusters. Please sync the chart CRD and, if practical, add a generated-CRD parity check to prevent the Helm copy from drifting again.

@luffy0x

luffy0x commented Aug 21, 2026

Copy link
Copy Markdown
Contributor Author

@Pangjiping 您好,#1497 的修复已在 PR #1523 中更新,之前 review 提出的两项问题均已处理:

  • 显式清除持久化的 failedPodUIDs,并补充持久化回归测试;
  • 同步 Helm CRD schema。

目前 PR 正在等待维护者复审和合并。方便时烦请帮忙审核;如果实现符合预期,请协助 approve 并 merge。若仍有冲突、CI 门禁或其他问题需要作者处理,也请指出,我会及时跟进。

@jianpingpei 也烦请帮忙确认最新修改是否覆盖了 #1497 中报告的场景。谢谢!

English

Hi @Pangjiping, the fix for #1497 has been updated in PR #1523. Both issues raised during the previous review have been addressed:

  • Explicitly clear the persisted failedPodUIDs and add a persistence-level regression test.
  • Synchronize the Helm CRD schema.

The PR is currently awaiting maintainer review and merge. When convenient, could you please review it? If the implementation looks good, please approve and merge it. If any conflicts, CI requirements, or other changes still need to be handled by the author, please let me know and I will follow up promptly.

@jianpingpei, could you also please confirm whether the latest changes cover the scenario reported in #1497? Thank you!

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/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BatchSandbox remains Failed after the same Pod recovers to Running and Ready

2 participants