Skip to content

Commit 25eb53d

Browse files
Ocean22pan3793
andcommitted
[KYUUBI #5680] Optimize Spark engine pod name generation
### _Why are the changes needed?_ Close #5680 **Background**: 1) In default case, when kyuubi submit spark sql engine on kubernetes, will generate spark driver pod name with "kyuubi-${app_name}-${engine_ref_id}-driver". 2) And app_name will be "kyuubi_${shareLevel}_${engineType}_${appUser}_${engineRefId}" if not set by user. 3) In result, we may get spark driver pod name with "kyuubi-kyuubi-${shareLevel}-${engineType}-${appUser}-${engineRefId}-${engineRefId}-driver". 4) We were hoping for a more concise and readable name, such as "kyuubi-${shareLevel}-${engineType}-${appUser}-${app_name}-${engineRefId}-driver". ### _How was this patch tested?_ - [ ] Add some test cases that check the changes thoroughly including negative and positive cases if possible - [ ] Add screenshots for manual tests if appropriate **1) Before modification:** Left is unset `spark.app.name`, and right is set to “ocean” ![image](https://github.com/apache/kyuubi/assets/45907917/350aa09f-a9cb-4cc4-bdc6-71b085ba0824) **2) Modify the code** ![image](https://github.com/apache/kyuubi/assets/45907917/f9cbef91-9e1a-482a-82bb-a78caf669438) **3) Build module and get the jar** ![image](https://github.com/apache/kyuubi/assets/45907917/b2cf7595-dd54-46eb-bb79-354f3301499f) **4) Build a new images** ![image](https://github.com/apache/kyuubi/assets/45907917/c0418f2d-dcde-4845-a568-84e920892359) **5) After modification:** ![image](https://github.com/apache/kyuubi/assets/45907917/5db95d5b-2550-41b7-a11c-d8e4a6c0f09f) - [ ] [Run test](https://kyuubi.readthedocs.io/en/master/contributing/code/testing.html#running-tests) locally before make a pull request ### _Was this patch authored or co-authored using generative AI tooling?_ No Closes #5695 from Ocean22/master. Closes #5680 6dbac57 [Cheng Pan] Update kyuubi-server/src/main/scala/org/apache/kyuubi/util/KubernetesUtils.scala 5ddc9f6 [no 会 English] Update KubernetesUtils.scala b685b60 [no 会 English] Update KubernetesUtils.scala 6a64e17 [no 会 English] Update KubernetesUtils.scala 1335bbd [no 会 English] Update EngineRef.scala f2af955 [no 会 English] Update KubernetesUtils.scala 891f172 [no 会 English] Update KubernetesUtils.scala c20b755 [no 会 English] Update EngineRef.scala 09f3ed1 [no 会 English] Update EngineRef.scala 64bd2c1 [no 会 English] Update EngineRef.scala Lead-authored-by: Ocean22 <1058853680@qq.com> Co-authored-by: no 会 English <45907917+Ocean22@users.noreply.github.com> Co-authored-by: Cheng Pan <pan3793@gmail.com> Signed-off-by: Cheng Pan <chengpan@apache.org>
1 parent 2a39d69 commit 25eb53d

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

kyuubi-server/src/main/scala/org/apache/kyuubi/util/KubernetesUtils.scala

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ object KubernetesUtils extends Logging {
120120
opt2.foreach { _ => require(opt1.isEmpty, errMessage) }
121121
}
122122

123-
private def getResourceNamePrefix(appName: String, engineRefId: String): String = {
124-
s"$appName-$engineRefId"
123+
private def getResourceNamePrefix(appName: String, engineRefId: Option[String]): String = {
124+
engineRefId.map(refId => s"$appName-$refId").getOrElse(appName)
125125
.trim
126126
.toLowerCase(Locale.ROOT)
127127
.replaceAll("[^a-z0-9\\-]", "-")
@@ -134,7 +134,16 @@ object KubernetesUtils extends Logging {
134134
appName: String,
135135
engineRefId: String,
136136
forciblyRewrite: Boolean): String = {
137-
lazy val resolvedResourceName = s"kyuubi-${getResourceNamePrefix(appName, engineRefId)}-driver"
137+
val resourceNamePrefix = if (appName.contains(engineRefId)) {
138+
getResourceNamePrefix(appName, None)
139+
} else {
140+
getResourceNamePrefix(appName, Some(engineRefId))
141+
}
142+
val resolvedResourceName = if (resourceNamePrefix.startsWith("kyuubi-")) {
143+
s"$resourceNamePrefix-driver"
144+
} else {
145+
s"kyuubi-$resourceNamePrefix-driver"
146+
}
138147
if (forciblyRewrite || resolvedResourceName.length > DRIVER_POD_NAME_MAX_LENGTH) {
139148
s"kyuubi-$engineRefId-driver"
140149
} else {
@@ -146,7 +155,16 @@ object KubernetesUtils extends Logging {
146155
appName: String,
147156
engineRefId: String,
148157
forciblyRewrite: Boolean): String = {
149-
val resolvedResourceName = s"kyuubi-${getResourceNamePrefix(appName, engineRefId)}"
158+
val resourceNamePrefix = if (appName.contains(engineRefId)) {
159+
getResourceNamePrefix(appName, None)
160+
} else {
161+
getResourceNamePrefix(appName, Some(engineRefId))
162+
}
163+
val resolvedResourceName = if (resourceNamePrefix.startsWith("kyuubi-")) {
164+
s"$resourceNamePrefix"
165+
} else {
166+
s"kyuubi-$resourceNamePrefix"
167+
}
150168
if (forciblyRewrite || resolvedResourceName.length > EXECUTOR_POD_NAME_PREFIX_MAX_LENGTH) {
151169
s"kyuubi-$engineRefId"
152170
} else {

0 commit comments

Comments
 (0)