Fix watch mapping for Sandboxes with adopted pods #190
+173
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
When a Sandbox was adopting a pod from a WarmPool, the Sandbox controller was not properly watching the pod because its name didn't match the Sandbox name. Here is an example:
test-warmpool-5dqwkSandboxClaimcalledtest-claim-sandboxwhich in turn creates a new Sandbox calledtest-claim-sandboxas welltest-warmpool-5dqwkStatus.Conditionsare not being updated properly, it still saysPod is ReadyThe controller logs keep showing this message:
The problem comes from this line:
agent-sandbox/controllers/sandbox_controller.go
Line 543 in 36c411a
EnqueueRequestForObjectcreates reconcile requests using the Pod's name (test-warmpool-5dqwk), not the Sandbox's name (test-claim-sandbox)This PR fixes the issue by making sure that the reconciliation logic actually looks at the OwnerRef of the pod instead of using the pod name, because it doesn't necessarily match the Sandbox name.
I think a real longer-term fix should be something like this #162 btw.
Testing
I think the only way to actually test this requires a real Kube cluster (this behavior is really hard to mock), so I wrote an E2E test which replicates the issue by deleting an adopted pod and checking that the status got propagated to the owner Sandbox. As expected, the test fails before my commit and succeeds afterwards.