sandbox_controller: get pod name from sandbox annotations on deletion#224
sandbox_controller: get pod name from sandbox annotations on deletion#224Iceber wants to merge 2 commits intokubernetes-sigs:mainfrom
Conversation
✅ Deploy Preview for agent-sandbox canceled.
|
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Iceber The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Hi @Iceber. Thanks for your PR. I'm waiting for a github.com member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
One is the logging name. @sdowell FYI |
|
Could we add a unit-test that fails without this fix ? |
|
/ok-to-test |
@barney-s I added a simple test, PTAL, Thanks |
Signed-off-by: Iceber Gu <caiwei95@hotmail.com>
Signed-off-by: Iceber Gu <caiwei95@hotmail.com>
59ed02f to
13aa72c
Compare
| podName := sandbox.Name | ||
| if name := sandbox.Annotations[SandboxPodNameAnnotation]; name != "" { | ||
| podName = name | ||
| log.Info("Using tracked pod name from sandbox annotation", "podName", podName) |
There was a problem hiding this comment.
If a malicious user has permissions to edit Sandbox annotations but not to delete arbitrary Pods in the namespace, they could set annotations on their Sandbox to indirectly delete any target Pod they want (in the same namespace).
Before deleting the Pod, Get it and verify its ControllerRef (OwnerReferences with controller=true) point to this Sandbox.
| // handles sandbox expiry by deleting child resources and the sandbox itself if needed | ||
| func (r *SandboxReconciler) handleSandboxExpiry(ctx context.Context, sandbox *sandboxv1alpha1.Sandbox) (bool, error) { | ||
| var allErrors error | ||
| log := log.FromContext(ctx) |
There was a problem hiding this comment.
This variable declaration shadows the imported log package. It's safer and cleaner to rename it to avoid confusion and potential scope issues.
| if name := sandbox.Annotations[SandboxPodNameAnnotation]; name != "" { | ||
| podName = name | ||
| log.Info("Using tracked pod name from sandbox annotation", "podName", podName) | ||
| } |
|
The Kubernetes project currently lacks enough active contributors to adequately respond to all PRs. This bot triages PRs according to the following rules:
You can:
Please send feedback to us at Agent Sandbox. /lifecycle stale |
|
@Iceber: The following test failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
|
please rebase @Iceber |
|
and fix the linter error @Iceber |
codebot-robot
left a comment
There was a problem hiding this comment.
Overall, the PR effectively aligns the deletion logic with the pod assignment changes, correctly addressing the deletion of adopted pods upon sandbox expiry by reading the tracked pod name from annotations. However, I've left several comments focused on maintainability, safety, and test coverage:
- Extract duplicated logic for determining the Pod name into a helper function to keep the codebase DRY.
- Enhance
r.Deletesafety by usingPreconditionsto prevent race conditions during Pod deletion. - Standardize structured logging keys and error messages to include the dynamic pod name.
- Expand test coverage to include edge cases like
ShutdownPolicyDelete. - Improve test rigor by asserting boolean return values and status updates, verifying that the "un-annotated" pod is not inadvertently deleted (using negative assertions), and enhancing test failure visibility (e.g., avoiding
require.Truefor error checking and improving failure context messages).
(This review was generated by Overseer)
agent-sandbox/controllers/sandbox_controller.go
Lines 314 to 320 in 7ed7d38
consistent with pod assignment
ref #265