Skip to content

feat(cache): bind a CacheRuntime to a snapshot of its CacheRuntimeClass - #6242

Open
btxu-db wants to merge 9 commits into
fluid-cloudnative:masterfrom
btxu-db:cacheruntime-pin-baseline
Open

btxu-db wants to merge 9 commits into
fluid-cloudnative:masterfrom
btxu-db:cacheruntime-pin-baseline

Conversation

@btxu-db

@btxu-db btxu-db commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Depends on #6177. The diff includes its commits; review only the last four commits (53afbac1, 64b0bd54, 7512a039, 5ac1064b). This branch will be rebased onto master after #6177 merges.

Ⅰ. Describe what this PR does

Editing a CacheRuntimeClass can currently change existing CacheRuntimes on their next reconcile. This PR binds each runtime to an immutable snapshot at its first Setup, so later class edits or deletion leave existing runtimes unchanged.

The snapshot covers the whole class, including component templates, options and data operation definitions, to keep images, configuration and scripts on the same version. It is stored in fluid-runtime-class-snapshot-<runtime>, a ConfigMap owned by the CacheRuntime.

  • Resources use the snapshot template as the baseline, with the per-key runtime overrides from fix(cache): merge CacheRuntime resources onto the CacheRuntimeClass baseline #6177.
  • Runtime reconciliation and data operations use the same snapshot. Data operations wait for it rather than falling back to the live class.
  • Changing runtimeClassName keeps the existing binding and emits a warning. Recreate the CacheRuntime to use a different class version.
  • Invalid snapshots are reported and left untouched. Snapshot creation and cleanup handle informer cache lag and use UID preconditions when deleting a stale snapshot.

Also avoids workload updates caused only by reordered resource claims, and updates the English and Chinese guides for snapshot behavior and Pod updates.

Ⅱ. Does this pull request fix one issue?

Fixes #6213.

Ⅲ. List the added test cases (unit test/integration test) if any, please explain if no tests are needed.

Unit tests cover snapshot creation and ownership, class edits and deletion, invalid snapshots, cache lag, safe cleanup, read-only data operations, and resource claim ordering.

The curvine e2e adds a check that class resource edits do not reach an existing worker, while a runtime replica change still takes effect.

Ⅳ. Describe how to verify it

go test -gcflags=all=-l ./pkg/ddc/cache/... ./pkg/common/...

On a cluster, create a CacheRuntime, edit its class resources, and trigger a reconcile. The worker resources should stay unchanged. Updating the CacheRuntime's own resource overrides should still apply.

Ⅴ. Special notes for reviews

CacheRuntime has not been released; migration from earlier development builds is not included. Unlike the original #6213 sketch, this snapshots the whole class, following #6239.

The curvine e2e was syntax-checked locally, but was not run on kind.

@btxu-db btxu-db closed this Nov 12, 2026
@codecov

codecov Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.60969% with 47 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.45%. Comparing base (253f6bb) to head (b643151).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
pkg/ddc/cache/engine/runtime_class_snapshot.go 88.00% 13 Missing and 5 partials ⚠️
pkg/ddc/cache/engine/setup.go 83.09% 8 Missing and 4 partials ⚠️
pkg/ddc/cache/engine/sync.go 85.29% 8 Missing and 2 partials ⚠️
cmd/cache/app/cache.go 0.00% 5 Missing ⚠️
pkg/common/cacheruntime.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6242      +/-   ##
==========================================
+ Coverage   66.13%   66.45%   +0.31%     
==========================================
  Files         486      488       +2     
  Lines       34616    34905     +289     
==========================================
+ Hits        22894    23195     +301     
+ Misses       9964     9943      -21     
- Partials     1758     1767       +9     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@btxu-db btxu-db reopened this Nov 13, 2026
@btxu-db
btxu-db force-pushed the cacheruntime-pin-baseline branch from 1ad2fa4 to 5ac1064 Compare November 13, 2026 05:48
@btxu-db btxu-db changed the title feat(cache): pin the CacheRuntimeClass resources baseline at creation feat(cache): bind a CacheRuntime to a snapshot of its CacheRuntimeClass Nov 13, 2026
@cheyang
cheyang requested a balanced review from Copilot November 13, 2026 21:39

Copilot AI left a comment

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.

🟡 Changes recommended

Snapshot storage can exceed Kubernetes’ 1 MiB ConfigMap limit and fail Setup, while the e2e script can falsely pass after a failed class patch without testing snapshot isolation.

2 open issues
What changed in this PR

This PR binds each CacheRuntime to an immutable snapshot of its CacheRuntimeClass at first Setup, keeping existing runtimes independent of later class edits or deletion. It builds on #6177’s per-key resource overrides.

Changes:

  • Uses the bound snapshot for setup, reconciliation, configuration, and DataLoad, with ownership checks and cache-lag handling.
  • Avoids workload updates caused only by reordered resource claims.
  • Adds snapshot regression coverage and updates English and Chinese guidance on class binding and Pod updates.
File Description
test/​gha-e2e/​curvine/​test.sh Checks resource overrides and isolation from class edits.
test/​gha-e2e/​curvine/​cacheruntimeclass.yaml Supplies baseline worker resources for end-to-end checks.
pkg/​ddc/​cache/​engine/​ufs.go Accepts the bound class for mount updates.
pkg/​ddc/​cache/​engine/​ufs_test.go Adapts mount-update tests to the class parameter.
pkg/​ddc/​cache/​engine/​transform_worker.go Validates merged worker resources.
pkg/​ddc/​cache/​engine/​transform_worker_test.go Covers worker resource conflicts.
pkg/​ddc/​cache/​engine/​transform_master.go Validates merged master resources.
pkg/​ddc/​cache/​engine/​transform_master_test.go Covers master resource conflicts.
pkg/​ddc/​cache/​engine/​transform_common.go Adds shared resource merging and validation.
pkg/​ddc/​cache/​engine/​transform_common_test.go Tests resource resolution, validation, and claims.
pkg/​ddc/​cache/​engine/​transform_client.go Validates merged client resources.
pkg/​ddc/​cache/​engine/​transform_client_test.go Covers client resource conflicts.
pkg/​ddc/​cache/​engine/​sync.go Reuses the snapshot throughout reconciliation.
pkg/​ddc/​cache/​engine/​sync_test.go Extends resource-sync regression coverage.
pkg/​ddc/​cache/​engine/​setup.go Binds the class before creating runtime resources.
pkg/​ddc/​cache/​engine/​runtime_class_snapshot.go Implements snapshot creation, reading, and ownership handling.
pkg/​ddc/​cache/​engine/​runtime_class_snapshot_test.go Tests binding, invalid snapshots, cache lag, and isolation.
pkg/​ddc/​cache/​engine/​resources_equivalence_test.go Checks creation and sync resource consistency.
pkg/​ddc/​cache/​engine/​dataload.go Reads snapshots without creating them or using live classes.
pkg/​ddc/​cache/​engine/​composition_matrix_test.go Updates expectations for per-key resource overrides.
pkg/​ddc/​cache/​engine/​cm.go Generates runtime configuration from the supplied bound class.
pkg/​ddc/​cache/​engine/​cm_test.go Adapts configuration tests to explicit class input.
pkg/​ddc/​cache/​component/​sync_component_spec_test.go Tests order-independent claim comparisons.
pkg/​ddc/​cache/​component/​resources.go Adds semantic resource and unordered claim comparison.
pkg/​ddc/​cache/​component/​advanced_statefulset_manager.go Uses the comparison helper and clarifies update behavior.
pkg/​common/​label.go Defines the snapshot’s class-name annotation.
pkg/​common/​constants.go Adds resource-conflict and snapshot warning reasons.
pkg/​common/​cacheruntime.go Defines snapshot ConfigMap naming.
docs/​zh/​samples/​cacheruntime/​cacheruntime_spec_update.md Documents binding and update behavior in Chinese.
docs/​zh/​dev/​generic_cache_runtime_integration.md Adds Chinese class-version release guidance.
docs/​en/​samples/​cacheruntime/​cacheruntime_spec_update.md Documents binding and update behavior in English.
docs/​en/​dev/​generic_cache_runtime_integration.md Adds English class-version release guidance.

Review effort: Balanced

BlockOwnerDeletion: ptr.To(true),
}},
},
Data: map[string]string{runtimeClassSnapshotKey: string(data)},
Comment thread test/gha-e2e/curvine/test.sh Outdated
Comment on lines +451 to +452
kubectl patch cacheruntimeclass "$class_name" --type json \
-p "[{\"op\":\"replace\",\"path\":\"${class_cpu_path}\",\"value\":\"4\"}]"
cheyang pushed a commit to cheyang/fluid that referenced this pull request Nov 13, 2026

@cheyang cheyang left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Both reviewers independently reproduced issue #6213 on the base — a CacheRuntimeClass edit resizes and rolls every CacheRuntime using it on the next 90s reconcile — and confirmed this head closes it, each with a re-runnable contract harness (verify/cacheruntime-class-snapshot-claude on base ff99142, verify/cacheruntime-class-snapshot-codex on 956d78a; both isolate the same four snapshot commits). The whole-class snapshot design is the right call: every class consumer now reads the bound immutable ConfigMap, the dataset controller only reads, stale-owner replacement is UID-preconditioned (via an interceptor client, since the stock fake client ignores UID preconditions), and the informer-lag, malformed-snapshot, and class-rename edges are all handled and tested. The PR's 15 snapshot specs, the full cache/common suites, and kind e2e across k8s v1.22–v1.33 are green.

No blocking findings. The two reviewers fully converged — every finding was confirmed in cross-critique, and the only corrections were factual refinements to how the 1 MiB ConfigMap limit bites (it is the apiserver's ConfigMap-specific validation vs the CR's ~1.5 MiB etcd bound, not JSON escaping — which actually makes it more reachable — and the error text does surface today, just under a generic reason).

One decision before merge: issue #6213's contract item 4 asks that a resource-merge conflict be reported "with a condition and a RuntimeResourcesConflict Warning event" — this PR, like #6177, ships only the event, and events expire in about an hour. Since the PR says "Fixes #6213", merging auto-closes the issue with that element unimplemented. Please either confirm events-only reporting is acceptable (and amend the issue), or commit to a ResourcesSynced condition follow-up before v1.1.0 — CacheRuntimeStatus.Conditions already exists, so adding it later is cheap.

Next round

[MUST] Maintainer decision on #6213 item 4 (persistent conflict condition vs events-only) — merge is gated on this sign-off, not on code changes
[SHOULD] Record the class resourceVersion/generation in the snapshot annotation, or do the one-time bind read through a non-cached client (F1)
[SHOULD] Pre-Create guard plus a dedicated event for classes whose snapshot exceeds the 1 MiB ConfigMap cap — one guard can also cover the 224-char name edge (F2, F5; agrees with Copilot's size flag)
[SHOULD] Emit RuntimeClassChanged once per spec change instead of every reconcile (F3)
[SHOULD] Check the class patch's exit status in test/gha-e2e/curvine/test.sh so the isolation check can't pass vacuously (F6, from Copilot)
[Filed] none

Reviewer C (Copilot) advisory: its 1 MiB snapshot-size flag is confirmed by the debate (with the mechanism corrected); its curvine e2e errexit flag was validated by both reviewers and is folded in above as a non-blocking item. Reviewer disagreement was limited to factual corrections within F2 — none changed a severity or verdict. Evidence branches: verify/cacheruntime-class-snapshot-claude and verify/cacheruntime-class-snapshot-codex on the reviewer fork.

Non-blocking observations (6) — not part of this round's ask; fix now, follow up, or file an issue as you see fit
  • pkg/ddc/cache/engine/runtime_class_snapshot.go:184 [minor] — one-time bind reads the class through the informer cache; a stale view is pinned forever
    F1: bindRuntimeClass resolves the class with e.getRuntimeClass -> e.Get, i.e. through the controller's informer cache, and the snapshot it writes is immutable (Immutable=true, never rewritten, never re-read while it exists). A class edit that lands inside the cache-propagation window when a runtime is first set up — realistically, the documented remediation itself (class edit + kubectl delete cm to force a rebind, back to back) or GitOps applying class+runtime together — silently pins the pre-edit class forever. The snapshot annotation records only the class name, so the captured version is invisible anywhere. Confirmed by both reviewers (A raised, B confirmed with the full caller chain: neither controller watches the class, so lag is never observed by a reconcile trigger; a first-ever cached Get does a fresh LIST, so the race needs a warm-but-stale informer — consistent with minor). Suggested: do the one-time bind read through a direct (non-cached) client, or record the class's resourceVersion/generation in the snapshot annotation so the mismatch is observable.
  • pkg/ddc/cache/engine/runtime_class_snapshot.go:217 [minor] — no size guard before writing the marshaled class into a ConfigMap (1 MiB cap)
    F2: the whole CacheRuntimeClass is json.Marshal-ed into the single runtimeclass.json ConfigMap data key and Created with no size check. The apiserver's ConfigMap-specific validation rejects total data over 1 MiB, while CRD objects bypass it entirely (bounded only by etcd's ~1.5 MiB max-request-bytes) — so a legally-creatable class in the ~1–1.5 MiB band (long scripts in dataOperationSpecs/executionEntries/extraResources) has its snapshot Create rejected with 'Too long: may not be more than 1048576 bytes', wedging Setup in a 20s requeue loop until the class shrinks. Consensus finding (A raised, B confirmed and strengthened the reachability), agreeing in the core with Copilot C4569021046. Two corrections settled in cross-critique: (1) the mechanism is the stricter ConfigMap validation vs the CR's etcd bound — not JSON-escaping overhead (the snapshot strips ObjectMeta, incl. last-applied-configuration, so it is usually smaller than the stored class); (2) the error does surface today via a generic ErrorProcessRuntimeReason event and a Dataset condition carrying the apiserver's 'Too long' text — what is missing is a dedicated, actionable event and a pre-Create guard. Suggested: check len(data) before Create and emit a RuntimeClassSnapshotInvalid-style event naming the 1 MiB limit and the offending class; the same guard can also close F5's name-length edge.
  • pkg/ddc/cache/engine/sync.go:361 [minor] — #6213 contract item 4 asks for a persistent conflict condition; only the event is implemented
    F4: Issue #6213's user-facing contract item 4 says a resource-merge conflict is reported 'with a condition and a RuntimeResourcesConflict Warning event' (the sketch suggests ResourcesSynced=False 'so the state is still visible after the events expire'). This PR, like #6177 before it, emits only the event (sync.go:361/374, transform_common.go:323); nothing writes a condition on the CacheRuntime — CacheRuntimeStatus.Conditions exists and the engine already calls utils.UpdateRuntimeCondition, so absence is a choice, not an API limitation. Events expire in about an hour, so a conflict that stopped the resources sync hours ago leaves no persistent trace — exactly the gap the condition was meant to close. The behavioral half of item 4 (nothing is synced on an invalid merge) is implemented and tested (sync_test.go:1384-1485). Consensus finding (B raised, A confirmed and independently re-verified the issue text and the grep). Because the PR says 'Fixes #6213', merging auto-closes the issue with that element unimplemented. Maintainer decision needed — this is the only failed DoD item (AC9): accept events-only (and amend the issue), or track the condition as a follow-up before v1.1.0, the first CacheRuntime release. The event-only pattern itself pre-exists in the #6177 stack, but the auto-close scope burden is this PR's claim.
  • pkg/ddc/cache/engine/runtime_class_snapshot.go:159 [nit] — RuntimeClassChanged warning is emitted on every reconcile
    F3: while spec.runtimeClassName disagrees with the bound class, loadRuntimeClassSnapshot records a RuntimeClassChanged Warning on every reconcile — the runtime controller's 90s requeue cadence (defaultRuntimeReconcileDuration), reached before any rate limiting via getBoundRuntimeClass at sync.go:53, and additionally from the dataset controller's read-only path (getBoundRuntimeClassReadOnly, e.g. dataload.go:58), so a runtime with active data operations gets it from two controllers. The recorder aggregates identical events by count so it is benign noise. Consensus (A raised, B confirmed and broadened). Emitting once per spec change (e.g. gated on a status condition) would keep the event stream cleaner. (An earlier suggestion referenced a RuntimeResourcesConflict condition as a model — that condition does not exist either; see F4.)
  • pkg/common/cacheruntime.go:138 [nit] — snapshot ConfigMap prefix narrows the longest usable CacheRuntime name by 8 chars
    F5: GetCacheRuntimeClassSnapshotConfigMapName prefixes 'fluid-runtime-class-snapshot-' (29 chars), tightening the longest usable CacheRuntime name to 224 chars where the pre-existing runtime-config CM prefix ('fluid-runtime-config-', 21 chars) allowed 232 — and the CRD imposes no name-length limit beyond the API server's generic 253, so a 225–232-char name was admissible and functional before. Such a runtime now fails to bind forever: bindRuntimeClass handles only IsAlreadyExists specially, so the invalid-name Create error returns up and Setup/Sync retry unbound. Extreme edge (B raised, A confirmed the arithmetic and the failure mode). A hash suffix or a documented name-length limit would close it; a pre-Create guard shared with F2's size check closes both.
  • test/gha-e2e/curvine/test.sh:452 [nit] — curvine e2e: class kubectl patch runs unchecked and the script has no errexit
    F6 (flagged by Reviewer C / Copilot C4569021108; no debater raised it as a finding, but both independently validated it during cross-critique): the class kubectl patch at test/gha-e2e/curvine/test.sh:451-453 runs unchecked and the script has no errexit, so if the patch fails, the unchanged-resources assertion passes vacuously and the replica-bump positive control does not prove the class edit landed. Valid test-rigor point that does not change either reviewer's verdict (both hold independent unit-level differential proof of the class-edit contract, and the e2e's replica-wait guard ensures a sync actually ran). Check the patch's exit status and panic on failure.
Verified review delta
  • F1: open (initial-pr)
  • F2: open (initial-pr)
  • F4: open (initial-pr)
  • F3: open (initial-pr)
  • F5: open (initial-pr)
  • F6: open (initial-pr)

Code: pending. CI: success; attribution: unknown. Required CI checks still apply.

btxu-db and others added 4 commits November 17, 2026 14:43
Resource claims are keyed by name, so a reordered list from the class
template no longer patches the AdvancedStatefulSet. Requests and limits
are compared semantically as before.

Also correct the SyncComponentSpec comment: the bundled AdvancedStatefulSet
controller updates only the image in place and recreates the Pods for any
other template change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: btxu-db <btxu-db@outlook.com>
The first time a CacheRuntime is set up, the CacheRuntimeClass it names is
copied into an immutable ConfigMap fluid-runtime-class-snapshot-<runtime>
controlled by the runtime. From then on the runtime reads its class only
from that snapshot, so editing or deleting a CacheRuntimeClass affects
only the CacheRuntimes created afterwards.

- Setup and Sync read the bound class once and pass it to every step, so
  a snapshot created moments ago but not yet in the informer cache is
  never read back. On AlreadyExists the existing snapshot is awaited.
- A snapshot controlled by an earlier runtime of the same name is deleted
  with a UID precondition, so a stale cache cannot remove the runtime's
  own snapshot.
- An invalid snapshot is never overwritten (RuntimeClassSnapshotInvalid
  event); changing runtimeClassName keeps the snapshot
  (RuntimeClassChanged event).
- Data operations only read: they never bind, delete or fall back to the
  live class, and retry until the runtime owns its snapshot.

Fixes fluid-cloudnative#6213

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: btxu-db <btxu-db@outlook.com>
Add a CacheRuntimeClass Snapshot section to the en/zh spec update guide,
state that an image change restarts the containers while a resources
change recreates the Pods, and explain how to release a new version of a
RuntimeClass in the integration guide.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: btxu-db <btxu-db@outlook.com>
Edit the class worker limits.cpu, which the CacheRuntime does not
override, together with the worker replicas as a positive control. Once
the new replicas reach the AdvancedStatefulSet, the worker resources must
be unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: btxu-db <btxu-db@outlook.com>
@btxu-db
btxu-db force-pushed the cacheruntime-pin-baseline branch from 5ac1064 to 632ec00 Compare November 17, 2026 05:47
@cheyang
cheyang requested a balanced review from Copilot November 17, 2026 22:54

Copilot AI left a comment

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.

🟡 Changes recommended

The regression test can pass after a failed class patch without exercising a class edit, and the documentation incorrectly states that image-only updates discard emptyDir caches.

4 open issues

Review effort: Balanced

Comment thread test/gha-e2e/curvine/test.sh Outdated
Comment on lines +451 to +452
kubectl patch cacheruntimeclass "$class_name" --type json \
-p "[{\"op\":\"replace\",\"path\":\"${class_cpu_path}\",\"value\":\"4\"}]"
**Key Takeaways**:
1. The current version supports dynamic updates for `runtimeVersion`, `resources` and `replicas`.
2. In cgroupv1 environments, `runtimeVersion` and `resources` must be updated separately (step-by-step); `replicas` is not subject to this limitation.
2. A `runtimeVersion` change restarts the containers and a `resources` change recreates the Pods; either loses the cache held in memory or `emptyDir` volumes.
cheyang pushed a commit to cheyang/fluid that referenced this pull request Nov 18, 2026
…32ec00, advance last-reviewed

Rebase onto master 5e64735 (fluid-cloudnative#6177 merged); range-diff of the 4 PR commits is
identical, no effective code delta on PR-touched paths. Premise re-reproduced on
the new base; C1/C2 contracts pass on the new head; full cache+common unit suite
and 15/15 snapshot specs green. Production code untouched.

@cheyang cheyang left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Round 2 (rebase check): this head 632ec00 is a clean rebase of the fully-verified round-1 head 5ac1064b onto the new base 5e64735 (which now contains #6177 and the sigs.k8s.io/yaml 1.6.0 bump). Both reviewers independently confirmed the four PR commits are bit-identical (git range-diff all =; empty diff over every PR-touched path), and re-ran the whole evidence set on the new refs anyway: the #6213 premise still reproduces on the new base and is closed on this head (both harness differentials), the contract specs — class-edit isolation, delete-to-rebind, data-ops-wait-while-unbound — all pass, and the full ./pkg/ddc/cache/... ./pkg/common/... sweep plus the 15 snapshot specs are green.

Two things changed this round, and neither is a code regression:

  • Required CI is red: staticcheck fails on a duplicate import in pkg/utils/dataset/lifecycle/node_test.go, a file this PR never touches — it arrived in the base via #6244 after the green round-1 CI, and master already fixed it in #6257. A rebase (or a re-run) clears it; no code change needed.
  • One new docs nit (F7): the new Key-Takeaways sentence says an image update loses emptyDir caches, but the AdvancedStatefulSet updates images in place and pod-scoped emptyDir survives a container restart — the doc's own body already says this correctly, so the summary sentence should just mirror it (also flagged by Copilot; mechanism verified against the vendored controller).

Carried unchanged from round 1 (code is byte-identical, so referenced rather than re-posted): F1 stale-informer bind read (minor), F2 missing 1 MiB snapshot-size guard (minor), F3 RuntimeClassChanged every reconcile (nit), F4 #6213 item-4 condition (minor — the maintainer decision below), F5 224-char name edge (nit), F6 unchecked e2e class patch (nit).

Still gating merge: issue #6213's contract item 4 asks that a resource-merge conflict be reported with a persistent condition; this PR, like #6177, ships only the expiring RuntimeResourcesConflict Warning event. Since the PR says "Fixes #6213", merging auto-closes the still-open issue with that element unimplemented — please either confirm events-only reporting is acceptable (and amend the issue), or commit to a ResourcesSynced condition follow-up before v1.1.0 (CacheRuntimeStatus.Conditions already exists, so adding it later is cheap).

Next round

[MUST] Maintainer decision on #6213 item 4 (persistent conflict condition vs events-only) — merge is gated on this sign-off, not on code changes
[MUST] Rebase onto current master (>= 1321a217d) or re-run CI so the required statusCheckRollup is green — the red staticcheck is base-introduced (#6244) and already fixed upstream (#6257); no code change needed
[SHOULD] Record the class resourceVersion/generation in the snapshot annotation, or read the bind through a non-cached client (F1)
[SHOULD] Pre-Create guard plus a dedicated event for classes whose snapshot exceeds the 1 MiB ConfigMap cap — one guard can also cover the 224-char name edge (F2, F5)
[SHOULD] Emit RuntimeClassChanged once per spec change instead of every reconcile (F3)
[SHOULD] Check the class patch's exit status in test/gha-e2e/curvine/test.sh so the isolation check can't pass vacuously (F6)
[SHOULD] Align the Key-Takeaways sentence with the doc body on emptyDir survival for image-only updates, en and zh (F7)
[Filed] none

Reviewer disagreement: none — the two documents converged on every finding; the only differences were bookkeeping (how AC12 records the base-introduced CI red, and an F7 label collision between the two docs, resolved here as F7 docs nit / F8 CI note). Reviewer C (Copilot) advisory: two flags, both confirmed by the debaters — the unchecked e2e class patch (F6) and the emptyDir docs wording (F7); neither gates the verdict.

Evidence branches: verify/cacheruntime-class-snapshot-claude and verify/cacheruntime-class-snapshot-codex on the reviewer fork.

Non-blocking observations (2) — not part of this round's ask; fix now, follow up, or file an issue as you see fit
  • pkg/utils/dataset/lifecycle/node_test.go:36 [minor] — pre-existing, not introduced by this PR — required-CI staticcheck is red at this head, but the defect is base-introduced and already fixed on master
    F8 (new in round 2; NOT a PR defect — both reviewers converged on the attribution independently): at head 632ec00 every CI check passes except staticcheck, which fails with ST1019 'package "sigs.k8s.io/controller-runtime/pkg/client" is being imported more than once' in pkg/utils/dataset/lifecycle/node_test.go:36-37 — a file this PR does not touch. The duplicate import (bare + ctrlclient alias) exists at base 5e64735, introduced by base commit 6f55f84 (#6244) after the previously green round-1 CI; master already fixed it in 1321a21 (#6257, landed 2026-11-17 14:47 +0800 — one hour after the 05:47 UTC failing run). Consequence: the required-CI gate (AC12's CI half) stays red through no fault of this PR until it rebases onto current master (>= 1321a21) or the check is re-run. Recorded so the red rollup is not mistaken for a PR regression. (ID note: both reviewers labeled their new round-2 item 'F7'; the ledger assigns F7 to the docs nit and F8 to this CI item.)
  • docs/en/samples/cacheruntime/cacheruntime_spec_update.md:227 [nit] — docs summary overstates emptyDir loss for image-only updates
    F7 (new in round 2; raised by Copilot on the rebased head and independently verified by both reviewers): the new Key-Takeaways sentence (en line 227; zh twin at docs/zh/samples/cacheruntime/cacheruntime_spec_update.md:225, which says 'both' lose the cache) reads 'A runtimeVersion change restarts the containers and a resources change recreates the Pods; either loses the cache held in memory or emptyDir volumes.' That overstates the image case: the bundled AdvancedStatefulSet computes in-place updates only for image-replace patches (vendored defaultCalculateInPlaceUpdateSpec returns an UpdateSpec only for image patches, nil for everything else — so a resources change recreates the Pod), and pod-scoped emptyDir volumes survive a container restart; only Pod recreation (the resources path) drops them. The doc's own body already says this correctly (the section 1 note and the resources Limitations attribute emptyDir loss to recreation only); the summary sentence should mirror that wording. Whether a restarted worker actually reuses the surviving on-disk cache is engine-specific, so mirror the body wording rather than claiming reuse. (ID note: this ledger's F7 is Reviewer B's F7 / Copilot C4606966944; the CI item both reviewers also called 'F7' is F8 here.)
Verified review delta
  • F8: open (preexisting)
  • F7: open (initial-pr)

Code: pending. CI: failure; attribution: baseline. Required CI checks still apply.

@cheyang cheyang left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Decision on #6213 item 4: the persistent condition is needed in this PR, not as a follow-up. RuntimeResourcesConflict events expire after about an hour, so a runtime whose resources stopped syncing earlier shows no trace today, and since this PR says "Fixes #6213" it should close the whole contract.

ResourcesSynced condition

  • Add a RuntimeConditionType ResourcesSynced and set it on CacheRuntime.status.conditions.
  • Make it follow the event in validDesiredResources: whenever a sync emits RuntimeResourcesConflict for the master or worker, set ResourcesSynced=False with reason RuntimeResourcesConflict and the event's message. Use one condition for the runtime; if both components conflict, name both. This includes the undeclared-claims branch, which emits the same reason today.
  • When a sync of the master and worker emits no conflict, set it to True, so correcting the override clears it.
  • Please also set it from checkComponentResources. A conflict there blocks Setup, and once the event expires only the generic setup error is left.

Two pitfalls

  • UpdateRuntimeCondition gives any type outside isReadyTypeCondition a fresh LastProbeTime/LastTransitionTime on every call. Writing the condition on each reconcile would then change the status every 90s and update it every time. Add ResourcesSynced to isReadyTypeCondition, or keep the timestamps yourself, so an unchanged condition causes no write.
  • Sync updates the runtime status in CheckAndUpdateRuntimeStatus right after syncRuntimeSpec, re-reading the runtime through the cached client. A separate status write inside syncRuntimeSpec would make that update race a stale copy. Prefer returning the result from syncRuntimeSpec and setting the condition in the same write.

Tests and docs

  • Extend the conflict specs in sync_test.go to assert the condition. Add a spec where removing the conflicting override flips it to True, and one where a repeated sync leaves the runtime's resourceVersion unchanged.
  • en/zh cacheruntime_spec_update.md: document the condition next to the event, e.g. kubectl get cacheruntime <name> -o jsonpath='{.status.conditions[?(@.type=="ResourcesSynced")]}'.

Rebase note

Rebasing onto current master is clean and clears staticcheck, but it breaks one spec added by #6264. data_operation_test.go "writes a DataLoad value file built from the runtime class DataOperationSpecs" seeds only the live class and fails with CacheRuntime default/test-runtime is not bound to a CacheRuntimeClass snapshot yet, retrying, because DataLoad now reads only the snapshot. Binding the runtime first fixes it (plus a context import):

c := fake.NewFakeClientWithScheme(CacheEngineTestScheme, runtimeObj, runtimeClass, dataset, dataload)
engine.Client = c
_, err := engine.getBoundRuntimeClass(context.Background(), runtimeObj)
Expect(err).NotTo(HaveOccurred())

With that change, FLUID_UNIT_TEST=true go test -gcflags=all=-l ./pkg/ddc/cache/... ./pkg/common/... passes on the rebased head.

Next round

[MUST] ResourcesSynced condition on the sync path, as above (#6213 item 4)
[MUST] Rebase onto current master and fix the #6264 spec
[SHOULD] Set the condition from checkComponentResources on the creation path too
[SHOULD] F1–F3 and F5–F7 from the last round still stand; F6 and F7 are small enough for the same push

Signed-off-by: btxu-db <btxu-db@outlook.com>
Record setup conflicts in ResourcesSynced and update the condition with
component status during sync. Exercise conflict recovery and class
snapshot isolation in the Curvine end-to-end test.

Signed-off-by: btxu-db <btxu-db@outlook.com>
Signed-off-by: btxu-db <btxu-db@outlook.com>

@cheyang cheyang left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

#6242 independent review: head 36a9ee7c (2026-11-22)

What changed since 2026-11-20 (632ec006 → 36a9ee7c)

  • 636a01ea adds a ResourcesSynced RuntimeConditionType. Sync writes it in the same status update as the component status and skips writes when nothing changed.
  • dbf1b1f7 persists conflicts on both paths. Setup writes False for creation-time conflicts, and Sync records conflicts even when the pass errors.
  • 7c7a6012 merges master (253f6bb8). 36a9ee7c binds the snapshot in the DataLoad values test added by #6264.
  • e2e: a JSON-patch test op plus a read-back now guard the class patch. The condition is asserted on both the creation path and the sync path.
  • CI is fully green at 36a9ee7c: unit, lint, staticcheck, kind e2e ×5 and backward-compat ×5. The PR description has not been updated.

Verdict

The design is right and the implementation is careful. Three small items should be fixed before merge: a stale condition on the Setup path, and two documentation gaps. Everything else is optional.

Should fix before merge

1. ResourcesSynced=False stays stale after a creation-time conflict is fixed (pkg/ddc/cache/engine/setup.go:94, pkg/controllers/runtime_controller.go:271-299, pkg/ddc/cache/engine/sync_test.go:221)

Setup writes False with "X cannot be created", and only Sync clears it. Sync doesn't run until Setup reports ready: runtime_controller.go:283 requeues every 20s until then.

After the user fixes the override, Setup creates the components, but the condition keeps saying they cannot be created for the whole readiness wait. If the Pods stay Pending or crash for an unrelated reason, the wait never ends, and the condition sends users after a cause they already fixed. The PR's own spec at sync_test.go:221 asserts this behavior.

Fix: once transform succeeds in Setup, replace a Setup-originated False with Unknown (reason e.g. WaitingForSync), or with True.

2. The new condition is undocumented

The en/zh cacheruntime_spec_update.md still describe only the Warning event (en line 129). Document:

  • the condition type, its status values and reasons;
  • its scope: master and worker, with the client covered at creation only;
  • how to use it, e.g. kubectl wait --for=condition=ResourcesSynced=True cacheruntime/<name>.

3. The documented rebind adopts the new class only in part (docs en:194, zh:193; event text at runtime_class_snapshot.go:154)

Probe, run in a scratch clone and not pushed:

  1. Bind to class v1.
  2. Edit the class: worker image and args, client image, master options.
  3. Delete the snapshot.
  4. Run Sync.
Changed by the rebind Not changed
worker image → v2 worker args
runtime config regenerated with the v2 options client image (stays v1)

This is the mixed-version state the snapshot exists to prevent. New options and commands reach components still running old images, including the client, which mounts the same runtime config.

The docs and the RuntimeClassSnapshotInvalid event text should present deletion only as recovery from an unreadable snapshot. They should list what moves and what doesn't:

  • Moves: master/worker image and resources, options, executionEntries, dataOperationSpecs.
  • Doesn't move: the client, and every other template field.

They should also recommend recreating the CacheRuntime to adopt a new class version.

Nits / optional

  1. Key Takeaway 2 overstates image updates (en:227, zh:225). The vendored defaultCalculateInPlaceUpdateSpec updates only container images in place (inplace_update_defaults.go:282), so the Pod and its emptyDir survive an image update. Only process memory is lost. The body text is right; make the summary match.
  2. Bind captures one cached read with no version recorded. Bind reads the class once through the informer cache (runtime_class_snapshot.go:184) and records only its name (:203). The snapshot is permanent, so a stale read pins the old version, and nothing shows which version was captured. This can happen when GitOps applies a class edit and a new runtime together. Record the class generation/resourceVersion in an annotation; optionally make this one read uncached.
  3. Per-component state passes through free text. keepWorkerConflict (sync.go:94, :327-328) rebuilds per-component state from the condition message. It is correct today: the validator emits one line per conflict, joined with "; ", and at most one message per component. It is still fragile. Consider reporting only what the current pass observed.
  4. decodeRuntimeClassSnapshot ignores the stored apiVersion/kind (:166-172). A future CacheRuntimeClass version would decode old snapshots silently into the new struct. Check apiVersion/kind when decoding.
  5. Trust model (no action needed now). Anyone who can create ConfigMaps in the namespace can supply the snapshot. IsControlledBy (:97, :126) checks only the controller UID, which the creator sets. A probe showed that a hand-made ConfigMap's image reached the worker AdvancedStatefulSet.
    • This doesn't widen what a CacheRuntime author can already do. spec.volumes (cacheruntime_types.go:177) accepts any volume, and runtimeVersion swaps images. Pod Security Admission applies to the Pods either way.
    • The snapshot is still not an integrity boundary, and a code comment should say so.
    • If CacheRuntime's spec is ever narrowed, use an object tenants can't write. ControllerRevision is one option: the default edit role can only read it.
  6. The PR description is stale. It still says "Depends on #6177 / review only the last four commits (53afbac1, …)" and doesn't mention the condition. It becomes the squash commit message.

Verified OK

  • The whole class is the right unit to snapshot. The class keeps being read after creation:

    • options feed the runtime config, which every Sync regenerates;
    • executionEntries are exec'd in the components;
    • dataOperationSpecs are read for each DataLoad.

    Pinning only resources would leave those paths live.

  • Every class read goes through the snapshot. Nothing outside pkg/ddc/cache/engine reads the class. Teardown doesn't read it, so deleting a class can't block deleting a runtime.

  • An invalid class is never pinned. bindRuntimeClass calls getRuntimeClass, which validates the topology first.

  • RBAC is sufficient.

    • The cache controller has configmaps create and cacheruntimes/finalizers, which blockOwnerDeletion needs.
    • The dataset controller has configmaps get/list/watch and caches ConfigMaps without a filter.
  • ResourcesEqual is correct. Quantities compare semantically, nil equals empty, and claims compare as a name-keyed set with full struct equality.

  • Condition writes are efficient.

    • A sync that changes nothing skips the write.
    • The condition is combined with the component status update.
    • Retries re-read the runtime before writing.
  • Unit tests pass locally at 36a9ee7c:

    KUBECONFIG=/nonexistent FLUID_UNIT_TEST=true go test -mod=vendor -gcflags='all=-N -l' ./pkg/ddc/cache/... ./pkg/common/... ./pkg/utils/... ./api/...
    

Re-assessment of the earlier condition ask

The condition is still worth having, but for a different reason than first given. The conflict event is re-emitted on every Sync while the conflict lasts, so it doesn't simply expire. What the condition adds:

  • persistent, machine-readable state that works with kubectl wait and GitOps health checks;
  • an explicit recovery signal;
  • independence from best-effort event delivery, which deduplicates and rate-limits events per object.

Report creation conflicts only for the runtime generation that Setup validated. Clear resolved conflicts before readiness and recheck the live runtime when status retries are exhausted.

Record the source class revision, validate snapshot metadata, and document recovery and resource sync behavior in English and Chinese.

Signed-off-by: btxu-db <btxu-db@outlook.com>
@sonarqubecloud

Copy link
Copy Markdown

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURES] CacheRuntime: pin the CacheRuntimeClass template at creation; resources = pinned baseline + per-key overrides

3 participants