Skip to content

sandboxclaim fix TemplateNotFound (#444)#445

Open
phantooom wants to merge 2 commits intokubernetes-sigs:mainfrom
phantooom:main
Open

sandboxclaim fix TemplateNotFound (#444)#445
phantooom wants to merge 2 commits intokubernetes-sigs:mainfrom
phantooom:main

Conversation

@phantooom
Copy link
Copy Markdown

@phantooom phantooom commented Mar 20, 2026

@netlify
Copy link
Copy Markdown

netlify bot commented Mar 20, 2026

Deploy Preview for agent-sandbox canceled.

Name Link
🔨 Latest commit be30946
🔍 Latest deploy log https://app.netlify.com/projects/agent-sandbox/deploys/69be1f07ebbd7e00087569ac

@k8s-ci-robot k8s-ci-robot requested a review from barney-s March 20, 2026 07:59
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: phantooom
Once this PR has been reviewed and has the lgtm label, please assign justinsb for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot requested a review from igooch March 20, 2026 07:59
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Mar 20, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

Welcome @phantooom!

It looks like this is your first PR to kubernetes-sigs/agent-sandbox 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/agent-sandbox has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Mar 20, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

Hi @phantooom. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions 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.

@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Mar 20, 2026
@igooch
Copy link
Copy Markdown
Contributor

igooch commented Mar 20, 2026

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Mar 20, 2026
@phantooom
Copy link
Copy Markdown
Author

Do you have any suggestions about this pr. thanks @igooch

@kincoy
Copy link
Copy Markdown

kincoy commented Mar 30, 2026

LGTM, thanks! Would be nice to add some tests.

@barney-s
Copy link
Copy Markdown
Contributor

barney-s commented Apr 3, 2026

@igooch @vicentefb - How do we test the impact of this PR on scale latencies and P numbers ?
Are the tests checked in ? Can we run the tests against this PR (Rebased to main) ?

if err := mgr.GetFieldIndexer().IndexField(context.Background(), &extensionsv1alpha1.SandboxClaim{}, templateRefIndexField, func(obj client.Object) []string {
claim, ok := obj.(*extensionsv1alpha1.SandboxClaim)
if !ok {
return nil
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.

I'm always wary of silently ignoring errors. I would probably at least log, and in this case panic. Given that I'm suggesting a panic, I think you could just claim := obj.(*extensionsv1alpha1.SandboxClaim)

// that reference the given SandboxTemplate. This ensures that when a
// SandboxTemplate is created or updated, any claims waiting for it get reconciled.
func (r *SandboxClaimReconciler) findClaimsForTemplate(ctx context.Context, obj client.Object) []reconcile.Request {
template, ok := obj.(*extensionsv1alpha1.SandboxTemplate)
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.

Same here TBH, I would probably just do a template := obj.(*extensionsv1alpha1.SandboxClaim)

client.InNamespace(template.Namespace),
client.MatchingFields{templateRefIndexField: template.Name},
); err != nil {
log.FromContext(ctx).Error(err, "failed to list SandboxClaims for template", "template", template.Name)
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.

Contrary to the above case, I agree with this not panicking. We don't expect it, but it's maybe "less unexpected" than getting the wrong object type. 👍 for logging so we can see if it is actually happening

@justinsb
Copy link
Copy Markdown
Contributor

justinsb commented Apr 3, 2026

Thank you @phantooom

I actually see this as fixing the issue that we should re-reconcile a claim whenever the template changes / is created. It will help performance, but I don't see this as a performance fix.

Do we have any tests that rely on this working correctly? (For example, a test where we create the SandboxClaim and then the SandboxTemplate - and if not, can we tweak one of the existing tests to make sure we are going through this code path).

This PR is not marked as fixing #444 and I think that's correct, I actually think the fix for #444 is to return ErrTemplateNotFound i.e. delete this code:

    if errors.Is(reconcileErr, ErrTemplateNotFound) {
        return result, nil // returns nil error — no requeue
    }

But I think to do that we want to merge this PR first.

I have a habit of being verbose; blockers are 1) can we just cast to SandboxTemplate and 2) do we have a test or can we reorder an existing test to rely on this index?

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

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. next-step:contributor ok-to-test Indicates a non-member PR verified by an org member that is safe to test. 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.

6 participants