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


##########
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:
   I think there should only ever be a single condition of type `Running` in 
the list that we return. Since we only have a single condition type right now, 
then the list should only have a single element. The latestTransition timestamp 
needs to represent when running changed from true->false or false->true. We can 
however keep updating the message if we want.



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