fix: stop adding SparkApplication owner reference to executor pods #3152
All Vouch review confidence checks passed
Residual risk 0.22 = Change Risk (0.52) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 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.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #3152"
general
weight: 0.35
vara-bonthu
Purpose of this PR
Proposed changes:
TestExecutorPodTemplateContentsandTestSubmitPodTemplatesso executor templates carry only user-supplied owner references; driver templates keep the controller reference to the SparkApplication (TestDriverPodTemplateContentsis unchanged).Problem
Since #2670 every executor pod has two owners: the driver pod (
controller: true, set by Spark itself) and the SparkApplication (controllerunset, added by the operator). Kubernetes garbage collection only deletes a dependent once all of its owners are gone, so deleting the driver pod (manually, or viaspec.suspend=true, e.g. when Kueue preempts the workload) leaves the executor pods behind until the SparkApplication itself is deleted. Across Kueue requeue cycles this accumulates orphaned executor pods.Root cause
internal/controller/sparkapplication/submission.go:1199-1209(buildExecutorPodTemplate) appendsutil.GetOwnerReference(app)withController/BlockOwnerDeletioncleared to the executor pod template. That extra owner is what blocks the cascade deletion from the driver pod. The webhook path (internal/webhook/sparkpod_defaulter.goaddOwnerReference) already returns early for non-driver pods, so submission is the only place that adds it.Fix
Remove the executor ownerReference block in
buildExecutorPodTemplate. Executor pods keep their controller reference to the driver pod, and the driver pod keeps its controller reference to the SparkApplication, so deleting the SparkApplication still cascades to the driver and then to the executors, while deleting only the driver now cascades to the executors as well. This follows the approach suggested in the issue discussion (drop the executor's SparkApplication reference and rely on GC cascade deletion instead of adding operator-managed deletion of executor pods).The original motivation for the extra reference was to let other controllers (e.g. Kueue) recognize executor pods as children of the SparkApplication. Kueue's ownership walk (
FindAncestorJobManagedByKueue) and itsIsOwnerManagedByKueueForObjectcheck both usemetav1.GetControllerOf, i.e. only controller references, and its SparkApplication integration identifies executor pods by thespark-rolelabel and reads readiness fromstatus.executorState, so the non-controller reference is not consumed there.How tested
Unit tests (no cluster required) plus an e2e assertion in the existing suspend/resume test.
Before the fix, with the updated expectations, three subtests fail. Two are shown below; the third,
TestSubmitPodTemplates/sends_default_templates_with_owner_ref_when_not_specified(internal/controller/sparkapplication/rest_submission_test.go:203), fails the same way because the submitted executor template still carries the SparkApplication owner reference (Emptyassertion onOwnerReferences) and is only absent from the output because of the-runfilter. The "pod template already has owner references" case is unchanged and passes both before and after, because user-supplied owner references are preserved as-is.After the fix:
gofmt -l,go vet,go build ./...andgolangci-lint run ./internal/controller/sparkapplication/...are clean.e2e (added on request of the reviewers): the
spark-pi: Suspend and Resumecase intest/e2e/sparkapplication_test.gonow waits for an executor pod to exist before suspending and, once the application reachesSuspended, asserts that no pod labelledsparkoperator.k8s.io/app-name=spark-piremains (driver or executor). Without this fix the executor pod survives the driver deletion because the SparkApplication is still an owner, so the assertion fails; with the fix the executors are cascade-deleted with the driver.gofmt -landgo vet ./...intest/e2eare clean; the CI e2e matrix runs it.Links
Change Category
Rationale
Covered above. Executor pods created by an operator built before this change keep their existing owner references; only newly submitted applications are affected.
Checklist
Additional Notes
This change was prepared with an AI agent operated by KR-Ravindra, who reviewed and tested it.