TQJADE commented on code in PR #749:
URL: 
https://github.com/apache/spark-kubernetes-operator/pull/749#discussion_r3547154871


##########
spark-operator/src/main/java/org/apache/spark/k8s/operator/reconciler/reconcilesteps/AppReconcileStep.java:
##########
@@ -65,30 +67,69 @@ protected ReconcileProgress observeDriver(
       final SparkAppContext context,
       final SparkAppStatusRecorder statusRecorder,
       final List<BaseAppDriverObserver> observers) {
-    Optional<Pod> driverPodOptional = context.getDriverPod();
     SparkApplication app = context.getResource();
     ApplicationStatus currentStatus = app.getStatus();
-    if (driverPodOptional.isPresent()) {
-      List<ApplicationState> stateUpdates =
-          observers.stream()
-              .map(o -> o.observe(driverPodOptional.get(), app.getSpec(), 
app.getStatus()))
-              .filter(Optional::isPresent)
-              .map(Optional::get)
-              .toList();
-      if (stateUpdates.isEmpty()) {
-        return proceed();
-      } else {
-        for (ApplicationState state : stateUpdates) {
-          currentStatus = currentStatus.appendNewState(state);
+    Optional<Pod> driverPodOptional = context.getDriverPod();
+
+    if (driverPodOptional.isEmpty()) {
+      Duration verifyAfter =
+          
Duration.ofSeconds(SparkOperatorConf.MISSING_DRIVER_GRACE_PERIOD_SECONDS.getValue());
+      ApplicationState observedState = currentStatus.getCurrentState();
+      Instant transitionedAt = 
Instant.parse(observedState.getLastTransitionTime());
+      Duration stateAge = Duration.between(transitionedAt, Instant.now());
+
+      if (stateAge.compareTo(verifyAfter) < 0) {
+        log.debug(
+            "Driver pod missing from informer cache; state {} is only {}s old, 
"
+                + "deferring verification.",
+            observedState.getCurrentStateSummary(), stateAge.toSeconds());
+        return ReconcileProgress.completeAndRequeueAfter(
+            
Duration.ofSeconds(SparkOperatorConf.DEFAULT_REQUEUE_INTERVAL_SECONDS.getValue()));
+      }
+
+      try {
+        Optional<Pod> liveDriver = context.getDriverPodFromApi();
+        if (liveDriver.isPresent()) {
+          log.warn(
+              "Driver pod {} missing from informer cache after {}s in state {} 
but "
+                  + "present on apiserver; informer is likely stale. Using 
live pod "
+                  + "for this reconcile.",
+              liveDriver.get().getMetadata().getName(),
+              stateAge.toSeconds(),
+              observedState.getCurrentStateSummary());
+          driverPodOptional = liveDriver;
+        } else {
+          ApplicationStatus updatedStatus =
+              currentStatus.appendNewState(driverUnexpectedRemoved());
+          return attemptStatusUpdate(
+              context, statusRecorder, updatedStatus, 
completeAndImmediateRequeue());
         }
-        return attemptStatusUpdate(
-            context, statusRecorder, currentStatus, 
completeAndImmediateRequeue());
+      } catch (RuntimeException e) {

Review Comment:
   Replaced with KubernetesClientException.



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