Skip to content

feat: support physical CPU request and limit in SparkConnect CRD - #3096

Merged
google-oss-prow[bot] merged 44 commits into
kubeflow:masterfrom
DUKartik:feat/sparkconnect-cpu-request-limit
Oct 19, 2026
Merged

google-oss-prow[bot] merged 44 commits into
kubeflow:masterfrom
DUKartik:feat/sparkconnect-cpu-request-limit

Conversation

@DUKartik

Copy link
Copy Markdown
Contributor

Purpose of this PR

This PR adds support for configuring physical Kubernetes CPU requests and limits for SparkConnect through the SparkConnect CRD.

Currently, SparkConnect exposes the cores field, which configures Spark driver/executor cores. However, cores does not provide independent control over the physical Kubernetes CPU request and limit for the corresponding pods.

Proposed changes:

  • Add optional coreRequest and coreLimit fields to SparkPodSpec for SparkConnect server and executor pods.
  • Map coreRequest and coreLimit to the corresponding Spark Kubernetes CPU request/limit configuration for the driver and executors.
  • Add CPU quantity validation and unit tests for CPU configuration generation and validation.
  • Regenerate the CRD, OpenAPI, Swagger, and Python API artifacts.
  • Update the SparkConnect example to demonstrate the new CPU request/limit fields.

Example

executor:
  instances: 2
  cores: 1
  coreRequest: "1000m"
  coreLimit: "1"
  memory: 512m

The new fields are independent of cores:

  • cores → spark.driver.cores / spark.executor.cores
  • coreRequest → physical Kubernetes CPU request
  • coreLimit → physical Kubernetes CPU limit

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

SparkConnect currently does not expose physical Kubernetes CPU request/limit configuration through its CRD.

This change provides independent control over Spark's core configuration and the Kubernetes CPU resources assigned to SparkConnect driver and executor pods, while preserving the existing behavior of the cores field.

The new fields are optional, so existing SparkConnect resources remain backward compatible.

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

The implementation maps the new fields as follows:

  • server.coreRequest → spark.kubernetes.driver.request.cores
  • server.coreLimit → spark.kubernetes.driver.limit.cores
  • executor.coreRequest → spark.kubernetes.executor.request.cores
  • executor.coreLimit → spark.kubernetes.executor.limit.cores

CPU quantity validation follows the repository's existing Kubernetes quantity validation conventions.

Generated API artifacts were regenerated and verified, including the CRD, OpenAPI/Swagger specification, and Python API models.

The SparkConnect example was updated to document usage of coreRequest and coreLimit.

Relevant SparkConnect controller and webhook tests pass locally, go vet passes, CRD drift checks pass, generated artifacts are up to date, and git diff --check passes.

Closes #2957

@google-oss-prow
google-oss-prow Bot requested review from ImpSy and RobuRishabh August 14, 2026 19:03
@github-actions

Copy link
Copy Markdown

🎉 Welcome to the Kubeflow Spark Operator! 🎉

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

Here's what happens next:

Join the community:

Feel free to ask questions in the comments if you need any help or clarification!
Thanks again for contributing to Kubeflow! 🙏

@DUKartik
DUKartik force-pushed the feat/sparkconnect-cpu-request-limit branch from 048a2d8 to d333ed0 Compare August 14, 2026 19:10
@DUKartik

Copy link
Copy Markdown
Contributor Author

Hi @tariq-hasan, I’ve implemented the upstream SparkConnect CRD support for #2957 and opened this PR.

The changes add coreRequest and coreLimit for SparkConnect server/executor CPU resources, while keeping them independent of the existing cores field.

Since you pointed me to the upstream issue, I’d appreciate your review when you have a chance. Thanks!

@tariq-hasan tariq-hasan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @DUKartik! Thank you for raising the PR. I have added some review comments.

Comment thread internal/controller/sparkconnect/options.go Outdated
Comment thread api/v1alpha1/sparkconnect_types.go Outdated
Comment thread api/v1alpha1/sparkconnect_types.go
Comment thread api/v1alpha1/sparkconnect_types.go
Comment thread internal/controller/sparkconnect/options_test.go
Comment thread internal/webhook/sparkconnect_validator.go
Comment thread api/v1alpha1/sparkconnect_types.go
Comment thread examples/sparkconnect/spark-connect.yaml Outdated
@tariq-hasan

Copy link
Copy Markdown
Member

/ok-to-test
/retest

@DUKartik
DUKartik force-pushed the feat/sparkconnect-cpu-request-limit branch from a993c30 to 598aa4a Compare August 24, 2026 05:03
@DUKartik

Copy link
Copy Markdown
Contributor Author

Thanks @tariq-hassan for pointing this out.

I updated the implementation based on your feedback:

  • server.coreRequest and server.coreLimit are now applied directly to the Kubernetes CPU request/limit of the operator-created SparkConnect server pod.
  • Removed the spark.kubernetes.driver.request.cores and spark.kubernetes.driver.limit.cores mappings for the server.
  • Kept executor.coreRequest and executor.coreLimit mapped to spark.kubernetes.executor.request.cores and spark.kubernetes.executor.limit.cores, since the executor pods are created by Spark.
  • Added reconciler tests covering CPU request/limit handling, Cores independence, invalid quantities, and template resources.
  • Regenerated the affected API/CRD/OpenAPI/Python API artifacts.

The focused SparkConnect/webhook tests, go vet, gofmt, and git diff --check all pass locally.

@DUKartik
DUKartik force-pushed the feat/sparkconnect-cpu-request-limit branch from 9cf5780 to 560847e Compare August 29, 2026 07:48
Signed-off-by: Kartik Nath Khatri <masterbro770@gmail.com>
Signed-off-by: Kartik Nath Khatri <masterbro770@gmail.com>
Signed-off-by: Kartik Nath Khatri <masterbro770@gmail.com>
Apply server.coreRequest and server.coreLimit directly to the Kubernetes CPU resources of the operator-created SparkConnect server pod.

Remove the incorrect driver Spark configuration mappings while keeping executor CPU configuration through spark.kubernetes.executor.{request,limit}.cores.

Add reconciler tests covering CPU resources and template behavior.

Signed-off-by: Kartik Nath Khatri <masterbro770@gmail.com>
Signed-off-by: Kartik Nath Khatri <masterbro770@gmail.com>
@DUKartik
DUKartik force-pushed the feat/sparkconnect-cpu-request-limit branch from 560847e to d3f4fdc Compare August 29, 2026 08:09
Signed-off-by: Kartik Nath Khatri <masterbro770@gmail.com>
@DUKartik
DUKartik force-pushed the feat/sparkconnect-cpu-request-limit branch from 245fc2e to 7d19343 Compare August 29, 2026 09:00
Signed-off-by: Kartik Nath Khatri <masterbro770@gmail.com>

@tariq-hasan tariq-hasan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @DUKartik! I have added a few comments.

Comment thread api/v1alpha1/sparkconnect_types.go Outdated
Comment thread api/v1alpha1/sparkconnect_types.go Outdated
Comment thread docs/website/user-guide/working-with-sparkconnect.md Outdated
Comment thread api/v1alpha1/sparkconnect_types.go Outdated
Comment thread test/e2e/sparkconnect_resources_test.go Outdated
Comment thread test/e2e/sparkconnect_resources_test.go Outdated
Comment thread test/e2e/sparkconnect_resources_test.go
Comment thread docs/website/user-guide/working-with-sparkconnect.md Outdated
@vikas-saxena02

Copy link
Copy Markdown
Contributor

@DUKartik are you able to address the review comments on this one

- Use resource.Quantity directly for SparkConnect CPU resources.
- Update CPU validation and controller logic for resource.Quantity.
- Update documentation for CPU resource specifications and pod lifecycle behavior.
- Update unit and e2e tests for the new CPU resource handling.
- Regenerate API artifacts and CRDs.

Signed-off-by: Kartik Nath Khatri <masterbro770@gmail.com>
Signed-off-by: Kartik Nath Khatri <masterbro770@gmail.com>
@vikas-saxena02

Copy link
Copy Markdown
Contributor

/retest

@google-oss-prow google-oss-prow Bot removed the lgtm label Oct 11, 2026
@DUKartik

Copy link
Copy Markdown
Contributor Author

Hi @tariq-hasan,
I noticed the Prow bot removed the LGTM label after I pushed the empty commit to retry CI. Since it didn't change the implementation,
Could you please re-apply /lgtm if the current revision still looks good to you?

Sorry for the extra notification, and thanks again for your guidance!

@tariq-hasan

Copy link
Copy Markdown
Member

/ok-to-test
/retest

1 similar comment
@tariq-hasan

Copy link
Copy Markdown
Member

/ok-to-test
/retest

@tariq-hasan

tariq-hasan commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

If you rebase the PR on master I think it should help trigger the CI. One of the tests is failing currently.

@DUKartik

DUKartik commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks @tariq-hasan! I looked into the CI failure a bit further.
It seems the Minikube setup is hitting GitHub's anonymous API rate limit (403), possibly because inputs.github-token is empty for this workflow. Using secrets.GITHUB_TOKEN might help address this.
Since the branch already appears up to date with master, I'm not sure rebasing would help with this particular failure.
Would you prefer to include this small workflow change here or handle it separately?

Thanks again for your guidance!

image

@vikas-saxena02

vikas-saxena02 commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

@DUKartik this is a known issue best is to execute a /retest ehen you run into this issue it will rerun failed tests. As the developer it always works for me. i am going to try this for you but it m,ay not work so feel free to do it once you are back online

@vikas-saxena02

Copy link
Copy Markdown
Contributor

/retest

@vikas-saxena02

Copy link
Copy Markdown
Contributor

@DUKartik seems like /retest only works from developer himself. can you please do that

@DUKartik

Copy link
Copy Markdown
Contributor Author

/retest

@DUKartik

Copy link
Copy Markdown
Contributor Author

Thanks a lot, @vikas-saxena02, for your help! /retest didn't seem to work for me, but the latest merge commit retriggered CI, and all checks have now passed.
Really appreciate you looking into this!

@DUKartik

Copy link
Copy Markdown
Contributor Author

Thanks @tariq-hasan! The latest merge commit retriggered CI, and all checks have now passed.
I really appreciate your patience and guidance throughout this process.
Could you please re-apply /lgtm if the current revision looks good to you?
Thanks again!

@tariq-hasan

Copy link
Copy Markdown
Member

Thanks for the contribution!
/lgtm

@google-oss-prow google-oss-prow Bot added the lgtm label Oct 13, 2026
@vikas-saxena02

Copy link
Copy Markdown
Contributor

@nabuskey can you please merge it so taht #3112 is unblocked

@DUKartik

Copy link
Copy Markdown
Contributor Author

Hi @nabuskey ,
could you please take a look at this PR when you get a chance? If everything looks good to you, would you mind merging it? Thanks for your time and help!

Comment thread internal/webhook/sparkconnect_validator.go Outdated
Comment thread internal/webhook/sparkconnect_validator.go Outdated
Comment thread internal/webhook/sparkconnect_validator.go Outdated
Comment thread internal/webhook/sparkconnect_validator.go Outdated
Comment thread internal/webhook/sparkconnect_validator.go Outdated
Comment thread internal/webhook/sparkconnect_validator.go Outdated
Comment thread internal/webhook/sparkconnect_validator.go Outdated
Comment thread internal/webhook/sparkconnect_validator.go Outdated
Comment thread internal/webhook/sparkconnect_validator.go Outdated
Comment thread internal/webhook/sparkconnect_validator.go
Signed-off-by: Kartik Nath Khatri <masterbro770@gmail.com>
@google-oss-prow google-oss-prow Bot removed the lgtm label Oct 17, 2026
@DUKartik

Copy link
Copy Markdown
Contributor Author

Hi @nabuskey ,
I've addressed the review comments and updated the validation logic, tests, and documentation. Could you please re-review the latest changes? If everything looks good, I'll create a merge commit from main.
Thanks for the feedback!

@DUKartik
DUKartik requested a review from nabuskey October 17, 2026 11:31

@nabuskey nabuskey left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/approve

Thank you very much!

@google-oss-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: nabuskey

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:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@google-oss-prow
google-oss-prow Bot merged commit 270baba into kubeflow:master Oct 19, 2026
23 checks passed
@DUKartik

Copy link
Copy Markdown
Contributor Author

Hi @Tariq and @nabuskey,
thank you both for your valuable feedback and guidance.
I really appreciate your time and support!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support physical CPU request/limit in the SparkConnect CRD

5 participants