Skip to content

Commit 8e09403

Browse files
committed
fix comments
1 parent 10965d3 commit 8e09403

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

kyuubi-common/src/main/scala/org/apache/kyuubi/config/KyuubiConf.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,13 +1172,13 @@ object KyuubiConf {
11721172
.createWithDefault(false)
11731173

11741174
val KUBERNETES_INFORMER_PERIOD: ConfigEntry[Long] =
1175-
buildConf("kyuubi.kubernetes.informer.period")
1175+
buildConf("kyuubi.kubernetes.informer.resyncPeriod")
11761176
.doc("Kubernetes Informer poll driver pod period." +
11771177
"Set too small can lead to, stress on Kubernetes Api Server; " +
11781178
"Set too lager can lead to, app info can't updated in time ")
11791179
.version("1.8.0")
11801180
.timeConf
1181-
.checkValue(_ > 0, "must be positive number")
1181+
.checkValue(_ >= 0, "Invalid resync period provided, It should be a non-negative value")
11821182
.createWithDefault(Duration.ofSeconds(10).toMillis)
11831183

11841184
val KUBERNETES_INFORMER_CACHE_PERIOD: ConfigEntry[Long] =

kyuubi-server/src/main/scala/org/apache/kyuubi/engine/KubernetesApplicationOperation.scala

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import io.fabric8.kubernetes.client.informers.SharedIndexInformer
2626

2727
import org.apache.kyuubi.Logging
2828
import org.apache.kyuubi.config.KyuubiConf
29-
import org.apache.kyuubi.engine.ApplicationState.{ApplicationState, FAILED, FINISHED, NOT_FOUND, PENDING, RUNNING, UNKNOWN}
29+
import org.apache.kyuubi.engine.ApplicationState.{isTerminated, ApplicationState, FAILED, FINISHED, NOT_FOUND, PENDING, RUNNING, UNKNOWN}
3030
import org.apache.kyuubi.engine.KubernetesApplicationOperation.{toApplicationState, LABEL_KYUUBI_UNIQUE_KEY, SPARK_APP_ID_LABEL}
3131
import org.apache.kyuubi.util.KubernetesUtils
3232

@@ -36,7 +36,7 @@ class KubernetesApplicationOperation extends ApplicationOperation with Logging {
3636

3737
@volatile
3838
private var kubernetesClient: KubernetesClient = _
39-
private var driverInformer: SharedIndexInformer[Pod] = _
39+
private var enginePodInformer: SharedIndexInformer[Pod] = _
4040
private var submitTimeout: Long = _
4141

4242
private val appInfoStore: ConcurrentHashMap[String, ApplicationInfo] =
@@ -51,10 +51,9 @@ class KubernetesApplicationOperation extends ApplicationOperation with Logging {
5151
submitTimeout = conf.get(KyuubiConf.ENGINE_SUBMIT_TIMEOUT)
5252
// Using Kubernetes Informer to update application state
5353
val informerPeriod = conf.get(KyuubiConf.KUBERNETES_INFORMER_PERIOD)
54-
driverInformer = client.informers().sharedIndexInformerFor(
55-
classOf[Pod],
56-
informerPeriod)
57-
driverInformer.addEventHandler(new SparkEnginePodEventHandler()).start()
54+
enginePodInformer =
55+
client.pods().withLabel(LABEL_KYUUBI_UNIQUE_KEY).runnableInformer(informerPeriod)
56+
enginePodInformer.addEventHandler(new SparkEnginePodEventHandler()).start()
5857
info("Start Kubernetes Client Informer.")
5958
// Using Cache help clean delete app info
6059
val cachePeriod = conf.get(KyuubiConf.KUBERNETES_INFORMER_CACHE_PERIOD)
@@ -139,8 +138,8 @@ class KubernetesApplicationOperation extends ApplicationOperation with Logging {
139138

140139
override def stop(): Unit = {
141140
try {
142-
if (driverInformer != null) {
143-
driverInformer.stop()
141+
if (enginePodInformer != null) {
142+
enginePodInformer.stop()
144143
}
145144
if (kubernetesClient != null) {
146145
kubernetesClient.close()
@@ -158,7 +157,7 @@ class KubernetesApplicationOperation extends ApplicationOperation with Logging {
158157
pod.getMetadata.getLabels.containsKey(LABEL_KYUUBI_UNIQUE_KEY)
159158
}
160159

161-
private def updateState(pod: Pod): Unit = {
160+
private def updateApplicationState(pod: Pod): Unit = {
162161
val metaData = pod.getMetadata
163162
val state = toApplicationState(pod.getStatus.getPhase)
164163
debug(s"Driver Informer change pod: ${metaData.getName} state: $state")
@@ -171,24 +170,24 @@ class KubernetesApplicationOperation extends ApplicationOperation with Logging {
171170
error = Option(pod.getStatus.getReason)))
172171
}
173172

174-
private def markDeleted(pod: Pod): Unit = {
173+
private def markTerminated(pod: Pod): Unit = {
175174
deletedAppInfoCache.put(
176175
pod.getMetadata.getLabels.get(LABEL_KYUUBI_UNIQUE_KEY),
177176
toApplicationState(pod.getStatus.getPhase))
178177
}
179178

180179
override def onAdd(pod: Pod): Unit = {
181180
if (isSparkEnginePod(pod)) {
182-
updateState(pod)
181+
updateApplicationState(pod)
183182
}
184183
}
185184

186185
override def onUpdate(oldPod: Pod, newPod: Pod): Unit = {
187186
if (isSparkEnginePod(newPod)) {
188-
updateState(newPod)
187+
updateApplicationState(newPod)
189188
toApplicationState(newPod.getStatus.getPhase) match {
190-
case FINISHED | FAILED | UNKNOWN =>
191-
markDeleted(newPod)
189+
case state if isTerminated(state) =>
190+
markTerminated(newPod)
192191
case _ =>
193192
// do nothing
194193
}
@@ -197,8 +196,8 @@ class KubernetesApplicationOperation extends ApplicationOperation with Logging {
197196

198197
override def onDelete(pod: Pod, deletedFinalStateUnknown: Boolean): Unit = {
199198
if (isSparkEnginePod(pod)) {
200-
updateState(pod)
201-
markDeleted(pod)
199+
updateApplicationState(pod)
200+
markTerminated(pod)
202201
}
203202
}
204203
}

0 commit comments

Comments
 (0)