dongjoon-hyun commented on code in PR #59112:
URL: https://github.com/apache/spark/pull/59112#discussion_r4133650258


##########
resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPVCResizePlugin.scala:
##########
@@ -121,23 +121,28 @@ class ExecutorPVCResizeDriverPlugin extends DriverPlugin 
with Logging {
   }
 
   private[k8s] def checkAndResizePVCs(): Unit = {
-    logInfo(s"Latest PVC usage reports: $latestReports")
     val appId = sparkContext.applicationId
 
     sparkContext.schedulerBackend match {
       case b: KubernetesClusterSchedulerBackend =>
         val client = b.kubernetesClient
+        // Skip terminated pods kept by deleteOnTermination=false since their 
reports are stale.
         val pods = client.pods()
           .inNamespace(namespace)
           .withLabel(SPARK_APP_ID_LABEL, appId)
           .withLabel(SPARK_ROLE_LABEL, SPARK_POD_EXECUTOR_ROLE)
+          .withoutLabel(SPARK_EXECUTOR_INACTIVE_LABEL, "true")
           .list()
           .getItems.asScala
 
         val podByExecId = pods.flatMap { p =>
           Option(p.getMetadata.getLabels.get(SPARK_EXECUTOR_ID_LABEL)).map(_ 
-> p)
         }.toMap
 
+        // Drop reports of executors without a pod so that latestReports does 
not grow unbounded.
+        latestReports.keySet().retainAll(podByExecId.keySet.asJava)

Review Comment:
   Thank you for the review, @sarutak. This window doesn't apply to live 
executors. An executor sends its first report only after one full interval 
because the initial delay of its `scheduleAtFixedRate` is `interval` (a 
positive multiple of 5 minutes), so its pod is already in the listing by then. 
Only the reports of executors without an active pod are pruned here, which is 
intended. So, I'd like to keep the code as is.
   



##########
resource-managers/kubernetes/core/src/test/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPVCResizePluginSuite.scala:
##########
@@ -308,6 +309,27 @@ class ExecutorPVCResizePluginSuite
     verify(pvcsWithNamespace, 
never()).withName(org.mockito.ArgumentMatchers.anyString())
   }
 
+  test("SPARK-59839: Reports of executors without a pod are removed") {
+    val plugin = createPlugin()
+    val pod = createPodWithPVC(1, "pvc-1", "/data")
+    when(podList.getItems).thenReturn(Collections.singletonList(pod))
+    plugin.receive(PVCDiskUsageReport("1", 0.5))
+    plugin.receive(PVCDiskUsageReport("2", 0.5)) // No pod for executor 2
+
+    plugin.checkAndResizePVCs()
+
+    assert(plugin.latestReports.keySet() === Collections.singleton("1"))

Review Comment:
   Thank you. I added the pre-prune assertion.
   



-- 
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]

Reply via email to