gyfora commented on code in PR #957:
URL: 
https://github.com/apache/flink-kubernetes-operator/pull/957#discussion_r2068631296


##########
flink-kubernetes-operator-api/src/main/java/org/apache/flink/kubernetes/operator/api/status/FlinkDeploymentStatus.java:
##########
@@ -55,4 +60,188 @@ public class FlinkDeploymentStatus extends 
CommonStatus<FlinkDeploymentSpec> {
 
     /** Information about the TaskManagers for the scale subresource. */
     private TaskManagerInfo taskManager;
+
+    /** Condition of the CR . */
+    private List<Condition> conditions = new ArrayList<>();
+
+    private String phase;
+
+    public List<Condition> getConditions() {
+        if (reconciliationStatus != null
+                && reconciliationStatus.deserializeLastReconciledSpec() != null
+                && 
reconciliationStatus.deserializeLastReconciledSpec().getJob() == null) {
+            // Populate conditions for SessionMode deployment
+            switch (jobManagerDeploymentStatus) {
+                case READY:
+                    updateCondition(
+                            conditions,
+                            ConditionUtils.crCondition(
+                                    ConditionUtils.SESSION_MODE_CONDITION.get(
+                                            
JobManagerDeploymentStatus.READY.name())));
+                    break;
+                case MISSING:
+                    updateCondition(
+                            conditions,
+                            ConditionUtils.crCondition(
+                                    ConditionUtils.SESSION_MODE_CONDITION.get(
+                                            
JobManagerDeploymentStatus.MISSING.name())));
+                    break;
+                case DEPLOYING:
+                    updateCondition(
+                            conditions,
+                            ConditionUtils.crCondition(
+                                    ConditionUtils.SESSION_MODE_CONDITION.get(
+                                            
JobManagerDeploymentStatus.DEPLOYING.name())));
+                    break;
+                case DEPLOYED_NOT_READY:
+                    updateCondition(
+                            conditions,
+                            ConditionUtils.crCondition(
+                                    ConditionUtils.SESSION_MODE_CONDITION.get(
+                                            
JobManagerDeploymentStatus.DEPLOYED_NOT_READY.name())));
+                    break;
+                case ERROR:
+                    updateCondition(
+                            conditions,
+                            ConditionUtils.crCondition(
+                                    ConditionUtils.SESSION_MODE_CONDITION.get(
+                                            
JobManagerDeploymentStatus.ERROR.name())));
+            }
+        } else if (getJobStatus() != null && getJobStatus().getState() != 
null) {
+            // Populate conditions for ApplicationMode deployment
+            switch (getJobStatus().getState()) {
+                case RECONCILING:
+                    updateCondition(
+                            conditions,
+                            ConditionUtils.crCondition(
+                                    
ConditionUtils.APPLICATION_MODE_CONDITION.get(
+                                            JobStatus.RECONCILING.name())));
+                    break;
+                case CREATED:
+                    updateCondition(
+                            conditions,
+                            ConditionUtils.crCondition(
+                                    
ConditionUtils.APPLICATION_MODE_CONDITION.get(
+                                            JobStatus.CREATED.name())));
+                    break;
+                case RUNNING:
+                    updateCondition(
+                            conditions,
+                            ConditionUtils.crCondition(
+                                    
ConditionUtils.APPLICATION_MODE_CONDITION.get(
+                                            JobStatus.RUNNING.name())));
+                    break;
+                case FAILING:
+                    updateCondition(
+                            conditions,
+                            ConditionUtils.crCondition(
+                                    
ConditionUtils.APPLICATION_MODE_CONDITION.get(
+                                            JobStatus.FAILING.name())));
+                    break;
+                case RESTARTING:
+                    updateCondition(
+                            conditions,
+                            ConditionUtils.crCondition(
+                                    
ConditionUtils.APPLICATION_MODE_CONDITION.get(
+                                            JobStatus.RESTARTING.name())));
+                    break;
+                case FAILED:
+                    updateCondition(
+                            conditions,
+                            ConditionUtils.crCondition(
+                                    
ConditionUtils.APPLICATION_MODE_CONDITION.get(
+                                            JobStatus.FAILED.name())));
+                    break;
+                case FINISHED:
+                    updateCondition(
+                            conditions,
+                            ConditionUtils.crCondition(
+                                    
ConditionUtils.APPLICATION_MODE_CONDITION.get(
+                                            JobStatus.FINISHED.name())));
+                    break;
+
+                case CANCELED:
+                    updateCondition(
+                            conditions,
+                            ConditionUtils.crCondition(
+                                    
ConditionUtils.APPLICATION_MODE_CONDITION.get(
+                                            JobStatus.CANCELED.name())));
+                    break;
+                case SUSPENDED:
+                    updateCondition(
+                            conditions,
+                            ConditionUtils.crCondition(
+                                    
ConditionUtils.APPLICATION_MODE_CONDITION.get(
+                                            JobStatus.SUSPENDED.name())));
+                    break;
+            }
+        }
+        return conditions;
+    }
+
+    public String getPhase() {
+        if (reconciliationStatus != null
+                && reconciliationStatus.deserializeLastReconciledSpec() != null
+                && 
reconciliationStatus.deserializeLastReconciledSpec().getJob() == null) {
+            // populate phase for SessionMode deployment
+            switch (jobManagerDeploymentStatus) {
+                case READY:
+                    phase = "Running";
+                    break;
+                case MISSING:
+                case DEPLOYING:
+                    phase = "Pending";
+                    break;
+                case ERROR:
+                    phase = "Failed";
+                    break;
+            }
+        } else if (getJobStatus() != null && getJobStatus().getState() != 
null) {
+            // populate phase for ApplicationMode deployment
+            switch (getJobStatus().getState()) {
+                case RECONCILING:
+                    phase = "Pending";
+                    break;
+                case CREATED:
+                    phase = JobStatus.CREATED.name();
+                    break;
+                case RUNNING:
+                    phase = JobStatus.RUNNING.name();
+                    break;
+                case FAILING:
+                    phase = JobStatus.FAILING.name();
+                    break;
+                case RESTARTING:
+                    phase = JobStatus.RESTARTING.name();
+                    break;
+                case FAILED:
+                    phase = JobStatus.FAILED.name();
+                    break;
+                case FINISHED:
+                    phase = JobStatus.FINISHED.name();
+                    break;
+                case CANCELED:
+                    phase = JobStatus.CANCELED.name();
+                    break;
+                case SUSPENDED:
+                    phase = JobStatus.SUSPENDED.name();
+                    break;
+            }
+        }
+        return phase;
+    }
+
+    private static void updateCondition(List<Condition> conditions, Condition 
condition) {
+        if (conditions.isEmpty()) {
+            conditions.add(condition);
+            return;
+        }
+        // If new condition is same as last condition, ignore
+        Condition existingCondition = conditions.get(conditions.size() - 1);
+        if (existingCondition.getType().equals(condition.getType())
+                && 
existingCondition.getMessage().equals(condition.getMessage())) {
+            return;
+        }
+        conditions.add(condition);

Review Comment:
   Yes, I think this makes sense for a `Running` condition



-- 
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: issues-unsubscr...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to