spark-operator icon indicating copy to clipboard operation
spark-operator copied to clipboard

Fix/use intstr intorstring

Open rahul810050 opened this issue 2 weeks ago • 1 comments

What this PR does

This PR adds full support for using intstr.IntOrString for spec.driver.cores and spec.executor.cores in SparkApplication. This allows users to specify CPU cores as either:

  • Integers (e.g. 1, 2), or
  • Fractional CPU values (e.g. "100m", "0.5")

This enhancement enables fine-grained CPU allocation for Spark driver and executor pods on Kubernetes and aligns the API with native Kubernetes resource semantics.

FIxed issue: #2688.


Why this is needed

Currently, spec.[driver|executor].cores only accepts integers, which prevents users from requesting less than 1 CPU core. In many real-world workloads (especially development, testing, and cost-optimized clusters), fractional CPU requests such as 100m or 0.25 are required.

This PR removes that limitation while preserving backward compatibility.


Summary of changes

API changes

  • Updated SparkPodSpec.cores to use *intstr.IntOrString instead of *int32.
  • Regenerated CRDs so that the OpenAPI schema accepts both integer and string values.

Spark submission logic

  • Updated internal/controller/sparkapplication/submission.go to:
    • Correctly parse IntOrString values.
    • Convert fractional CPU values to integers using ceiling logic before passing them to:
      • spark.driver.cores
      • spark.executor.cores
  • This preserves Spark’s requirement that these configuration values must be integers.

Resource quota validation

  • Updated internal/webhook/resourcequota.go to:
    • Convert both integer and string CPU values to milliCPU.
    • Ensure accurate quota validation when fractional CPUs are used.

Defaulting logic

  • Updated api/v1beta2/defaults.go to set default cores using intstr.FromInt(1) instead of int32.

Backward compatibility

  • Existing SparkApplications that specify integer values for cores continue to work without any changes.
  • No breaking changes to existing users.

Example usage after this change

driver:
  cores: "100m"

executor:
  cores: "0.25"

Behavior:

  • Kubernetes receives a fractional CPU request.
  • Spark receives an integer value (rounded up to 1) as required.

rahul810050 avatar Dec 10 '25 19:12 rahul810050

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Once this PR has been reviewed and has the lgtm label, please assign mwielgus for approval. For more information see the Kubernetes Code Review Process.

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

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[bot] avatar Dec 10 '25 19:12 google-oss-prow[bot]