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,13 @@ 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 (
135+ LABEL_SPARK_CLUSTER_NAME ,
136+ "cluster-name" ,
137+ LABEL_SPARK_ROLE_NAME ,
138+ LABEL_SPARK_ROLE_WORKER_VALUE ),
139+ service1 .getSpec ().getSelector ());
132140 }
133141
134142 @ Test
@@ -151,6 +159,13 @@ void testMasterServiceWithTemplate() {
151159 assertEquals ("bar" , service1 .getMetadata ().getLabels ().get ("foo" ));
152160 assertEquals ("4.0.0" , service1 .getMetadata ().getLabels ().get (LABEL_SPARK_VERSION_NAME ));
153161 assertEquals ("foo" , service1 .getSpec ().getExternalName ());
162+ assertEquals (
163+ Map .of (
164+ LABEL_SPARK_CLUSTER_NAME ,
165+ "cluster-name" ,
166+ LABEL_SPARK_ROLE_NAME ,
167+ LABEL_SPARK_ROLE_MASTER_VALUE ),
168+ service1 .getSpec ().getSelector ());
154169 }
155170
156171 @ Test
@@ -172,6 +187,17 @@ void testMasterStatefulSet() {
172187 SparkClusterResourceSpec spec2 = new SparkClusterResourceSpec (cluster , sparkConf );
173188 StatefulSet statefulSet2 = spec2 .getMasterStatefulSet ();
174189 assertEquals ("other-namespace" , statefulSet2 .getMetadata ().getNamespace ());
190+ assertEquals (
191+ "cluster-name" ,
192+ statefulSet2
193+ .getSpec ()
194+ .getTemplate ()
195+ .getMetadata ()
196+ .getLabels ()
197+ .get (LABEL_SPARK_CLUSTER_NAME ));
198+ assertEquals (
199+ LABEL_SPARK_ROLE_MASTER_VALUE ,
200+ statefulSet2 .getSpec ().getTemplate ().getMetadata ().getLabels ().get (LABEL_SPARK_ROLE_NAME ));
175201 }
176202
177203 @ Test
@@ -236,6 +262,17 @@ void testWorkerStatefulSet() {
236262 SparkClusterResourceSpec spec2 = new SparkClusterResourceSpec (cluster , sparkConf );
237263 StatefulSet statefulSet2 = spec2 .getWorkerStatefulSet ();
238264 assertEquals ("other-namespace" , statefulSet2 .getMetadata ().getNamespace ());
265+ assertEquals (
266+ "cluster-name" ,
267+ statefulSet2
268+ .getSpec ()
269+ .getTemplate ()
270+ .getMetadata ()
271+ .getLabels ()
272+ .get (LABEL_SPARK_CLUSTER_NAME ));
273+ assertEquals (
274+ LABEL_SPARK_ROLE_WORKER_VALUE ,
275+ statefulSet2 .getSpec ().getTemplate ().getMetadata ().getLabels ().get (LABEL_SPARK_ROLE_NAME ));
239276 }
240277
241278 @ Test
0 commit comments