Skip to content

Sanitize remote metadata for MultiKueue external-framework jobs - #12643

Merged
kubernetes-prow[bot] merged 2 commits into
kubernetes-sigs:mainfrom
apullo777:fix/12540-multikueue-external-adapter-ownerrefs
Jul 1, 2026
Merged

kubernetes-prow[bot] merged 2 commits into
kubernetes-sigs:mainfrom
apullo777:fix/12540-multikueue-external-adapter-ownerrefs

Conversation

@apullo777

@apullo777 apullo777 commented Jun 30, 2026 •

Copy link
Copy Markdown
Member

What type of PR is this?

/kind bug
/area multikueue

What this PR does / why we need it:

The external-framework MultiKueue adapter created remote objects from localObj.DeepCopy() and only cleared resourceVersion. This could copy source-cluster metadata such as ownerReferences to the worker cluster.

Since those owner UIDs do not exist on the worker, the worker garbage collector can delete the remote object, causing the adapter to recreate it repeatedly.

This PR builds the remote unstructured object from scratch instead, keeping only GVK, name, namespace, labels, annotations, and spec. This mirrors the api.CloneObjectMetaForCreation whitelist used by the typed adapters.

The integration test asserts that the remote object is created without ownerReferences, finalizers, or status. It does not assert the full create-delete loop because envtest does not run a real garbage collector. AI assistance was used for parts of this change.

Which issue(s) this PR fixes:

Fixes #12540

Special notes for your reviewer:

Does this PR introduce a user-facing change?

MultiKueue: Fixed custom jobs using external-framework adapters being repeatedly created and deleted on worker clusters when source-cluster metadata was copied to the remote object.

Summary by CodeRabbit

  • Bug Fixes

    • Remote objects created for admitted workloads are now sanitized to include only the expected creation-safe metadata (and spec only when present), avoiding unintended carryover such as local ownership details and status.
    • Worker-created resources no longer inherit source-cluster ownership, finalizers, or status metadata.
  • Tests

    • Added unit tests to verify creation-safe cloning and remote object metadata/spec handling (including replicas/spec behavior).
    • Added an integration scenario ensuring worker-created RayCluster resources start without inherited source metadata.

@kubernetes-prow kubernetes-prow Bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/bug Categorizes issue or PR as related to a bug. area/multikueue Issues or PRs related to MultiKueue labels Jun 30, 2026
@netlify

netlify Bot commented Jun 30, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for kubernetes-sigs-kueue canceled.

Name Link
🔨 Latest commit 8f9fe91
🔍 Latest deploy log https://app.netlify.com/projects/kubernetes-sigs-kueue/deploys/6a44086a2e87740008d88bf2

@kubernetes-prow kubernetes-prow Bot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jun 30, 2026
@kubernetes-prow kubernetes-prow Bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jun 30, 2026
@kubernetes-prow

Copy link
Copy Markdown

Hi @apullo777. 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.

Tip

We noticed you've done this a few times! Consider joining the org to skip this step and gain /lgtm and other bot rights. We recommend asking approvers on your previous PRs to sponsor you.

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.

@kubernetes-prow kubernetes-prow Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jun 30, 2026
@coderabbitai

coderabbitai Bot commented Jun 30, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b523f09d-0ef7-407c-bc0c-f8b930f33ac3

📥 Commits

Reviewing files that changed from the base of the PR and between 9e277c5 and 8f9fe91.

📒 Files selected for processing (2)
  • pkg/controller/admissionchecks/multikueue/externalframeworks/adapter.go
  • pkg/controller/admissionchecks/multikueue/externalframeworks/adapter_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • pkg/controller/admissionchecks/multikueue/externalframeworks/adapter.go
  • pkg/controller/admissionchecks/multikueue/externalframeworks/adapter_test.go

📝 Walkthrough

Walkthrough

createRemoteObject in the MultiKueue external frameworks adapter now clones only creation-safe metadata and spec fields before creating remote objects. New unit and integration tests verify that source-cluster metadata is stripped and expected fields are preserved.

Safe remote object cloning

Layer / File(s) Summary
Creation-safe clone helper
pkg/controller/admissionchecks/multikueue/externalframeworks/adapter.go
createRemoteObject now uses cloneUnstructuredForCreation, which rebuilds an unstructured.Unstructured with cleaned metadata from api.CloneObjectMetaForCreation and copies spec when present.
Unit coverage for cloning and remote creation
pkg/controller/admissionchecks/multikueue/externalframeworks/adapter_test.go
Tests verify the clone helper preserves apiVersion/kind, name/namespace, labels, annotations, and spec, while removing creation-forbidden metadata. Another test verifies remote object creation sanitization and spec handling.
Integration coverage for worker copies
test/integration/multikueue/external_job_test.go
A new integration test creates a manager RayCluster with a fake owner reference and checks that the worker-side remote RayCluster has empty OwnerReferences, empty Finalizers, and zero Status.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 I hopped through the metadata brush,
Leaving behind the noisy rush.
Only clean fields crossed the gate,
So remote clones now feel just great.
No shadow refs to cause a fuss—
Just specs and names that travel with us.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: sanitizing remote metadata for MultiKueue external-framework jobs.
Linked Issues check ✅ Passed The adapter now builds remote objects from a creation-safe subset and tests confirm unsafe metadata is stripped, addressing the reported Create-Delete loop.
Out of Scope Changes check ✅ Passed The only code changes are the adapter fix and tests that directly support the linked metadata-sanitization bug.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@mbobrovskyi

Copy link
Copy Markdown
Contributor

/ok-to-test

@kubernetes-prow kubernetes-prow Bot 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 Jun 30, 2026

// cloneUnstructuredForCreation creates a copy of obj containing only the GVK, name,
// namespace, labels, annotations and spec, the unstructured analogue of
// api.CloneObjectMetaForCreation; keep the two in sync. Dropping the rest (notably

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.

To be more precise, this replicates the logic of copySpec func(dst, src PtrT), which just so happens to, for every implementation, copy the spec and use the api.CloneObjectMetaForCreation to copy the ObjectMeta.

To avoid having to sync methods we can extract the part that does indeed focus on mirroring api.CloneObjectMetaForCreation and make one of the methods call the other. Since both cases would require converting Unstructured and ObjectMeta in both directions, choosing where the logic actually lies should mainly be a cosmetic choice. It might be easier to use the api.CloneObjectMetaForCreation here instead of the other way around as it is placed in the utils/api package.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks, that makes sense. I will update cloneUnstructuredForCreation to reuse api.CloneObjectMetaForCreation for the metadata part, and keep only the unstructured-specific spec copy locally.

That should remove the parallel whitelist / “keep in sync” concern while keeping the behavior covered by the existing TestCloneUnstructuredForCreation cases. I will also thread an error return through, since the unstructured to ObjectMeta conversion can fail.

@mimowo

mimowo commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

/lgtm
/approve
/cherrypick release-0.18
/cherrypick release-0.17
Thank you for hardening of Kueue 👍

@k8s-infra-cherrypick-robot

Copy link
Copy Markdown
Contributor

@mimowo: once the present PR merges, I will cherry-pick it on top of release-0.17, release-0.18 in new PRs and assign them to you.

Details

In response to this:

/lgtm
/approve
/cherrypick release-0.18
/cherrypick release-0.17
Thank you for hardening of Kueue 👍

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.

@kubernetes-prow kubernetes-prow Bot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 1, 2026
@kubernetes-prow

Copy link
Copy Markdown

LGTM label has been added.

DetailsGit tree hash: ec9a735ee501ab2f081e4af9bf893c27f6943b18

@kubernetes-prow

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: apullo777, mimowo

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

The pull request process is described 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

@kubernetes-prow kubernetes-prow Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 1, 2026
@kubernetes-prow
kubernetes-prow Bot merged commit 3628238 into kubernetes-sigs:main Jul 1, 2026
56 checks passed
@kubernetes-prow kubernetes-prow Bot added this to the v0.19 milestone Jul 1, 2026
@k8s-infra-cherrypick-robot

Copy link
Copy Markdown
Contributor

@mimowo: new pull request created: #12677

Details

In response to this:

/lgtm
/approve
/cherrypick release-0.18
/cherrypick release-0.17
Thank you for hardening of Kueue 👍

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-infra-cherrypick-robot

Copy link
Copy Markdown
Contributor

@mimowo: #12643 failed to apply on top of branch "release-0.17":

Applying: Sanitize remote metadata for MultiKueue external-framework jobs
Using index info to reconstruct a base tree...
M	pkg/controller/admissionchecks/multikueue/externalframeworks/adapter.go
M	test/integration/multikueue/external_job_test.go
Falling back to patching base and 3-way merge...
Auto-merging pkg/controller/admissionchecks/multikueue/externalframeworks/adapter.go
Auto-merging test/integration/multikueue/external_job_test.go
CONFLICT (content): Merge conflict in test/integration/multikueue/external_job_test.go
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 Sanitize remote metadata for MultiKueue external-framework jobs

Details

In response to this:

/lgtm
/approve
/cherrypick release-0.18
/cherrypick release-0.17
Thank you for hardening of Kueue 👍

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.

@apullo777

Copy link
Copy Markdown
Member Author

Let me do the cherry-pick for 0.17 :)

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

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. area/multikueue Issues or PRs related to MultiKueue cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

6 participants