Skip to content

Commit 6d478e9

Browse files
committed
[SPARK-51075][K8S] Use container resource for HPA
### What changes were proposed in this pull request? This PR aims to use `container resource` for HPA instead of `pod resource`. ### Why are the changes needed? Since K8s 1.30, `Container resource based pod autoscaling` [KEP-1610](https://kep.k8s.io/1610) becomes `Stable`. - https://v1-30.docs.kubernetes.io/blog/2024/03/12/kubernetes-1-30-upcoming-changes/ `container` metrics is more accurate the `pod` metric because Spark Worker pods frequently have more containers for logging and monitoring. ### Does this PR introduce _any_ user-facing change? No, this is not released yet. ### How was this patch tested? Pass the CIs. ### Was this patch authored or co-authored using generative AI tooling? No. Closes apache#156 from dongjoon-hyun/SPARK-51075. Authored-by: Dongjoon Hyun <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]>
1 parent 94f3d8f commit 6d478e9

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

examples/cluster-with-hpa-template.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ spec:
3939
memory: "3Gi"
4040
horizontalPodAutoscalerSpec:
4141
metrics:
42-
- type: Resource
43-
resource:
42+
- type: ContainerResource
43+
containerResource:
4444
name: cpu
45+
container: worker
4546
target:
4647
type: Utilization
4748
averageUtilization: 10

spark-submission-worker/src/main/java/org/apache/spark/k8s/operator/SparkClusterResourceSpec.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,14 +307,15 @@ private static Optional<HorizontalPodAutoscaler> buildHorizontalPodAutoscaler(
307307
new HorizontalPodAutoscalerSpecBuilder()
308308
.addToMetrics(
309309
new MetricSpecBuilder()
310-
.withType("Resource")
311-
.withNewResource()
310+
.withType("ContainerResource")
311+
.withNewContainerResource()
312312
.withName("cpu")
313+
.withContainer("worker")
313314
.withNewTarget()
314315
.withType("Utilization")
315316
.withAverageUtilization(30)
316317
.endTarget()
317-
.endResource()
318+
.endContainerResource()
318319
.build())
319320
.withNewBehavior()
320321
.withNewScaleUp()

spark-submission-worker/src/test/java/org/apache/spark/k8s/operator/SparkClusterResourceSpecTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,5 +304,7 @@ void testHorizontalPodAutoscaler() {
304304
assertEquals("4.0.0", hpa.getMetadata().getLabels().get(LABEL_SPARK_VERSION_NAME));
305305
assertEquals(1, hpa.getSpec().getMinReplicas());
306306
assertEquals(3, hpa.getSpec().getMaxReplicas());
307+
assertEquals(1, hpa.getSpec().getMetrics().size());
308+
assertEquals("worker", hpa.getSpec().getMetrics().get(0).getContainerResource().getContainer());
307309
}
308310
}

0 commit comments

Comments
 (0)