Skip to content

Commit 55d85c4

Browse files
fixes issue where multiple sparkclusters in one namespace will lead to wrong worker assignment
1 parent 34ae166 commit 55d85c4

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

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
@@ -21,7 +21,7 @@
2121

2222
import static org.apache.spark.k8s.operator.Constants.*;
2323

24-
import java.util.Collections;
24+
import java.util.Map;
2525
import java.util.Optional;
2626

2727
import scala.Tuple2;
@@ -117,8 +117,9 @@ private static Service buildMasterService(
117117
.endMetadata()
118118
.withNewSpecLike(serviceSpec)
119119
.withClusterIP("None")
120+
.withClusterIP("None")
120121
.withSelector(
121-
Collections.singletonMap(LABEL_SPARK_ROLE_NAME, LABEL_SPARK_ROLE_MASTER_VALUE))
122+
Map.of("app", name + "-master", LABEL_SPARK_ROLE_NAME, LABEL_SPARK_ROLE_MASTER_VALUE))
122123
.addNewPort()
123124
.withName("web")
124125
.withPort(8080)
@@ -150,7 +151,7 @@ private static Service buildWorkerService(
150151
.withNewSpecLike(serviceSpec)
151152
.withClusterIP("None")
152153
.withSelector(
153-
Collections.singletonMap(LABEL_SPARK_ROLE_NAME, LABEL_SPARK_ROLE_WORKER_VALUE))
154+
Map.of("app", name + "-worker", LABEL_SPARK_ROLE_NAME, LABEL_SPARK_ROLE_MASTER_VALUE))
154155
.addNewPort()
155156
.withName("web")
156157
.withPort(8081)

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@
1919

2020
package org.apache.spark.k8s.operator;
2121

22-
import static org.apache.spark.k8s.operator.Constants.LABEL_SPARK_VERSION_NAME;
22+
import static org.apache.spark.k8s.operator.Constants.*;
2323
import static org.junit.jupiter.api.Assertions.assertEquals;
2424
import static org.junit.jupiter.api.Assertions.assertTrue;
2525
import static org.mockito.Mockito.mock;
2626
import static org.mockito.Mockito.when;
2727

28+
import java.util.Map;
2829
import java.util.Optional;
2930

3031
import io.fabric8.kubernetes.api.model.ObjectMeta;
@@ -129,6 +130,9 @@ void testWorkerServiceWithTemplate() {
129130
assertEquals("bar", service1.getMetadata().getLabels().get("foo"));
130131
assertEquals("4.0.0", service1.getMetadata().getLabels().get(LABEL_SPARK_VERSION_NAME));
131132
assertEquals("foo", service1.getSpec().getExternalName());
133+
assertEquals(
134+
Map.of("app", "cluster-name-worker", LABEL_SPARK_ROLE_NAME, LABEL_SPARK_ROLE_MASTER_VALUE),
135+
service1.getSpec().getSelector());
132136
}
133137

134138
@Test
@@ -151,6 +155,9 @@ void testMasterServiceWithTemplate() {
151155
assertEquals("bar", service1.getMetadata().getLabels().get("foo"));
152156
assertEquals("4.0.0", service1.getMetadata().getLabels().get(LABEL_SPARK_VERSION_NAME));
153157
assertEquals("foo", service1.getSpec().getExternalName());
158+
assertEquals(
159+
Map.of("app", "cluster-name-master", LABEL_SPARK_ROLE_NAME, LABEL_SPARK_ROLE_MASTER_VALUE),
160+
service1.getSpec().getSelector());
154161
}
155162

156163
@Test

0 commit comments

Comments
 (0)