Skip to content

Commit 3eed035

Browse files
authored
re-include executor/driver cores in spark-config (#302)
* re-include executor/driver cores in spark-config * updated changelog * add executor/cores check by inspecting env-vars * adapted docs * check env vars with jsonpath * replace jq usage with yq * revert jq usage for testing * wip: test jq with single test * re-include tests * re-include tests II
1 parent a6efaa5 commit 3eed035

File tree

7 files changed

+20
-5
lines changed

7 files changed

+20
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ All notable changes to this project will be documented in this file.
2525
### Fixed
2626

2727
- Dynamic loading of Maven packages ([#281]).
28+
- Re-instated driver/executor cores setting ([#302]).
2829

2930
### Removed
3031

@@ -41,6 +42,7 @@ All notable changes to this project will be documented in this file.
4142
[#288]: https://github.com/stackabletech/spark-k8s-operator/pull/288
4243
[#291]: https://github.com/stackabletech/spark-k8s-operator/pull/291
4344
[#297]: https://github.com/stackabletech/spark-k8s-operator/pull/297
45+
[#302]: https://github.com/stackabletech/spark-k8s-operator/pull/302
4446

4547
## [23.7.0] - 2023-07-14
4648

docs/modules/spark-k8s/pages/usage-guide/resources.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ CPU request and limit will be rounded up to the next integer value, resulting in
7777
|2
7878
|===
7979

80-
Spark allows CPU limits to be set for the driver and executor using standard Spark settings (`spark.{driver|executor}.cores}`) as well as Kubernetes-specific ones (`spark.kubernetes.{driver,executor}.{request|limit}.cores`). Since `spark.kubernetes.{driver,executor}.request.cores` takes precedence over `spark.{driver|executor}.cores}`, `spark.{driver|executor}.cores}` is not specified by the operator when building the spark-submit configuration.
80+
Spark allows CPU limits to be set for the driver and executor using Spark settings (`spark.{driver|executor}.cores}`) as well as Kubernetes-specific ones (`spark.kubernetes.{driver,executor}.{request|limit}.cores`). `spark.kubernetes.executor.request.cores` takes precedence over `spark.executor.cores` in determining the pod CPU request, but does not affect task parallelism (the number of tasks an executor can run concurrently), so for this reason `spark.executor.cores` is set to the value of `spark.kubernetes.executor.limit.cores`.
8181

8282
=== Memory
8383

rust/crd/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,7 @@ fn resources_to_driver_props(
822822
let min_cores = cores_from_quantity(min.0.clone())?;
823823
let max_cores = cores_from_quantity(max.0.clone())?;
824824
// will have default value from resources to apply if nothing set specifically
825+
props.insert("spark.driver.cores".to_string(), max_cores.clone());
825826
props.insert(
826827
"spark.kubernetes.driver.request.cores".to_string(),
827828
min_cores,
@@ -861,6 +862,7 @@ fn resources_to_executor_props(
861862
let min_cores = cores_from_quantity(min.0.clone())?;
862863
let max_cores = cores_from_quantity(max.0.clone())?;
863864
// will have default value from resources to apply if nothing set specifically
865+
props.insert("spark.executor.cores".to_string(), max_cores.clone());
864866
props.insert(
865867
"spark.kubernetes.executor.request.cores".to_string(),
866868
min_cores,
@@ -1041,6 +1043,7 @@ mod tests {
10411043
resources_to_driver_props(true, &driver_config, &mut props).expect("blubb");
10421044

10431045
let expected: BTreeMap<String, String> = vec![
1046+
("spark.driver.cores".to_string(), "1".to_string()),
10441047
("spark.driver.memory".to_string(), "128m".to_string()),
10451048
(
10461049
"spark.kubernetes.driver.limit.cores".to_string(),
@@ -1084,6 +1087,7 @@ mod tests {
10841087
resources_to_executor_props(true, &executor_config, &mut props).expect("blubb");
10851088

10861089
let expected: BTreeMap<String, String> = vec![
1090+
("spark.executor.cores".to_string(), "2".to_string()),
10871091
("spark.executor.memory".to_string(), "128m".to_string()), // 128 and not 512 because memory overhead is subtracted
10881092
(
10891093
"spark.kubernetes.executor.request.cores".to_string(),

tests/templates/kuttl/resources/10-assert.yaml.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ spec:
5555
resources:
5656
# these resources are set via Spark submit properties like "spark.executor.cores"
5757
limits:
58-
cpu: "1"
58+
cpu: "2"
5959
memory: 1Gi
6060
requests:
61-
cpu: "1"
61+
cpu: "2"
6262
memory: 1Gi

tests/templates/kuttl/resources/10-deploy-spark-app.yaml.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ spec:
5050
enableVectorAgent: {{ lookup('env', 'VECTOR_AGGREGATOR') | length > 0 }}
5151
resources:
5252
cpu:
53-
min: 250m
54-
max: 1000m
53+
min: 1250m
54+
max: 2000m
5555
memory:
5656
limit: 1024Mi

tests/templates/kuttl/resources/12-deploy-spark-app.yaml.j2

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ spec:
2525
spark.kubernetes.executor.podNamePrefix: "resources-sparkconf"
2626
spark.kubernetes.driver.request.cores: "1"
2727
spark.kubernetes.driver.limit.cores: "1"
28+
spark.driver.cores: "1"
2829
spark.driver.memory: "1g"
2930
spark.driver.memoryOverheadFactor: "0.4"
3031
spark.kubernetes.executor.request.cores: "1"
3132
spark.kubernetes.executor.limit.cores: "2"
33+
spark.executor.cores: "2"
3234
spark.executor.memory: "2g"
3335
spark.executor.memoryOverheadFactor: "0.4"
3436
spark.executor.instances: "1"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
apiVersion: kuttl.dev/v1beta1
3+
kind: TestAssert
4+
timeout: 120
5+
commands:
6+
- script: kubectl get pods -n $NAMESPACE resources-crd-exec-1 -o json | jq '.spec.containers[].env[] | select(.name == "SPARK_EXECUTOR_CORES").value' | grep -w "2"
7+
- script: kubectl get pods -n $NAMESPACE resources-sparkconf-exec-1 -o json | jq '.spec.containers[].env[] | select(.name == "SPARK_EXECUTOR_CORES").value' | grep -w "2"

0 commit comments

Comments
 (0)