fix(utils): converge datasetControllerOwnerReference with transformer helper #6199
<!-- ccr-overview-v2 -->
Copilot review overview
🟢 Approval recommended
The implementation consistently delegates GVK recovery and includes appropriate regression coverage.
Review effort: Balanced
Findings: None
<details>
<summary><strong>What changed in this PR</strong></summary>
Consolidates Dataset owner-reference GVK recovery through the shared transformer while preserving Dataset-specific fallbacks.
Changes:
TypeMeta values.| File | Description |
| ---- | ----------- |
| pkg/utils/dataset_runtime.go | Uses shared GVK recovery with Dataset fallbacks. |
| pkg/utils/dataset_runtime_test.go | Tests Dataset owner-reference scenarios. |
| pkg/utils/transformer/owner_reference_test.go | Tests partial TypeMeta recovery. |
</details>
---
💡 <a href="/fluid-cloudnative/fluid/new/master?filename=.github/skills/code-review/SKILL.md" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Add a code-review agent skill</a> or configure MCP servers for context-aware, tailored reviews. <a href="https://docs.github.com/copilot/how-tos/use-copilot-agents/request-a-code-review/use-code-review?tool=webui#mcp-servers-and-agent-skills" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Learn more in the docs.</a>
Codecov Report
:x: Patch coverage is
42.85714% with 4 lines in your changes missing coverage. Please review.:white_check_mark: Project coverage is 65.46%. Comparing base (
e0fc4c1) to head (1bad02a).:warning: Report is 5 commits behind head on master.
| Files with missing lines | Patch % | Lines |
|---|---|---|
| pkg/utils/dataset\_runtime.go | 42.85% | 4 Missing :warning: |
<details><summary>Additional details and impacted files</summary>
@@ Coverage Diff @@
## master #6199 +/- ##
==========================================
+ Coverage 65.45% 65.46% +0.01%
==========================================
Files 486 486
Lines 34307 34312 +5
==========================================
+ Hits 22455 22464 +9
+ Misses 10091 10089 -2
+ Partials 1761 1759 -2
</details>
:umbrella: View full report in Codecov by Harness.
:loudspeaker: Have feedback on the report? Share it here.
<details><summary> :rocket: New features to boost your workflow: </summary>
</details>
Hi @cheyang, all checks have passed.Could you please take a look when you get a chance?
This last-resort fallback (kind = datav1alpha1.Datasetkind, apiVersion = datav1alpha1.GroupVersion.String()) is unreachable for this function's only input type: *datav1alpha1.Dataset is registered in the transformer's scheme via utilruntime.Must at package init, and the shared helper's recovery triggers exactly when Kind or Version is empty, so the delegated result never comes back with empty fields here. Two independent sweeps (11 and 9 TypeMeta shapes) confirm the branch never fires. Issue #6140 item 3 asks for this fallback verbatim, so keep it as defense in depth — but a one-line "unreachable by design" comment would stop a future cleanup from removing it as accidental dead code. Related nit: the doc comment and the PR body's "recovery and fallback" phrasing read as if the fallback were exercised; the "empty TypeMeta" test case actually exercises the scheme-recovery path.
No committed test asserts that CreateRuntimeForReferenceDatasetIfNotExist actually persists a well-formed ownerReference (Kind/APIVersion/Controller) on the created or adopted ThinRuntime — the pre-existing test checks only error/termination behavior, and the new tests invoke the unexported wrapper directly. That persisted reference is the property this helper exists for (owner-based watch resolution). A small fake-client assertion on the created ThinRuntime's OwnerReferences would close the gap; note the fake client does not validate ownerReference well-formedness, so compare the exact field values rather than relying on a round-trip.
The convergence's core invariant — the delegated implementation is observably identical to the old one for every TypeMeta shape a real client can produce — is implied by the 5-case table, not asserted. A differential test with the legacy implementation as oracle would guard future refactors of either side; it must pin the one deliberate divergence rather than assert blind equality: a malformed apiVersion ("data.fluid.io/", group set / version empty) is now normalized to the registered data.fluid.io/v1alpha1 instead of being copied through verbatim — an improvement, since the old output failed API-server validation ("version must not be empty"). A permanent byte-copy oracle invites rot, so assert "identical on all reachable shapes, plus pinned normalization on the malformed shape".
Both reviewers independently confirmed the premise from #6140 — on master, datasetControllerOwnerReference still carries its own GVK recovery and never goes through the transformer — and both verified the convergence is behavior-preserving (legacy-oracle differential sweeps across 11+ TypeMeta shapes, an envtest through the real production path with a real API server, and mutation runs proving the tests bite). The only divergence found is an improvement: malformed apiVersion strings like "data.fluid.io/" now normalize to the registered version instead of being copied through verbatim. Two small items worth a follow-up: the last-resort Dataset fallback at dataset_runtime.go:52 is unreachable for this caller (Dataset is always in the scheme), so a one-line "unreachable by design" comment would keep a future cleanup from removing it; and nothing in the committed tests asserts the ownerReference actually persisted on the ThinRuntime created for a reference dataset — a small fake-client assertion comparing exact Kind/APIVersion/Controller values would close that gap. No blockers or majors from either side; the reviewers agreed on every finding. Copilot (advisory) reviewed this head and raised no findings.
[APPROVALNOTIFIER] This PR is NOT APPROVED
This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign trafalgarzzz for approval by writing /assign @trafalgarzzz in a comment. For more information see:The Kubernetes Code Review Process.
The full list of commands accepted by this bot can be found here.
<details open>
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
</details>
<!-- META={"approvers":["trafalgarzzz"]} -->
Good call on both. Just pushed an update:
dataset_runtime.go:52 noting Dataset is already in the scheme and keeping it as a defensive fallback.
TestCreateRuntimeForReferenceDatasetIfNotExist to make sure OwnerReferences (Kind, APIVersion, UID, Controller: true) actually persist on both created and adopted ThinRuntimes.
Let me know if this looks good to you!
<!-- ccr-overview-v2 -->
🟢 Approval recommended
The implementation consistently reuses the shared recovery logic and includes comprehensive regression coverage.
0 open findings
🧠 Review effort: Balanced
This delegation now routes the Dataset owner path through GenerateOwnerReferenceFromObject (pkg/utils/transformer/owner_reference.go:54), which only overwrites (Group, Version) as a pair and only when gvk.Version is empty, so a partial TypeMeta with a version but no group (e.g. APIVersion: "v1alpha1") mints an ownerReference {Kind: "Dataset", APIVersion: "v1alpha1"} — the group is never taken from the scheme, the exact class #6140 proposal 1 targeted. This PR adds regression entries for kind-only / apiVersion-only shapes, but the group-less shape is neither handled nor covered. Both reviewers reproduced the malformed output on the PR head. Rated minor rather than blocking because it is pre-existing on base (the legacy per-field fallback produced the identical output, confirmed by canary tests on both verification branches) and the shape is only constructible from malformed in-memory input — typed clients hand back empty TypeMeta and the API server rejects objects whose own apiVersion doesn't resolve. Suggested follow-up: gate on Kind/Group/Version each being empty and fill all three independently from the scheme lookup (verified compatible with the full existing suite).
The new "dataset with custom APIVersion" test cements pass-through of data.fluid.io/v1beta1 rather than normalization to the scheme's version. That matches the transformer's fill-only-missing-fields contract and is the conservative behavior — an object really can be of that version — but #6140's proposal 1 phrasing ("keeping the scheme lookup as the source of truth for both fields") could be read as wanting normalization. Could you confirm pass-through is the decision, so the test documents intent rather than an accident? Both reviewers independently confirmed the legacy implementation also passed a set apiVersion through verbatim, so this is a clarification, not a defect.
The committed tests pass unchanged when dataset_runtime.go is reverted to the pre-PR implementation (verified independently by both reviewers by running the PR's tests against the base implementation), so a future refactor that quietly drops the delegation and re-introduces a divergent local copy would not trip any committed test. This was already requested in a previous review round as a differential test with the legacy implementation as oracle. One is built and proven on the verification branch (pkg/utils/dataset_runtime_ownerref_verify_test.go: 11 reachable TypeMeta shapes asserted identical, 3 malformed shapes pinned to the normalized output, mutation-checked — removing the recovery fails 8/11 equivalence subtests); it is additive and can be uplifted as-is.
The new table entries cover only-kind-set and only-apiVersion-set (with the full group/version string). The remaining partial shape — an apiVersion carrying a version but no group (APIVersion: "v1alpha1"), where the current recovery leaves the group empty and the reference malformed (see the finding above) — has no entry. Once the group gating is fixed, add entries for it; the verification branch already contains the failing contract test to copy.
The five-case table only covers shapes where pre-PR and post-PR behavior are identical. The one shape whose behavior intentionally changed — a malformed apiVersion with a group but no version (data.fluid.io/), previously copied verbatim into an ownerReference a real API server rejects, now normalized to data.fluid.io/v1alpha1 — has no committed coverage. One more table entry pinning expectedAPIVersion: "data.fluid.io/v1alpha1" for that input would document the deliberate improvement.
Both reviewers independently confirmed the premise and the core safety of this change: issue #6140's per-field recovery and failure logging already landed on master via #6139, and this PR delivers exactly the remainder — delegating datasetControllerOwnerReference to the shared transformer helper plus partial-TypeMeta regression coverage — with the delegation proven behavior-preserving against a verbatim copy of the old implementation (contract tests, an 11-shape differential with a mutation check, and envtest end-to-end against a real API server on both verification branches). What remains is follow-up material, not blockers: the transformer still never recovers the Group when the Version is set, so a group-less apiVersion ("v1alpha1") mints a malformed ownerReference — pre-existing on base, not a regression from this PR, with a compatible one-line fix sketched on the verification branch; the committed tests pin the behavior contract but not the convergence itself (they pass against the old implementation too — an upliftable differential test is built and proven to bite); and the one intentional improvement (malformed data.fluid.io/ now normalized) plus the intent behind stale-version pass-through deserve a pin and a confirmation respectively. On the debated points there was full agreement — every finding was confirmed by both sides, nothing rebutted. Copilot (advisory) raised no findings on this head.
 Quality Gate passed
Issues
 2 New issues
 0 Accepted issues
Measures
 0 Security Hotspots
 0.0% Coverage on New Code
 1.0% Duplication on New Code
<!-- sqra-placement-anchor -->
See analysis details on SonarQube Cloud
Thanks for the thorough verification run!
To answer your question: yes, passing through custom versions like v1beta1 is intentional to stick with the fill-only-missing-fields contract.
Just pushed an update:
TestDatasetControllerOwnerReference for the data.fluid.io/ shape to pin the normalization to data.fluid.io/v1alpha1.
Happy to open a follow-up PR for the group-recovery improvement whenever you're ready.
cheyang
frenemy17
Ⅰ. Describe what this PR does
This PR converges the owner-reference GVK recovery logic between
datasetControllerOwnerReferenceinpkg/utils/dataset_runtime.goand the shared helperGenerateOwnerReferenceFromObjectinpkg/utils/transformer/owner_reference.go, as proposed in #6140:1.
datasetControllerOwnerReferencenow delegates totransformer.GenerateOwnerReferenceFromObjectso that scheme-backed GVK recovery is shared across both code paths, while retaining the well-knownDatasetvalues as a last-resort fallback if scheme lookup is unavailable.2. Added regression test coverage for partial
TypeMetashapes (onlyKindset, and onlyAPIVersionset) forDatasetandAlluxioRuntimeinpkg/utils/transformer/owner_reference_test.go.3. Added unit tests for
datasetControllerOwnerReferenceinpkg/utils/dataset_runtime_test.gocovering complete, empty, kind-only, apiVersion-only, and custom versionTypeMeta.Ⅱ. Does this pull request fix one issue?
fixes #6140
Ⅲ. List the added test cases (unit test/integration test) if any, please explain if no tests are needed.
pkg/utils/dataset_runtime_test.go: AddedTestDatasetControllerOwnerReferenceasserting proper recovery and fallback for complete, empty, kind-only, apiVersion-only, and custom versionTypeMeta.pkg/utils/transformer/owner_reference_test.go: Added table entries toDescribeTable("when the TypeMeta of the object is incomplete")forDatasetandAlluxioRuntimewith partialTypeMeta.Ⅳ. Describe how to verify it
Ⅴ. Special notes for reviews
Follow-up to #6138 and #6139 as requested by @cheyang in #6140.