Pradeep39 opened a new pull request, #995:
URL: https://github.com/apache/spark-kubernetes-operator/pull/995
### What changes were proposed in this pull request?
The operator now records the executors of the current attempt in
`SparkApplication` status:
| Field | Recorded for | Meaning |
|---|---|---|
| `activeExecutors` | every application | executor pods that are pending
(including scheduling-gated) or running (including being deleted) |
| `readyExecutors` | every application | executor pods that are running and
`Ready`, and not being deleted |
| `maxExecutorId` | applications with Dynamic Allocation | highest executor
ID so far; Spark never reuses executor IDs, so it never decreases within an
attempt |
| `executorState` | applications with Dynamic Allocation, opt-in | executor
pod name → `PENDING`, `RUNNING`, `COMPLETED`, `FAILED` or `UNKNOWN` |
- **How:** a new `AppExecutorStateStep` reads the attempt's executor pods
(`spark-app-selector` equal to the attempt's `spark.app.id`) from the existing
pod informer cache: no new watch, LIST or GET. The counts are computed from the
pods, not from `executorState`, so they stay exact however many executors an
application has had.
- **Writes:** only when a field changed, with no state transition. An
application without Dynamic Allocation records only the two counts, which for
its fixed executors change mostly when it starts and ends.
- **Deleted executors:** the pod informer's delete filter remembers each
executor pod's last phase (`DeletedExecutorPods`), so an executor removed by
Dynamic Allocation is recorded as `COMPLETED` or `FAILED` rather than `UNKNOWN`.
- **Lifecycle:** the fields are unset until the attempt has an executor pod,
and start over with each attempt and when the application is suspended. The
counts drop to 0 once every executor is gone, while `maxExecutorId` is kept.
- **Properties:**
- `spark.kubernetes.operator.reconciler.executorStateEnabled` (default
`false`, dynamically overridable) also records the `executorState` map. It is
off by default because the counts are enough for most consumers, and every
entry adds to each status write.
- `spark.kubernetes.operator.reconciler.maxTrackedExecutorPerApp` (default
1000) bounds that map, evicting executors that are gone, oldest first.
- `spark.kubernetes.operator.reconciler.executorCountsEnabled` (default
`true`, dynamically overridable) can turn the two counts off, in case their
status writes load the API server and etcd more than a cluster can take.
Turning it off clears the counts recorded before; `maxExecutorId` and
`executorState` are not affected.
- **API and CRD:** an `ExecutorState` enum and four optional
`ApplicationStatus` fields, in the v1 CRD only.
`Utils.isDynamicAllocationEnabled` is the existing check from `AppRunningStep`,
moved so both steps share it.
### Why are the changes needed?
Dynamic Allocation adds and removes executors from the driver without
changing the `SparkApplication` spec, and even with a fixed number of executors
the spec can't tell how many are running or whether they have started. Today
anything that needs the executors of an application, such as users, dashboards,
autoscalers and batch schedulers, has to list and watch its pods and work out
which belong to the current attempt. With this change, the `SparkApplication`
declares them:
- `activeExecutors` is the capacity an application holds now, for example to
size or charge it.
- `readyExecutors` tells whether its executors have started, for example for
a readiness timeout.
- `maxExecutorId` tells how many executors the driver has requested in
total, which distinguishes scale-ups.
- `executorState` follows each executor, when the counts are not enough.
For example, Kueue's support for elastic Spark applications follows executor
counts declared by the operator (kubernetes-sigs/kueue#17127), and these fields
would let it support this operator's applications.
### Does this PR introduce _any_ user-facing change?
Yes: the four optional status fields and the three properties above. Nothing
changes for an application until it has executor pods, and `executorState` is
recorded only when enabled.
Caveats:
- **Rate limiting:** with the default `maxLoopForPeriod` (5 per
`refreshPeriodSeconds`, 15s), the fields can lag the pods by up to 15s under
churn.
- **Last phase of deleted pods** is held in memory, and lost when the
operator restarts.
- **A `spark.app.id` set in `sparkConf`** is shared by all attempts, so
leftover executors of a previous attempt may be counted.
### How was this patch tested?
- **Unit tests:** `ApplicationStatusTest`, `ExecutorStateTest`,
`ExecutorStateUtilsTest`, `AppExecutorStateStepTest` and
`DeletedExecutorPodsTest` are new, and `SparkAppReconcilerTest` is updated.
They cover the counts and their edge cases (gated, terminating, not ready,
succeeded and other attempts' pods), the count beyond
`maxTrackedExecutorPerApp`, writes only on change, applications without Dynamic
Allocation, both properties, and the final state of deleted executors. Negative
controls fail as expected: dropping the deletion check from `readyExecutors`,
removing the `executorCountsEnabled` switch, or restoring the early return that
skipped applications without Dynamic Allocation. The regenerated v1 CRD and the
generated config docs match the committed ones.
- **e2e:** a new chainsaw group, `tests/e2e/executor-state`, run in the
dynamic-configuration CI mode:
1. an application without Dynamic Allocation records `activeExecutors` and
`readyExecutors` only;
2. a `SparkALS` application with Dynamic Allocation (1 to 3 executors)
scales above its minimum and records `activeExecutors` and `maxExecutorId` but
no `executorState`; at `ResourceReleased`, `activeExecutors` is 0 and
`maxExecutorId` is kept;
3. with `executorStateEnabled=true` through dynamic configuration, the
same application ends with every recorded executor `COMPLETED` or `FAILED`;
4. with the states enabled, on an idle Spark Connect server Dynamic
Allocation removes one of two executors: the removed one is kept, and the
running executor pods match the `RUNNING` states and `activeExecutors`.
Steps 1, 3 and 4 were run by hand on a cluster against an earlier build of
this change, applying each fixture as CI does and checking the same assertions.
Step 2 checks the current defaults and runs only in CI.
- **On a cluster,** with the executor states enabled, `SparkALS` (Spark
4.0.1, Dynamic Allocation 3 to 30) recorded every executor that ran with its
true final state (48 `COMPLETED` and 2 `FAILED` of 59; the 9 `UNKNOWN` were
pods deleted while still scheduling-gated).
<details>
<summary>API server load: measured on a small test cluster</summary>
20 applications with Dynamic Allocation (`SparkALS`, 1 to 3 executors, 4s
idle timeout) submitted at once, about 90 executors per run, single API server.
The operator ran with `maxLoopForPeriod=30` per 15s, so the per-application
ceiling was 2 writes/s instead of the default 0.33; the applications stayed far
below it.
| | States off (default) | States on |
|---|---|---|
| Status writes per application | 14.2 | 19.0 |
| Average / peak writes per second (20 apps) | 0.77 / 2.5 | 0.92 / 3.7 |
| Bytes per write | 6.9 KB | 7.2 KB |
| API server request + watch bytes per second | 5.3 + 13.1 KB/s | 6.6 + 16.3
KB/s |
| Status write p99 latency | 0.75 s | 0.86 s |
- About 1.2 status writes per executor with the states off, and 2.3 with
them on (the extra one is the Pending to Running transition), on top of the ~9
writes an application makes for its own state machine.
- Each `executorState` entry adds 46 to 80 bytes, depending on the pod name,
to every write; a full map at `maxTrackedExecutorPerApp=1000` adds 50 to 85 KB.
- p99 latency stayed within this control plane's idle range (0.61 to 0.96 s
across runs).
</details>
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Opus 5.5
--
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]