fix: avoid nil pointer dereference in CacheRuntime configmap builder #6157
All Vouch review confidence checks passed
Residual risk 0.30 = Change Risk (0.66) × (1 − Review Confidence (0.54)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.66 · 362 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.353
Shallow Review Depth
shallow_review_depth
0.289
Sensitive Paths
sensitive_paths
0.066
Real PR Conversation Timeline
1 comments
"Review active on #6157"
general
weight: 0.35
btxu-db
I. Describe what this PR does
CacheRuntimeClass.Topology and its Master/Worker/Client sub-fields are optional pointers, and the engine dereferences them in several places without a nil check. A class that omits a component — or omits topology altogether — panics the controller, and the Dataset never reaches Bound.
The check now lives in validateRuntimeClassTopology (validate.go), called from getRuntimeClass (runtime.go). That's the only place a CacheRuntimeClass enters the engine, so all five callers are covered: setup.go:39, cm.go:107, sync.go:50, ufs.go:97, dataload.go:56.
Guarding at the loader also picks up the dereferences at dataload.go:97, image.go:29, sync.go:190 and sync.go:214 — the first revision of this PR missed all four, and the DataLoad path still panicked. The two call sites in transform.go stay as they are, since transform_test.go builds a CacheRuntimeClass directly and never goes through the loader.
The fix covers all three components, not just Client as the issue title suggests — Master and Worker have the same unguarded dereference.
The loader also returns an explicit error for a topology that declares no component at all (topology: {}), rather than quietly producing an incomplete config.
II. Does this pull request fix one issue?
fixes #6147
III. List the added test cases
Three regression tests in pkg/ddc/cache/engine/cm_test.go:
TestGenerateRuntimeConfigDataWithMissingComponentTopology — table-driven, one case per component. Each case enables the component under test; otherwise && short-circuits and the guard never runs.
TestGenerateRuntimeConfigDataWithoutAnyComponent — table-driven, covering both topology absent and topology: {} with nothing declared.
TestGenerateDataLoadValueFileWithNilTopology — the DataLoad path, which the first revision didn't cover.
IV. Describe how to verify it
go test ./pkg/ddc/cache/engine/ \
-run 'TestGenerateRuntimeConfigData|TestGenerateDataLoadValueFile' -count=1
Before the fix the DataLoad path panics:
engine.(CacheEngine).genDataLoadValue dataload.go:97
engine.(CacheEngine).generateDataLoadValueFile dataload.go:61
After it, ok.
Every guard was checked by removing it and confirming something turns red (baseline green before each run):
mutation result
drop Master component guard FAIL
drop Worker component guard FAIL
drop Client component guard FAIL
drop the loader guard FAIL (both tests)
drop the topology: {} clause FAIL
One caveat: TestCacheEngine has 12 pre-existing spec failures in ufs_test.go / sync_test.go on master that have nothing to do with this change, so scope runs with -run.
Also reproduced on a kind cluster beforehand — the controller restarted 31 times and the Dataset stayed in NotBound, with the panic stack pointing at the Client dereference in the configmap builder.
V. Special notes for reviews
None.