Skip to content

extensions: propagate claim identity labels to Sandboxes and backing Pods#455

Open
noeljackson wants to merge 1 commit intokubernetes-sigs:mainfrom
noeljackson:claim-identity-labels
Open

extensions: propagate claim identity labels to Sandboxes and backing Pods#455
noeljackson wants to merge 1 commit intokubernetes-sigs:mainfrom
noeljackson:claim-identity-labels

Conversation

@noeljackson
Copy link
Copy Markdown
Contributor

Summary

  • add universal claim identity labels to claimed Sandboxes and backing Pods
  • stamp the labels in both cold-start and warm-pool adoption paths
  • document the labels and cover propagation in controller tests

This adds two generic labels:

  • agents.x-k8s.io/claim-name
  • agents.x-k8s.io/claim-uid

They provide a consumer-agnostic way to locate the Sandbox and Pod associated with a SandboxClaim, including after warm-pool adoption.

Testing

  • GOTMPDIR=/home/noel/src/codewire/isol8/.tmp/go-build GOCACHE=/home/noel/src/codewire/isol8/.tmp/go-cache go test ./extensions/controllers -count=1
  • GOTMPDIR=/home/noel/src/codewire/isol8/.tmp/go-build GOCACHE=/home/noel/src/codewire/isol8/.tmp/go-cache go test ./controllers -count=1

@netlify
Copy link
Copy Markdown

netlify bot commented Mar 21, 2026

Deploy Preview for agent-sandbox canceled.

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

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: noeljackson
Once this PR has been reviewed and has the lgtm label, please assign janetkuo 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 added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Mar 21, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

Hi @noeljackson. 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 size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Mar 21, 2026

// ClaimNameLabel is propagated to Sandboxes and backing Pods so consumers can
// locate the workload associated with a SandboxClaim.
ClaimNameLabel = "agents.x-k8s.io/claim-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.

How about we just keep the claim-uid?

  1. What if the user deletes and recreates the claim with the same name? What happens to the labels of the underlying Pod?
  2. uid is a better strategy for labelling as it has fixed character of 36 conforming to label limits.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed. We use the claim UID (not name) for exactly those reasons. The label key is agents.x-k8s.io/claim-uid and the value is the claim's .metadata.uid, which changes on delete/recreate. No duplicate constant -- we use SandboxIDLabel directly.

@noeljackson noeljackson force-pushed the claim-identity-labels branch from 8015eb6 to 9ed6899 Compare March 25, 2026 21:32
Copy link
Copy Markdown

@codebot-robot codebot-robot left a comment

Choose a reason for hiding this comment

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

Overall, the implementation correctly propagates the claim UID labels to both Sandboxes and their backing Pods, which is beneficial for tracking and discovery. The test coverage effectively validates this behavior across both cold-start and warm-pool adoption paths.

However, there is a notable issue: the newly introduced ClaimUIDLabel constant has the exact same string value (agents.x-k8s.io/claim-uid) as the already existing SandboxIDLabel constant. This duplication results in redundant map assignments in the controllers and overlapping assertions in the tests.

Please see the inline comments for specific suggestions on consolidating these constants and cleaning up the redundant code.

(This review was generated by Overseer)


// ClaimUIDLabel is propagated to Sandboxes and backing Pods as a stable,
// immutable identity that survives delete/recreate of identically-named claims.
ClaimUIDLabel = "agents.x-k8s.io/claim-uid"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This constant has the exact same string value (agents.x-k8s.io/claim-uid) as SandboxIDLabel defined in sandboxtemplate_types.go. Defining two distinct constants for the exact same label key can be confusing and lead to redundant assignments. I recommend either reusing SandboxIDLabel directly or replacing SandboxIDLabel globally with ClaimUIDLabel if you feel it's a more accurate name.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The current version uses SandboxIDLabel directly. No duplicate constant.

adopted.Spec.PodTemplate.ObjectMeta.Labels = make(map[string]string)
}
adopted.Labels = ensureClaimIdentityLabels(adopted.Labels, claim)
adopted.Spec.PodTemplate.ObjectMeta.Labels = ensureClaimIdentityLabels(adopted.Spec.PodTemplate.ObjectMeta.Labels, claim)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Because ClaimUIDLabel (set inside ensureClaimIdentityLabels) and SandboxIDLabel share the exact same string value, this code ends up writing the exact same map key twice to adopted.Spec.PodTemplate.ObjectMeta.Labels. Consolidating the constants will resolve this duplication.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Resolved. Using SandboxIDLabel only, no duplicate writes.

sandbox.Spec.PodTemplate.ObjectMeta.Labels = make(map[string]string)
}
sandbox.Labels = ensureClaimIdentityLabels(sandbox.Labels, claim)
sandbox.Spec.PodTemplate.ObjectMeta.Labels = ensureClaimIdentityLabels(sandbox.Spec.PodTemplate.ObjectMeta.Labels, claim)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The manual nil check for sandbox.Spec.PodTemplate.ObjectMeta.Labels on the preceding lines (508-510) is now redundant since ensureClaimIdentityLabels already securely handles nil map initialization.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed the redundant nil check. ensureClaimIdentityLabels handles nil initialization.

}

// 2. Verify pod template claim-uid label was added
if val := adoptedSandbox.Spec.PodTemplate.ObjectMeta.Labels[extensionsv1alpha1.ClaimUIDLabel]; val != string(claim.UID) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

These two tests (step 2 and step 3) are asserting the exact same label key (agents.x-k8s.io/claim-uid) in PodTemplate.ObjectMeta.Labels, just using two different constants. If you consolidate the constants as suggested, one of these assertions can be removed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Already consolidated. Tests use SandboxIDLabel only.

PodTemplate: sandboxv1alpha1.PodTemplate{
ObjectMeta: sandboxv1alpha1.PodMetadata{
Labels: map[string]string{
extensionsv1alpha1.ClaimUIDLabel: "claim-uid-1",
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If ClaimUIDLabel is removed in favor of SandboxIDLabel to prevent duplicate constants, ensure this test uses the correct constant to verify label propagation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Already consolidated. Tests use SandboxIDLabel only.

if err != nil {
t.Fatalf("expected sandbox to be created but got error: %v", err)
}
if val := sandbox.Labels[extensionsv1alpha1.ClaimUIDLabel]; val != string(claim.UID) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Like the adoption tests above, if the duplicate constants are consolidated, these assertions will need to be updated to use the single unified constant.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Already consolidated. Tests use SandboxIDLabel only.

@noeljackson
Copy link
Copy Markdown
Contributor Author

Friendly bump. All review comments addressed, tests pass. Could a maintainer run /ok-to-test when convenient?

@noeljackson noeljackson force-pushed the claim-identity-labels branch from 9546055 to 6bb656a Compare April 2, 2026 13:09
@aditya-shantanu
Copy link
Copy Markdown
Contributor

/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 Apr 2, 2026
When a SandboxClaim creates or adopts a Sandbox, the controller now
propagates agents.x-k8s.io/claim-uid (via the existing SandboxIDLabel
constant) to both the Sandbox CR and its Pod template labels.

This consolidates with SandboxIDLabel rather than introducing a
duplicate constant — both represent the claim UID for discovery
and NetworkPolicy targeting.
@noeljackson noeljackson force-pushed the claim-identity-labels branch from 6bb656a to 0bbf49b Compare April 3, 2026 12:28
@noeljackson
Copy link
Copy Markdown
Contributor Author

/retest

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

Labels

area:extensions cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. 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