1919
2020package 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 .* ;
2323import static org .junit .jupiter .api .Assertions .assertEquals ;
2424import static org .junit .jupiter .api .Assertions .assertTrue ;
2525import static org .mockito .Mockito .mock ;
2626import static org .mockito .Mockito .when ;
2727
28+ import java .util .Map ;
2829import java .util .Optional ;
2930
3031import 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 (LABEL_SPARK_CLUSTER_NAME , "cluster-name" , LABEL_SPARK_ROLE_NAME , LABEL_SPARK_ROLE_WORKER_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 (LABEL_SPARK_CLUSTER_NAME , "cluster-name" , LABEL_SPARK_ROLE_NAME , LABEL_SPARK_ROLE_MASTER_VALUE ),
160+ service1 .getSpec ().getSelector ());
154161 }
155162
156163 @ Test
@@ -172,6 +179,9 @@ void testMasterStatefulSet() {
172179 SparkClusterResourceSpec spec2 = new SparkClusterResourceSpec (cluster , sparkConf );
173180 StatefulSet statefulSet2 = spec2 .getMasterStatefulSet ();
174181 assertEquals ("other-namespace" , statefulSet2 .getMetadata ().getNamespace ());
182+ assertEquals ("cluster-name" , statefulSet2 .getSpec ().getTemplate ().getMetadata ().getLabels ().get (LABEL_SPARK_CLUSTER_NAME ));
183+ assertEquals (LABEL_SPARK_ROLE_MASTER_VALUE , statefulSet2 .getSpec ().getTemplate ().getMetadata ().getLabels ().get (LABEL_SPARK_ROLE_NAME ));
184+
175185 }
176186
177187 @ Test
@@ -236,6 +246,8 @@ void testWorkerStatefulSet() {
236246 SparkClusterResourceSpec spec2 = new SparkClusterResourceSpec (cluster , sparkConf );
237247 StatefulSet statefulSet2 = spec2 .getWorkerStatefulSet ();
238248 assertEquals ("other-namespace" , statefulSet2 .getMetadata ().getNamespace ());
249+ assertEquals ("cluster-name" , statefulSet2 .getSpec ().getTemplate ().getMetadata ().getLabels ().get (LABEL_SPARK_CLUSTER_NAME ));
250+ assertEquals (LABEL_SPARK_ROLE_WORKER_VALUE , statefulSet2 .getSpec ().getTemplate ().getMetadata ().getLabels ().get (LABEL_SPARK_ROLE_NAME ));
239251 }
240252
241253 @ Test
0 commit comments