strelok89 opened a new pull request, #999:
URL: https://github.com/apache/spark-kubernetes-operator/pull/999
### What changes were proposed in this pull request?
This PR pins each SparkApplication attempt to a single topology zone. It is
off by default.
- **Zone choice** (`AppInitStep`, new `ZonePinningUtils`): before the driver
is requested, the operator chooses a zone for the current attempt.
- The `spark.operator/zone` annotation wins. It must be a valid label
value, or the attempt fails with `SchedulingFailure`.
- Otherwise the operator picks the zone in
`spark.kubernetes.operator.zonePinning.zones` with the fewest active
(non-terminated) applications pinned to it, counted from the primary cache.
Ties are broken by the app uid, so applications submitted together spread out.
- **Stability**: the zone is recorded in
`status.currentAttemptSummary.attemptInfo.zone` (new optional CRD field) before
any resource is created, followed by an immediate requeue and a `ZonePinned`
event. A resource spec built again for the same attempt, for example after a
failed status update, therefore keeps the zone. A restarted or resumed attempt
chooses again.
- **Placement** (`SparkAppResourceSpecFactory`): a pinned attempt gets
`spark.kubernetes.{driver,executor}.node.selector.<topologyKey>=<zone>`. The
topology key defaults to `topology.kubernetes.io/zone` and is set by
`spark.kubernetes.operator.zonePinning.topologyKey`.
- **Zone-dependent Spark conf**:
`spark.kubernetes.operator.zonePinning.sparkConf` takes `key=value` pairs
separated by `;`, with a `{zone}` placeholder. For example,
`spark.celeborn.tags.tagsExpr=az-{zone}` keeps Celeborn shuffle traffic in the
zone. A key the application sets itself is not overridden.
- Applications queued through Kueue
(`spark.kubernetes.operator.kueue.enabled` and a queue name label) are not
pinned, since Kueue owns their placement. SparkCluster is not pinned.
### Why are the changes needed?
On multi-zone clusters (for example AWS EKS across AZs), the driver, the
executors and a remote shuffle service such as Celeborn get spread across
zones. Shuffle and driver-executor traffic then crosses zones, which costs
money and adds latency. The node-selector conf alone can't fix this: the zone
must be chosen per attempt, stay stable while the attempt runs, and be
consistent with the shuffle service's zone-aware conf.
### Does this PR introduce _any_ user-facing change?
Yes, but only when enabled:
- New operator configs
`spark.kubernetes.operator.zonePinning.{zones,topologyKey,sparkConf}`. All are
dynamically overridable and documented in `docs/config_properties.md`.
- A new annotation `spark.operator/zone`.
- A new optional status field `attemptInfo.zone`, added to the CRD and the
Helm chart.
- A new Normal event `ZonePinned`.
- Documentation: a new "Zone Pinning" section in
`docs/spark_custom_resources.md`, plus updates to `docs/architecture.md` and
`docs/configuration.md`.
When neither the zones config nor the annotation is set, the behavior is
unchanged.
### How was this patch tested?
New unit tests:
- `ZonePinningUtilsTest`: annotation precedence and validation, least-loaded
choice, tie-breaking, Kueue exclusion, conf templates, configurable topology
key.
- `ApplicationStatusTest`: pinning keeps state and counters, next attempt is
not pinned, serialization.
- `SparkAppResourceSpecFactoryTest`: a pinned attempt gets the node
selectors.
- `AppInitStepTest`: the zone is pinned before the driver is requested,
pinned again after a failed status update, and a pinned attempt requests the
driver.
`./gradlew build` passes the API tests and all linters (checkstyle, PMD,
SpotBugs). `assertGeneratedCRDMatchesHelmChart` passes.
This is a draft because it has not run on a cluster yet; an e2e test and a
multi-zone cluster run will follow.
Known limitations:
- "Least loaded" counts applications, not their resource requests, and it
counts suspended applications too.
- A pinned attempt waits for capacity in its zone; it does not move to
another zone.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Claude Opus 5.5)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
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]