fix(sparkconnect): pass server options as individual container arguments #3188
All Vouch review confidence checks passed
Residual risk 0.22 = Change Risk (0.50) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.50 · 607 lines diff across 7 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.384
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #3188"
general
weight: 0.35
tariq-hasan
Purpose of this PR
Fixes #3072.
The Spark Connect server container is built with
container.Command = ["bash", "-c"]andcontainer.Args = []string{strings.Join(args, " ")}. Joining every generated option into one string leaves it to the shell to decide what constitutes a single argument, and exposes user-supplied Spark and Hadoop configuration values to shell interpretation.#3051 addressed the symptom by shell-quoting configuration values. This PR addresses the construction itself, as raised in https://github.com/kubeflow/spark-operator/pull/3051#discussion_r3718206526, and removes the quoting workaround as it is no longer needed.
Proposed changes:
start-connect-server.shfrom a fixed entrypoint prelude that forwards those arguments verbatim through"$@".Change Category
Rationale
The
SparkApplicationcontroller avoids this class of problem withexec.Command(command, args...), and the same shape applies here: build the options as a list, hand each one to the container separately.It cannot be applied literally, because two values can only be resolved inside the pod:
1.
${SPARK_HOME}is set by the image'sENV. The operator cannot read it — unlikeSparkApplication, wherespark-submitruns in the operator process andos.LookupEnv(common.EnvSparkHome)works (internal/controller/sparkapplication/submission.go). Kubelet's$(VAR)expansion only covers pod-spec env, not image env, so removing the shell entirely would mean hardcoding a Spark home path.2.
spark.driver.hostbrackets an IPv6POD_IP, added in #2703. The downward API cannot express that transform.The shell is therefore kept but reduced to a fixed prelude containing no user-supplied data:
Every generated option arrives as a separate
argvelement and is forwarded through"$@", which applies no further expansion to its contents.execkeeps the JVM as a direct child so signal handling is unchanged.No IPv6 behaviour change. The transform from #2703 is preserved exactly — including the no-op case for an already-bracketed address — it has only moved out of the argument list, because the argument list is no longer shell-evaluated.
spark.driver.hostis appended after"$@"so the operator's value continues to take precedence over a user-supplied one, matching the current option ordering.Checklist
Additional Notes
No documentation change is needed:
docs/website/user-guide/spark-connect.mdonly states that the image must contain${SPARK_HOME}/sbin/start-connect-server.sh, which remains true.Validation
All clean. The new spec was confirmed to execute rather than be skipped:
Test coverage
reconciler_test.go— new spec assertingcontainer.Commandis the four-element entrypoint and that configuration values land as individual arguments, with the server script path absent fromcontainer.Args.options_test.go— the adversarial inputs from #3051 are retained unchanged (regex metacharacters, embedded single and double quotes,$HOME,$(...), backticks,;,&,|, embedded newline, empty value). The helper no longer round-trips them throughbash; it asserts the argument slice directly, since a shell no longer sits between the operator and the server script.The entrypoint prelude was also exercised directly against a stub server script for IPv4, bare IPv6, already-bracketed IPv6, and zero arguments, with the configuration values above passed alongside.