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


##########
resource-managers/kubernetes/core/src/main/scala/org/apache/spark/deploy/k8s/submit/KubernetesClientApplication.scala:
##########
@@ -177,10 +193,30 @@ private[spark] class Client(
       kubernetesClient.resourceList(otherKubernetesResources: 
_*).forceConflicts().serverSideApply()
     } catch {
       case NonFatal(e) =>
-        kubernetesClient.pods().resource(createdDriverPod).delete()
+        Utils.tryLogNonFatalError {
+          kubernetesClient.pods().resource(createdDriverPod).delete()
+        }
         throw e
     }
 
+    // Every resource the driver mounts exists now, so let the scheduler place 
the pod. The
+    // strategic merge patch names the gate, so it is idempotent and leaves 
other gates alone.
+    if (gateDriverPod) {
+      try {
+        kubernetesClient.pods().resource(createdDriverPod).patch(
+          PatchContext.of(PatchType.STRATEGIC_MERGE),
+          s"""{"spec":{"schedulingGates":[""" +
+            
s"""{"$$patch":"delete","name":"$DRIVER_RESOURCES_SCHEDULING_GATE"}]}}""")
+      } catch {
+        case NonFatal(e) =>
+          logError("Please check \"kubectl auth can-i patch pod\" first. It 
should be yes.")

Review Comment:
   Both are done.
   
   - The `can-i patch pod` hint is logged only for a 
`KubernetesClientException` with code 403, and it now adds `Or set 
spark.kubernetes.submission.useDriverSchedulingGate to false.`. I ran the 
compiled `Client.run()` as an account without `patch` on a real cluster: the 
submission fails with HTTP 403, no pod or config map is left behind, and the 
log has the hint.
   - A gate named `spark.apache.org/driver-resources` that is already on the 
resolved pod is removed before Spark adds its own, so the pod is no longer 
rejected as a duplicate and the patch clears it. A pod with that gate and a 
second one, run through the same compiled `Client.run()`, was accepted, and 
only the other gate was left after the submission. A test covers it, and 
dropping the removal fails that test.



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