Dennis-Mircea commented on code in PR #1249:
URL: 
https://github.com/apache/flink-kubernetes-operator/pull/1249#discussion_r4709727159


##########
flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/observer/deployment/AbstractFlinkDeploymentObserver.java:
##########
@@ -60,42 +84,72 @@ public AbstractFlinkDeploymentObserver(EventRecorder 
eventRecorder) {
     @Override
     public void observeInternal(FlinkResourceContext<FlinkDeployment> ctx) {
         var flinkDep = ctx.getResource();
-        if (!isJmDeploymentReady(flinkDep)) {
-            // Only observe the JM if we think it's in bad state
+        if (!isJmDeployed(flinkDep)) {
             observeJmDeployment(ctx);
-        }
-
-        if (isJmDeploymentReady(flinkDep)) {
-            // Only observe session/application if JM is ready
+        } else {
             observeFlinkCluster(ctx);
         }
 
-        if (isJmDeploymentReady(flinkDep)) {
-            observeClusterInfo(ctx);
+        if (isJmReady(flinkDep)) {
+            observeJob(ctx);
         }
 
         clearErrorsIfDeploymentIsHealthy(flinkDep);
     }
 
-    private void observeClusterInfo(FlinkResourceContext<FlinkDeployment> ctx) 
{
+    protected void observeFlinkCluster(FlinkResourceContext<FlinkDeployment> 
ctx) {
         var flinkApp = ctx.getResource();
+        var status = flinkApp.getStatus();
         try {
-            var clusterInfo =
-                    ctx.getFlinkService()
-                            .getClusterInfo(
-                                    ctx.getObserveConfig(),
-                                    
flinkApp.getStatus().getJobStatus().getJobId());
-            
flinkApp.getStatus().getClusterInfo().putAll(clusterInfo.getInfo());
-            logger.debug("ClusterInfo: {}", 
flinkApp.getStatus().getClusterInfo());
+            var clusterInfo = 
ctx.getFlinkService().getClusterInfo(ctx.getObserveConfig());
+            status.getClusterInfo().putAll(clusterInfo);
+        } catch (Exception e) {
+            if (isJmReady(flinkApp)) {
+                logger.warn("JobManager REST API stopped answering", e);
+                if (JobStatus.RUNNING == status.getJobStatus().getState()) {
+                    // The job was last observed RUNNING, its state is unknown 
until the REST API
+                    // answers again
+                    status.getJobStatus().setState(JobStatus.RECONCILING);
+                }
+            } else if (e instanceof TimeoutException) {
+                logger.info(
+                        "JobManager REST API is not ready yet, no answer 
within {}",
+                        TimeUtils.formatWithHighestUnit(
+                                
ctx.getOperatorConfig().getFlinkClientTimeout()));
+            } else {
+                logger.info("JobManager REST API is not ready yet: {}", 
e.toString());
+            }
+            // Either way, find out what happened to the JobManager pod
+            observeJmDeployment(ctx);

Review Comment:
   Not necessarily. The `observeFlinkCluster` is actually called only when the 
JM status is `DEPLOYED_NOT_READY` or `READY`. Based on these 2 states, there 
are 2 main flows that could reach this:
   1. JM state is `DEPLOYED_NOT_READY` - this is the case of an upgrade (the 
base case) - In this case the branch at line 115 or 120 is taken and 
`observeJmDeployment` is still called because even tho we are in a normal 
upgrade and we are waiting for the JobManager to become ready, but there may be 
unexpected cases where the JobManager crashes and never become READY, so we do 
not want to loop over and over again, and we want to identify the problem and 
to possibly downgrade the state from `DEPLOYED_NOT_READY` to `MISSING`.
   2. JM state is `READY` - this is the case were JM stopped responding - In 
this case the branch at line 108 is taken and the `observeJmDeployment` is 
called in order to make the transition from `READY` to `MISSING` or even 
`ERROR`.



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

Reply via email to