← Back to Pull requests

fix(sparkconnect): pass server options as individual container arguments #3188

Closed
unknown closed this pull request without merging on Sep 28, 2026 22:03 UTC
View on GitHub
unknown unknown commented on Sep 23, 2026 00:34 UTC
Author

Purpose of this PR

Fixes #3072.

The Spark Connect server container is built with container.Command = ["bash", "-c"] and container.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:

  • Pass each generated option to the server container as its own argument instead of joining them into a single shell string.

  • Invoke start-connect-server.sh from a fixed entrypoint prelude that forwards those arguments verbatim through "$@".

  • Remove the shell quoting of Spark and Hadoop configuration values introduced in #3051.

  • Update the Spark Connect unit tests to assert the arguments as the container receives them, with no shell round-trip.
  • Change Category

  • Bugfix (non-breaking change which fixes an issue)

  • Feature (non-breaking change which adds functionality)

  • Breaking change (fix or feature that could affect existing functionality)

  • Documentation update
  • Rationale

    The SparkApplication controller avoids this class of problem with exec.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's ENV. The operator cannot read it — unlike SparkApplication, where spark-submit runs in the operator process and os.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.host brackets an IPv6 POD_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:

    host="${POD_IP}"
    case "${host}" in
    \[*) ;;
    *:*) host="[${host}]" ;;
    esac
    exec "${SPARK_HOME}/sbin/start-connect-server.sh" "$@" --conf "spark.driver.host=${host}"
    

    Every generated option arrives as a separate argv element and is forwarded through "$@", which applies no further expansion to its contents. exec keeps 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.host is appended after "$@" so the operator's value continues to take precedence over a user-supplied one, matching the current option ordering.

    Checklist

  • I have conducted a self-review of my own code.

  • I have updated documentation accordingly.

  • I have added tests that prove my changes are effective or that my feature works.

  • Existing unit tests pass locally with my changes.
  • Additional Notes

    No documentation change is needed: docs/website/user-guide/spark-connect.md only states that the image must contain ${SPARK_HOME}/sbin/start-connect-server.sh, which remains true.

    Validation

    gofmt -l internal/
    go build ./...
    go vet ./internal/controller/sparkconnect/...
    go test -race ./internal/controller/sparkconnect/...
    

    All clean. The new spec was confirmed to execute rather than be skipped:

    go test -v ./internal/controller/sparkconnect -ginkgo.focus='separate container argument'
    
    Ran 1 of 23 Specs
    SUCCESS! -- 1 Passed | 0 Failed | 0 Pending | 22 Skipped
    

    Test coverage

  • reconciler_test.go — new spec asserting container.Command is the four-element entrypoint and that configuration values land as individual arguments, with the server script path absent from container.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 through bash; 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.

    Diff: 607 lines (+455 / -152) across 7 files Reviewer: tariq-hasan Review duration: 8489m
    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
    0.50
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 50.1% (MEDIUM) · Higher = larger blast radius
    50.1%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 21.7% · Safe to merge
    21.7%