← Back to Pull requests

feat(spark)!: delegate SparkApplication driver service account to the Spark Operator #776

Merged
adibmbrk merged 5 files (37 lines) on Oct 07, 2026 16:23 UTC
View on GitHub
adibmbrk adibmbrk commented on Aug 30, 2026 02:51 UTC
Author

What this PR does / why we need it:

Removes the hardcoded spark-operator-spark default service account for the SparkApplication driver spec. The Spark Operator now supports a fallback service account mechanism for the driver (kubeflow/spark-operator#3092, merged), so the SDK no longer needs to set this default itself. get_spark_job_driver_spec now leaves service_account unset unless a caller explicitly provides one via Driver.service_account, keeping the SDK decoupled from operator cluster-admin concerns.

Which issue(s) this PR fixes:

Fixes #616

Checklist:

  • Docs included if any changes are user facing
  • Diff: 37 lines (+25 / -12) across 5 files Reviewer: tariq-hasan Review duration: 55532m
    All Vouch review confidence checks passed
    Residual risk 0.02 = Change Risk (0.31) × (1 − Review Confidence (0.93)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.31 · 37 lines diff across 5 files
    0.31
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.94 · 5 substantive comment(s)
    0.94
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    92%
    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.218
    Real PR Conversation Timeline
    32 items
    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Aug 30, 2026 02:51 UTC
    Reviewer

    Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

    github-actions[bot] github-actions[bot] commented on Aug 30, 2026 02:51 UTC
    Bot

    🎉 Welcome to the Kubeflow SDK! 🎉

    Thanks for opening your first PR! We're happy to have you as part of our community 🚀

    Here's what happens next:

  • If you haven't already, please check out our Contributing Guide for repo-specific guidelines and the Kubeflow Contributor Guide for general community standards

  • Our team will review your PR soon! cc @kubeflow/kubeflow-sdk-team
  • Join the community:

  • Slack: Join our #kubeflow-ml-experience and #kubeflow-trainer Slack channels

  • Meetings: Attend the Kubeflow SDK and ML Experience bi-weekly meetings
  • Feel free to ask questions in the comments if you need any help or clarification!
    Thanks again for contributing to Kubeflow! 🙏

    tariq-hasan tariq-hasan commented on Aug 30, 2026 23:28 UTC
    Contributor

    /ok-to-test
    /retest

    tariq-hasan tariq-hasan commented on code on Aug 30, 2026 23:37 UTC
    Code Review
    kubeflow/spark/backends/kubernetes/utils.py:1
    @@ -682,7 +686,7 @@ def get_spark_job_driver_spec(
         return models.SparkV1beta2DriverSpec(
             cores=cores,
             memory=memory,
    -        service_account=constants.DEFAULT_SERVICE_ACCOUNT,
    +        service_account=driver.service_account if driver else None,
         )

    service_account=driver.service_account if driver else None, should be removed.

        )
    

    tariq-hasan tariq-hasan commented on code on Aug 30, 2026 23:38 UTC
    Code Review
    kubeflow/spark/backends/kubernetes/utils_test.py:1
    @@ -1256,15 +1261,16 @@ def test_get_spark_job_driver_spec(test_case: TestCase) -> None:
     
         print("Executing test:", test_case.name)
     
    -    spec = get_spark_job_driver_spec()
    +    driver = test_case.config["driver"]
    +    spec = get_spark_job_driver_spec(driver=driver)
     
         assert test_case.expected_status == SUCCESS
     
         assert spec.cores == constants.DEFAULT_DRIVER_CPU
         assert spec.memory == _memory_kubernetes_to_spark(
             constants.DEFAULT_DRIVER_MEMORY,
         )
    -    assert spec.service_account == constants.DEFAULT_SERVICE_ACCOUNT
    +    assert spec.service_account == (driver.service_account if driver else None)

        assert spec.service_account is None
    

    tariq-hasan tariq-hasan commented on code on Aug 30, 2026 23:39 UTC
    Code Review
    kubeflow/spark/backends/kubernetes/utils_test.py:1
    @@ -1256,15 +1261,16 @@ def test_get_spark_job_driver_spec(test_case: TestCase) -> None:
     
         print("Executing test:", test_case.name)
     
    -    spec = get_spark_job_driver_spec()
    +    driver = test_case.config["driver"]
    +    spec = get_spark_job_driver_spec(driver=driver)

    This change is not necessary.

        spec = get_spark_job_driver_spec()
    

    tariq-hasan tariq-hasan commented on Aug 31, 2026 00:13 UTC
    Contributor

    /retitle feat(spark)!: delegate SparkApplication driver service account to the Spark Operator

    tariq-hasan tariq-hasan commented on code on Aug 31, 2026 00:14 UTC
    Code Review
    examples/spark/README.md:1
    @@ -35,7 +35,7 @@ Install spark dependencies:
     uv pip install kubeflow[spark]
     ```
     
    -The Spark examples run against a Kubernetes cluster with the Spark Operator installed. Batch job submission requires a `spark-operator-spark` ServiceAccount in the target namespace with the required SparkApplication RBAC permissions. See the [Spark SDK docs](https://sdk.kubeflow.org/en/latest/spark/index.html) for prerequisites.
    +The Spark examples run against a Kubernetes cluster with the Spark Operator installed. Batch job submission relies on the Spark Operator's fallback ServiceAccount (`spark-operator-spark` by default with the standard Helm install) having the required SparkApplication RBAC permissions in the target namespace; the SDK does not set a ServiceAccount on the driver spec, so this operator-configured fallback is always used. See the [Spark SDK docs](https://sdk.kubeflow.org/en/latest/spark/index.html) for prerequisites.

    The Spark examples run against a Kubernetes cluster with the Spark Operator installed. The SDK does not set a ServiceAccount on the driver spec, so the Spark Operator must be configured with a fallback ServiceAccount that can create executor pods in the target namespace (`controller.defaultServiceAccount` in the Helm chart). See the [Spark SDK docs](https://sdk.kubeflow.org/en/latest/spark/index.html) for prerequisites.
    

    tariq-hasan tariq-hasan commented on code on Aug 31, 2026 00:17 UTC
    Code Review
    docs/source/spark/index.rst:1
    @@ -52,13 +52,11 @@ using ``num_executors`` and ``resources_per_executor``.
     
     .. note::
     
    -   Batch job submission requires the ``spark-operator-spark`` ServiceAccount to
    -   exist in the target namespace, with the required SparkApplication RBAC
    -   permissions bound to it. Otherwise, ``submit_job()`` requests will fail.
    -
    -   This is a current Spark Operator requirement and is expected to be simplified
    -   once `kubeflow/spark-operator#3049 <https://github.com/kubeflow/spark-operator/issues/3049>`_
    -   is resolved.
    +   Batch job submission relies on the Spark Operator's fallback ServiceAccount
    +   (``spark-operator-spark`` with the standard Helm install) having the
    +   required SparkApplication RBAC permissions in the target namespace.
    +   ``SparkClient`` does not set a ServiceAccount on the driver spec, so this
    +   operator-configured fallback is always used for batch jobs.

       ``SparkClient`` does not set a ServiceAccount on the driver spec. Both
       interactive sessions and batch jobs need the driver to run as a
       ServiceAccount with permission to create executor pods in the target
       namespace. That ServiceAccount is provisioned and selected by the platform,
       not by the SDK.
    
       On a Kubeflow Platform install, the Profile controller creates a
       ``default-editor`` ServiceAccount in every profile namespace and binds it to
       the ``kubeflow-edit`` ClusterRole, which covers pods and services
       in-namespace. Set ``controller.defaultServiceAccount=default-editor`` in the
       Spark Operator Helm chart so the operator falls back to it. On a standalone
       Spark Operator install, set it to a ServiceAccount that exists in every
       namespace where you submit jobs — for example the ``<release>-spark``
       account the chart creates in the namespaces listed under
       ``spark.jobNamespaces``.
    
       When ``controller.defaultServiceAccount`` is unset, the driver runs as the
       namespace's ``default`` ServiceAccount and the job fails with a
       ``403 Forbidden`` error when the driver tries to create executor pods.
    
       Interactive sessions can override the ServiceAccount per session with
       ``Driver(service_account=...)``; batch jobs have no per-job override.
    

    tariq-hasan tariq-hasan commented on code on Aug 31, 2026 00:27 UTC
    Code Review
    kubeflow/spark/backends/kubernetes/utils_test.py:1
    @@ -1245,9 +1245,14 @@ def test_read_pod_logs(test_case: TestCase) -> None:
         "test_case",
         [
             TestCase(
    -            name="default spark job driver spec",
    +            name="default spark job driver spec leaves service account unset",
                 expected_status=SUCCESS,
    -            config={},
    +            config={"driver": None},
    +        ),
    +        TestCase(
    +            name="spark job driver spec honors service account override",
    +            expected_status=SUCCESS,
    +            config={"driver": Driver(service_account="custom-sa")},

    We do not need the second test case.

                config={},
    

    tariq-hasan tariq-hasan commented on code on Aug 31, 2026 00:30 UTC
    Code Review
    kubeflow/spark/backends/kubernetes/utils.py:1
    @@ -670,6 +670,10 @@ def get_spark_job_driver_spec(
     ) -> models.SparkV1beta2DriverSpec:
         """Build DriverSpec for SparkApplication.
     
    +    The service account is intentionally left unset so that the Spark
    +    Operator's fallback service account (configured cluster-wide by the
    +    operator installation) is used unless overridden via `driver`.
    +

        The service account is intentionally left unset so that the Spark
        Operator's configured fallback service account is used.
    
    

    tariq-hasan tariq-hasan commented on Aug 31, 2026 00:35 UTC
    Reviewer

    Hi @adibmbrk! I have added a few comments.

    tariq-hasan tariq-hasan commented on Aug 31, 2026 00:36 UTC
    Contributor

    /assign

    adibmbrk adibmbrk commented on Aug 31, 2026 05:06 UTC
    Author

    /retest

    Goku2099 Goku2099 commented on code on Sep 01, 2026 09:49 UTC
    Code Review
    kubeflow/spark/backends/kubernetes/utils_test.py:1
    @@ -1245,7 +1245,7 @@ def test_read_pod_logs(test_case: TestCase) -> None:
         "test_case",
         [
             TestCase(
    -            name="default spark job driver spec",
    +            name="default spark job driver spec leaves service account unset",

    Looks good for the default case. Can we also add a case that passes Driver(service_account="something") and asserts it comes through untouched?

    Goku2099 Goku2099 commented on Sep 01, 2026 10:02 UTC
    Reviewer

    Thanks for the PR!

    adibmbrk adibmbrk commented on code on Sep 02, 2026 12:36 UTC
    Code Review
    kubeflow/spark/backends/kubernetes/utils_test.py:1
    @@ -1245,7 +1245,7 @@ def test_read_pod_logs(test_case: TestCase) -> None:
         "test_case",
         [
             TestCase(
    -            name="default spark job driver spec",
    +            name="default spark job driver spec leaves service account unset",

    Addressed in a739415

    adibmbrk adibmbrk commented on Sep 04, 2026 05:26 UTC
    Author

    Hi @tariq-hasan @Goku2099! Thank you for the review. I have addressed all your comments. Let me know if further changes are needed.

    tariq-hasan tariq-hasan commented on code on Sep 05, 2026 00:05 UTC
    Code Review
    kubeflow/spark/backends/kubernetes/utils_test.py:1
    @@ -1245,7 +1245,7 @@ def test_read_pod_logs(test_case: TestCase) -> None:
         "test_case",
         [
             TestCase(
    -            name="default spark job driver spec",
    +            name="default spark job driver spec leaves service account unset",

    Actually we can do without this test case. It will bring back the redundant driver.service_account pass-through. Let's remove the last commit.

    adibmbrk adibmbrk commented on code on Sep 05, 2026 05:44 UTC
    Code Review
    kubeflow/spark/backends/kubernetes/utils_test.py:1
    @@ -1245,7 +1245,7 @@ def test_read_pod_logs(test_case: TestCase) -> None:
         "test_case",
         [
             TestCase(
    -            name="default spark job driver spec",
    +            name="default spark job driver spec leaves service account unset",

    Done with 3fa6863

    tariq-hasan tariq-hasan commented on Sep 05, 2026 20:54 UTC
    Contributor

    Thanks!
    /lgtm

    tariq-hasan tariq-hasan commented on Sep 05, 2026 21:01 UTC
    Contributor

    @andreyvelich I am wondering how we should move this PR forward. This change depends on https://github.com/kubeflow/spark-operator/issues/3049 which has been completed recently.

    As there is an upstream dependency that has not been released yet I am thinking if we'd need a release note for the breaking change that would basically only work for the next operator release - v2.6.0.

    andreyvelich andreyvelich commented on code on Sep 09, 2026 23:10 UTC
    Code Review
    kubeflow/spark/backends/kubernetes/utils.py:1
    @@ -670,6 +670,9 @@ def get_spark_job_driver_spec(
     ) -> models.SparkV1beta2DriverSpec:
         """Build DriverSpec for SparkApplication.
     
    +    The service account is intentionally left unset so that the Spark
    +    Operator's configured fallback service account is used.
    +

    I don't think we need it.

    
    

    adibmbrk adibmbrk commented on Sep 11, 2026 18:02 UTC
    Author

    /retest

    adibmbrk adibmbrk commented on Sep 16, 2026 15:44 UTC
    Author

    /retest

    adibmbrk adibmbrk commented on Sep 16, 2026 15:47 UTC
    Author

    Hi @tariq-hasan, the E2E check has failed in this PR, I believe it's a flake, would you be able to trigger the tests once again to confirm.

    tariq-hasan tariq-hasan commented on Oct 03, 2026 04:25 UTC
    Contributor

    /ok-to-test
    /retest

    tariq-hasan tariq-hasan commented on Oct 03, 2026 04:25 UTC
    Contributor

    /retest

    tariq-hasan tariq-hasan commented on Oct 04, 2026 17:16 UTC
    Contributor

    /ok-to-test
    /retest

    andreyvelich andreyvelich commented on Oct 07, 2026 15:34 UTC
    Reviewer

    /lgtm
    /approve

    google-oss-prow[bot] google-oss-prow[bot] commented on Oct 07, 2026 15:34 UTC
    Bot

    [APPROVALNOTIFIER] This PR is APPROVED

    This pull-request has been approved by: <a href="https://github.com/kubeflow/sdk/pull/776#pullrequestreview-5444598294" title="Approved">andreyvelich</a>

    The full list of commands accepted by this bot can be found here.

    The pull request process is described here

    <details >
    Needs approval from an approver in each of these files:

  • ~~OWNERS~~ [andreyvelich]
  • Approvers can indicate their approval by writing /approve in a comment
    Approvers can cancel approval by writing /approve cancel in a comment
    </details>
    <!-- META={"approvers":[]} -->

    Reviewers
    Assignees
    adibmbrk adibmbrk
    Labels
    risk: low confidence: 92.6% 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: 30.6% (LOW) · Higher = larger blast radius
    30.6%
    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: 92.6% · Lower = rushed or shallow review
    92.6%
    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: 2.3% · Safe to merge
    2.3%
    Repository