Skip to content

Commit 2839e3c

Browse files
TQJADEdongjoon-hyun
authored andcommitted
[SPARK-52657] Allow spark.app.id
### What changes were proposed in this pull request? SparkAppDriverConf should use the value stored in effectiveSparkConf rather than pre-computed Id for creation. ### Why are the changes needed? When user set the spark.app.id in sparkConf, operator should honor this value. ### Does this PR introduce _any_ user-facing change? no ### How was this patch tested? unit test ### Was this patch authored or co-authored using generative AI tooling? no Closes apache#271 from TQJADE/appid-bug-fix. Authored-by: Qi Tan <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]>
1 parent c1d8af1 commit 2839e3c

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ protected SparkAppDriverConf buildDriverConf(
126126
effectiveSparkConf.setIfMissing("spark.app.id", appId);
127127
return SparkAppDriverConf.create(
128128
effectiveSparkConf,
129-
appId,
129+
effectiveSparkConf.getAppId(),
130130
primaryResource,
131131
applicationSpec.getMainClass(),
132132
applicationSpec.getDriverArgs().toArray(String[]::new),

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,4 +219,20 @@ void generatedSparkAppIdShouldComplyLengthLimit() {
219219
String appId = SparkAppSubmissionWorker.generateSparkAppId(mockApp);
220220
assertTrue(appId.length() <= DEFAULT_ID_LENGTH_LIMIT);
221221
}
222+
223+
@Test
224+
void checkAppIdWhenUserSpecifiedInSparkConf() {
225+
SparkApplication mockApp = mock(SparkApplication.class);
226+
ApplicationSpec mockSpec = mock(ApplicationSpec.class);
227+
Map<String, String> appProps = new HashMap<>();
228+
appProps.put("spark.app.id", "foo");
229+
ObjectMeta appMeta = new ObjectMetaBuilder().withName("app1").withNamespace("ns1").build();
230+
when(mockSpec.getSparkConf()).thenReturn(appProps);
231+
when(mockApp.getSpec()).thenReturn(mockSpec);
232+
when(mockApp.getMetadata()).thenReturn(appMeta);
233+
234+
SparkAppSubmissionWorker submissionWorker = new SparkAppSubmissionWorker();
235+
SparkAppDriverConf conf = submissionWorker.buildDriverConf(mockApp, Collections.emptyMap());
236+
assertEquals(conf.appId(), "foo");
237+
}
222238
}

0 commit comments

Comments
 (0)