HwangDongJun commented on code in PR #58187:
URL: https://github.com/apache/spark/pull/58187#discussion_r4608817808


##########
resource-managers/kubernetes/core/src/main/scala/org/apache/spark/deploy/k8s/submit/KubernetesClientApplication.scala:
##########
@@ -135,6 +136,24 @@ private[spark] class Client(
       .build()
     val driverPodName = resolvedDriverPod.getMetadata.getName
 
+    // The API server rejects a pod that has both spec.nodeName and scheduling 
gates, and a pod
+    // with spec.nodeName skips the scheduler anyway, so only pods the 
scheduler places are gated.
+    // The check cannot see a nodeName that an admission webhook sets after 
this point.
+    val gateDriverPod = conf.get(USE_DRIVER_SCHEDULING_GATE) &&
+      Option(resolvedDriverPod.getSpec.getNodeName).forall(_.isEmpty)
+    val podToCreate =
+      if (gateDriverPod) {
+        // A gate of the same name would be rejected as a duplicate, and the 
patch clears it.
+        new PodBuilder(resolvedDriverPod)
+          .editSpec()
+            .removeMatchingFromSchedulingGates(_.getName == 
DRIVER_RESOURCES_SCHEDULING_GATE)
+            .addNewSchedulingGate(DRIVER_RESOURCES_SCHEDULING_GATE)
+            .endSpec()
+          .build()
+      } else {
+        resolvedDriverPod

Review Comment:
   Done as you suggested. `Client.run()` now removes a gate named 
`spark.apache.org/driver-resources` from the resolved pod before it decides 
anything else (`ungatedDriverPod`), and adds it only when `gateDriverPod` is 
true. Other gates on the template are kept.
   
   I reproduced both cases before changing the code, on a v1.34 API server:
   
   - without `nodeName`, a pod created with the Spark gate stayed `Pending` 
with reason `SchedulingGated` and no node for the 100 seconds I watched it;
   - with `nodeName`, the server rejected it with `spec.nodeName: Forbidden: 
cannot be set until all schedulingGates have been cleared`, and a pod with 
`nodeName` alone was accepted.
   
   With the change I ran the compiled `Client.run()` against the same server 
with a template that carries the Spark gate. The default (`false`) and `true` 
with `spec.nodeName` both created the pod without the gate, and `true` without 
`nodeName` removed the gate after submission. A template with only 
`example.com/keep-me` kept that gate and the pod stayed `SchedulingGated`, as 
expected while another tool's gate is still on it.
   
   New tests in `ClientSuite`: `a Spark gate on the template is dropped when 
the gate is off` and `a Spark gate on a template that sets nodeName is 
dropped`. Making the removal conditional on `gateDriverPod` again fails both.
   
   The `schedulingGates` row in `running-on-kubernetes.md` now says that a gate 
of that name in the template is always dropped, whether or not Spark gates the 
pod, and that Spark removes it once the resources exist when it gates the pod.



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