turboFei commented on code in PR #6318:
URL: https://github.com/apache/kyuubi/pull/6318#discussion_r1571259641
##########
kyuubi-server/src/main/scala/org/apache/kyuubi/engine/KubernetesApplicationOperation.scala:
##########
@@ -317,22 +328,75 @@ class KubernetesApplicationOperation extends
ApplicationOperation with Logging {
}
}
+ private class SparkEngineSvcEventHandler(kubernetesInfo: KubernetesInfo)
+ extends ResourceEventHandler[Service] {
+
+ override def onAdd(svc: Service): Unit = {
+ if (isSparkEngineSvc(svc)) {
+ updateApplicationUrl(kubernetesInfo, svc)
+ }
+ }
+
+ override def onUpdate(oldSvc: Service, newSvc: Service): Unit = {
+ if (isSparkEngineSvc(newSvc)) {
+ updateApplicationUrl(kubernetesInfo, newSvc)
+ }
+ }
+
+ override def onDelete(svc: Service, deletedFinalStateUnknown: Boolean):
Unit = {
+ // do nothing
+ }
+ }
+
private def isSparkEnginePod(pod: Pod): Boolean = {
val labels = pod.getMetadata.getLabels
labels.containsKey(LABEL_KYUUBI_UNIQUE_KEY) &&
labels.containsKey(SPARK_APP_ID_LABEL)
}
+ private def isSparkEngineSvc(svc: Service): Boolean = {
+ val selectors = svc.getSpec.getSelector
+ selectors.containsKey(LABEL_KYUUBI_UNIQUE_KEY) &&
selectors.containsKey(SPARK_APP_ID_LABEL)
+ }
+
private def updateApplicationState(kubernetesInfo: KubernetesInfo, pod:
Pod): Unit = {
val (appState, appError) =
toApplicationStateAndError(pod, appStateSource, appStateContainer)
debug(s"Driver Informer changes pod: ${pod.getMetadata.getName} to state:
$appState")
- appInfoStore.put(
- pod.getMetadata.getLabels.get(LABEL_KYUUBI_UNIQUE_KEY),
- kubernetesInfo -> ApplicationInfo(
- id = pod.getMetadata.getLabels.get(SPARK_APP_ID_LABEL),
- name = pod.getMetadata.getName,
- state = appState,
- error = appError))
+ val kyuubiUniqueKey =
pod.getMetadata.getLabels.get(LABEL_KYUUBI_UNIQUE_KEY)
+ appInfoStore.synchronized {
+ Option(appInfoStore.get(kyuubiUniqueKey)).map { case (_, appInfo) =>
+ appInfoStore.put(
+ kyuubiUniqueKey,
+ kubernetesInfo -> appInfo.copy(
+ id = pod.getMetadata.getLabels.get(SPARK_APP_ID_LABEL),
+ name = pod.getMetadata.getName,
+ state = appState,
+ error = appError))
+ }.getOrElse {
+ appInfoStore.put(
+ kyuubiUniqueKey,
+ kubernetesInfo -> ApplicationInfo(
+ id = pod.getMetadata.getLabels.get(SPARK_APP_ID_LABEL),
+ name = pod.getMetadata.getName,
+ state = appState,
+ error = appError))
+ }
+ }
+ }
+
+ private def updateApplicationUrl(kubernetesInfo: KubernetesInfo, svc:
Service): Unit = {
+ val appUrl =
+ svc.getSpec.getPorts.asScala.find(_.getName ==
SPARK_UI_PORT_NAME).map(_.getPort).map {
+ uiPort =>
+
s"http://${svc.getMetadata.getName}.${kubernetesInfo.namespace.orNull}.svc:$uiPort"
+ }
+ debug(s"Driver Informer svc: ${svc.getMetadata.getName} app url: $appUrl")
+ val kyuubiUniqueKey = svc.getSpec.getSelector.get(LABEL_KYUUBI_UNIQUE_KEY)
Review Comment:
get unique key from selector
##########
kyuubi-server/src/main/scala/org/apache/kyuubi/engine/KubernetesApplicationOperation.scala:
##########
@@ -317,22 +328,75 @@ class KubernetesApplicationOperation extends
ApplicationOperation with Logging {
}
}
+ private class SparkEngineSvcEventHandler(kubernetesInfo: KubernetesInfo)
+ extends ResourceEventHandler[Service] {
+
+ override def onAdd(svc: Service): Unit = {
+ if (isSparkEngineSvc(svc)) {
+ updateApplicationUrl(kubernetesInfo, svc)
+ }
+ }
+
+ override def onUpdate(oldSvc: Service, newSvc: Service): Unit = {
+ if (isSparkEngineSvc(newSvc)) {
+ updateApplicationUrl(kubernetesInfo, newSvc)
+ }
+ }
+
+ override def onDelete(svc: Service, deletedFinalStateUnknown: Boolean):
Unit = {
+ // do nothing
+ }
+ }
+
private def isSparkEnginePod(pod: Pod): Boolean = {
val labels = pod.getMetadata.getLabels
labels.containsKey(LABEL_KYUUBI_UNIQUE_KEY) &&
labels.containsKey(SPARK_APP_ID_LABEL)
}
+ private def isSparkEngineSvc(svc: Service): Boolean = {
+ val selectors = svc.getSpec.getSelector
+ selectors.containsKey(LABEL_KYUUBI_UNIQUE_KEY) &&
selectors.containsKey(SPARK_APP_ID_LABEL)
Review Comment:
check selectors
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]