lajith2006 commented on code in PR #749: URL: https://github.com/apache/flink-kubernetes-operator/pull/749#discussion_r1452966020
########## flink-kubernetes-operator-api/src/main/java/org/apache/flink/kubernetes/operator/api/status/CommonStatus.java: ########## @@ -101,4 +108,67 @@ public ResourceLifecycleState getLifecycleState() { * loop immediately. For example autoscaler overrides have changed and we need to apply them. */ @JsonIgnore @Internal private boolean immediateReconciliationNeeded = false; + + public List<Condition> getConditions() { + switch (getLifecycleState()) { + case CREATED: + updateConditionIfNotExist( + conditions, + ConditionUtils.notReady( + "The resource was created in Kubernetes but not yet handled by the operator")); + break; + case SUSPENDED: + updateConditionIfNotExist( + conditions, + ConditionUtils.notReady("The resource (job) has been suspended")); + break; + case UPGRADING: + updateConditionIfNotExist( + conditions, ConditionUtils.notReady("The resource is being upgraded")); + break; + case DEPLOYED: + updateConditionIfNotExist( + conditions, + ConditionUtils.ready( + "The resource is deployed, but it’s not yet considered to be stable and might be rolled back in the future")); + break; + case ROLLING_BACK: + updateConditionIfNotExist( + conditions, + ConditionUtils.notReady( + "The resource is being rolled back to the last stable spec")); + break; + case ROLLED_BACK: + updateConditionIfNotExist( + conditions, + ConditionUtils.ready("The resource is deployed with the last stable spec")); + break; + case FAILED: + updateConditionIfNotExist(conditions, ConditionUtils.error("failed")); + break; + case STABLE: + updateConditionIfNotExist( + conditions, + ConditionUtils.ready( + "The resource deployment is considered to be stable and won’t be rolled back")); + break; + } + + return conditions; + } + + private void updateConditionIfNotExist(List<Condition> conditions, Condition newCondition) { + if (conditions.isEmpty()) { + conditions.add(newCondition); + } + if (conditions.stream() + .noneMatch(condition -> condition.getType().equals(newCondition.getType()))) { + conditions.add(newCondition); + } else if (conditions.removeIf( + condition -> + !(condition.getReason().equals(newCondition.getReason()) + && condition.getMessage().equals(newCondition.getMessage())))) { + conditions.add(newCondition); + } Review Comment: Sure, will add the docs to code. above logic is to make sure that rather to blindly replace any existing conditions with new one , check for existing condition with same type and replace only if the same condition type has different message. -- 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