Fix/use intstr intorstring
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.coresto use*intstr.IntOrStringinstead of*int32. - Regenerated CRDs so that the OpenAPI schema accepts both integer and string values.
Spark submission logic
- Updated
internal/controller/sparkapplication/submission.goto:- Correctly parse
IntOrStringvalues. - Convert fractional CPU values to integers using ceiling logic before passing them to:
spark.driver.coresspark.executor.cores
- Correctly parse
- This preserves Spark’s requirement that these configuration values must be integers.
Resource quota validation
- Updated
internal/webhook/resourcequota.goto:- Convert both integer and string CPU values to milliCPU.
- Ensure accurate quota validation when fractional CPUs are used.
Defaulting logic
- Updated
api/v1beta2/defaults.goto set default cores usingintstr.FromInt(1)instead ofint32.
Backward compatibility
- Existing SparkApplications that specify integer values for
corescontinue 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.
[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.
Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment