caican00 opened a new issue, #1000:
URL: https://github.com/apache/spark-kubernetes-operator/issues/1000
## Summary
`KueueWorkloadFactory` builds the `Workload` pod sets of a queued
`SparkApplication`
from `spec.sparkConf` and the pod templates in the spec, so the reserved
quota follows
those values. Spark however lets the application override any of them via
`SparkConf#set`
(or `SparkSession.Builder#config`) in the jar, and the driver creates the
executor pods
from this merged configuration. An application that hard-codes executor
resources
therefore runs with larger requests than its `Workload` reserved: Kueue's
quota
accounting silently diverges from the real usage, the `ClusterQueue`
over-commits, and
workloads admitted afterwards may not find the resources their admission
promised.
The driver pod is unaffected — it is created before the user code runs —
while the
executor pod requests and the executor pod count are.
## Environment
* `spark-kubernetes-operator` 1.1.0 (also on `main`), Kueue integration
enabled with
`spark.kubernetes.operator.kueue.enabled`
* Kueue v0.20.0 or later; a `LocalQueue` / `ClusterQueue` with a finite
`cpu` / `memory`
quota
* A jar whose main class calls
`new SparkConf().set("spark.executor.memory",
"8g").set("spark.executor.cores", "4")`
while the `SparkApplication` spec declares `spark.executor.memory: 1g` and
`spark.executor.cores: 1`
## Symptoms
With a spec like:
```yaml
apiVersion: spark.apache.org/v1
kind: SparkApplication
metadata:
name: code-overrides-resources
labels:
kueue.x-k8s.io/queue-name: spark-queue
spec:
mainClass: "org.example.Main"
jars: "local:///opt/spark/examples/jars/example.jar"
sparkConf:
spark.executor.instances: "2"
spark.executor.memory: "1g"
spark.executor.cores: "1"
runtimeVersions:
sparkVersion: "4.3.0"
```
`kubectl get workload sparkapplication-code-overrides-resources -o yaml`
shows the
executor pod set reserving 2 × (1 core, ~1.1Gi), while
kubectl get pod -l spark-role=executor \
-o jsonpath='{.items[*].spec.containers[0].resources}'
reports 4 cores / 8g+overhead per pod: the `Workload` reserved ~2 cores /
~2Gi for an
application that consumes ~8 cores / ~16Gi. No event, condition or log line
reports the
mismatch.
The same hole exists for the pod count: `spark.executor.instances` or
`spark.dynamicAllocation.*` set in code changes how many executor pods start
while the
executor pod set count was fixed at admission time.
## Root cause
Spark's configuration precedence puts values set programmatically by the
application
above what `spark-submit` (and therefore the operator) passes, so the
effective
configuration of the executor pods is only known when the driver builds them
at
runtime. `KueueWorkloadFactory` faithfully mirrors Spark's resource formulas
(memory +
overhead factors + off-heap + PySpark memory, `request.cores` / `cores`,
`spark.<role>.resource.*`), but its input is only the submitted
configuration:
| Config source | Accounted in the PodSet | Applied to the executor pods |
| --- | --- | --- |
| `spec.sparkConf` | yes | only if the code does not override it |
| Pod template in `spec.driverSpec` / `spec.executorSpec` | yes | merged |
| `SparkConf#set` in the jar | no | wins over both of the above |
| `spark.executor.instances` / `spark.dynamicAllocation.*` in the jar | no |
changes the pod count |
The overriding value cannot be computed from the jar at build time in the
general case:
it may be a constant, computed at runtime, or read from an external system.
Cases the
operator cannot account for at build time are otherwise handled explicitly —
a pod
template file fails with `SchedulingFailure`, and dynamic allocation reserves
`spark.dynamicAllocation.maxExecutors` on opt-in via the
`spark.operator/kueue-reserve-max-executors` annotation (SPARK-60225) — but
resource
configs overridden in application code are neither detected nor documented:
the Kueue
feature support table in `docs/spark_custom_resources.md` does not mention
them.
## Suggested fixes
Any of these would resolve it:
1. Reserve a declared upper bound per executor pod and for the pod count, in
the spirit
of SPARK-60225, and document that resources set in code must stay below
it.
2. Detect the divergence at runtime — the operator observes the executor
pods anyway —
and surface it with a warning event or a condition. The e2e test of
[kueue#15833](https://github.com/kubernetes-sigs/kueue/pull/15833)
compares Workload
PodSet requests against actual Spark pod requests and could be adopted as
a runtime
check.
3. Enforce the reserved values on the executor pods, e.g. clamp or reject
requests above
the reserved amount, so the reserved quota is the quota used.
Whichever is chosen, the limitation should be documented in the Kueue
feature support
table of `docs/spark_custom_resources.md`.
## Related
* [SPARK-60225](https://issues.apache.org/jira/browse/SPARK-60225) — dynamic
allocation
reserves `maxExecutors` on opt-in, the "reserve the worst case" precedent
* [SPARK-60077](https://issues.apache.org/jira/browse/SPARK-60077) —
decouple executor
demand computation from pod creation for external admission
* [kueue#15833](https://github.com/kubernetes-sigs/kueue/pull/15833) — the
Kueue
SparkApplication integration mirrors Spark's resource formulas for the
same reason, but
only for spec fields and sparkConf as resolved by spark-submit
* [kueue#18186](https://github.com/kubernetes-sigs/kueue/issues/18186) — the
same class
of bug one level up (a SparkConf key bypassing the accounted inputs);
there the fix
rejects the bypassing config, which cannot work here since the overriding
value is
unknowable at admission time
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]