-
Notifications
You must be signed in to change notification settings - Fork 484
[FLINK-33634] Add Conditions to Flink CRD's Status field #957
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 11 commits
afdf40b
1d84164
727bb4b
c66fd1f
c623f33
196c494
32294f4
7b6d6a1
4f6679b
93be98a
9faab16
b40dcf3
70030db
9311031
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,18 +18,26 @@ | |
package org.apache.flink.kubernetes.operator.api.status; | ||
|
||
import org.apache.flink.annotation.Experimental; | ||
import org.apache.flink.api.common.JobStatus; | ||
import org.apache.flink.kubernetes.operator.api.spec.FlinkDeploymentSpec; | ||
import org.apache.flink.kubernetes.operator.api.utils.ConditionUtils; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import io.fabric8.kubernetes.api.model.Condition; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.NoArgsConstructor; | ||
import lombok.ToString; | ||
import lombok.experimental.SuperBuilder; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
import static org.apache.flink.kubernetes.operator.api.utils.ConditionUtils.CONDITION_TYPE_RUNNING; | ||
|
||
/** Last observed status of the Flink deployment. */ | ||
@Experimental | ||
|
@@ -55,4 +63,56 @@ 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<>(); | ||
|
||
public List<Condition> getConditions() { | ||
if (getJobStatus() != null) { | ||
JobStatus jobStatus = getJobStatus().getState(); | ||
if (jobStatus == null) { | ||
// Populate conditions for SessionMode deployment | ||
updateCondition( | ||
conditions, | ||
ConditionUtils.crCondition( | ||
ConditionUtils.SESSION_MODE_CONDITION.get( | ||
jobManagerDeploymentStatus.name()))); | ||
} else if (jobStatus != null) { | ||
// Populate conditions for ApplicationMode deployment | ||
updateCondition( | ||
conditions, | ||
ConditionUtils.crCondition( | ||
ConditionUtils.APPLICATION_MODE_CONDITION.get(jobStatus.name()))); | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this entire code block should be part of the ConditionUtils probably encapsulated into a single:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @gyfora . I believe , If we have them in ConditionUtils block, we will not be able to utilise the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be implemented as a static method that operates on the status There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@gyfora Yes - we were thinking changing to something like
Can you see a slicker way of doing this given we need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just wanted to factor out this condition logic from the FlinkDeploymentStatus class, it doesn't seem to belong there. I don't have an issue with he logic itself There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved logic to |
||
return conditions; | ||
} | ||
|
||
private static void updateCondition(List<Condition> conditions, Condition newCondition) { | ||
if (newCondition.getType().equals(CONDITION_TYPE_RUNNING)) { | ||
Optional<Condition> existingCondition = | ||
conditions.stream() | ||
.filter( | ||
c -> | ||
c.getType().equals(CONDITION_TYPE_RUNNING) | ||
&& c.getReason() | ||
.equals(newCondition.getReason()) | ||
&& c.getMessage() | ||
.equals(newCondition.getMessage())) | ||
.findFirst(); | ||
// Until there is a condition change which reflects the latest state, no need to add | ||
// condition to list. | ||
if (existingCondition.isPresent()) { | ||
return; | ||
} | ||
// Remove existing Condition with type running and then add a new condition that | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: the comment is not quite right I think. then There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's been refactored.. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Honestly I don't get this whole logic here. Can we simply always update the list to List.of(newCondition) + update the transition timestamp if the value changed from true->false or vice versa. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @davidradl @lajith2006 am I missing something ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gyfora I talked with @lajith2006. His code originally was wanting to handle more than one condition and manage the existing list to prevent 2 running conditions being in the list. We agreed to keep it simple and amend this code as you suggest i.e. just add a new list with one running condition. We thought the transition time should also be updated if the message changes, as there are cases in the flow diagram in the Flip where the running condition remains false, but the message changes, in this case we think that we should update the transition time WDYT? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lastTransitionTime time should refer to the time when the status changes (true -> false or false->true) at least this is how it is used everywhere I know and everywhere I find online. Changed message alone should not update the timestamp as it would break the semantics and makes it impossible to tell when the job actually stopped running for example. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @gyfora , modified in such a way that |
||
// reflects the current state. | ||
conditions.removeIf( | ||
c -> | ||
c.getType().equals(CONDITION_TYPE_RUNNING) | ||
&& !c.getMessage().equals(newCondition.getMessage()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we have got here because the new condition is not the same as the existing condition. So we should just remove the existing condition without any conditions. As-is the condition will not be removed if existing condition message or reason matches the new condition; which is not correct. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Right its fine for now, But I think, if in later point of time, if we are adding new conditions other than Running, just removing the existing condition without of any check will cause an issue.
That's right, but for Running type , we don't have any such case were reason or message can be matched with existing condition. |
||
&& !c.getReason().equals(newCondition.getReason())); | ||
} | ||
conditions.add(newCondition); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.flink.kubernetes.operator.api.utils; | ||
|
||
import org.apache.flink.api.common.JobStatus; | ||
import org.apache.flink.kubernetes.operator.api.status.JobManagerDeploymentStatus; | ||
|
||
import io.fabric8.kubernetes.api.model.Condition; | ||
import io.fabric8.kubernetes.api.model.ConditionBuilder; | ||
|
||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
import java.util.Map; | ||
|
||
/** Creates a condition object with the type, status, message and reason. */ | ||
public class ConditionUtils { | ||
public static final String CONDITION_TYPE_RUNNING = "Running"; | ||
|
||
public static Condition crCondition(Condition condition) { | ||
return new ConditionBuilder(condition) | ||
.withLastTransitionTime( | ||
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").format(new Date())) | ||
.build(); | ||
} | ||
|
||
public static final Map<String, Condition> SESSION_MODE_CONDITION = | ||
Map.of( | ||
JobManagerDeploymentStatus.READY.name(), | ||
new ConditionBuilder() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: you could refactor to a method and pass JobManagerDeploymentConditionStatus.READY, as the rest of the condition builder is the same apart from the status .
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It has been moved to method and reason and messages are getting from enum. |
||
.withType(CONDITION_TYPE_RUNNING) | ||
.withStatus("True") | ||
.withReason("JobManagerReady") | ||
.withMessage( | ||
"JobManager is running and ready to receive REST API calls") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May be a better design to add this fields into the enum directly then simply get it from it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, Sure, have addressed using enum . |
||
.build(), | ||
JobManagerDeploymentStatus.MISSING.name(), | ||
new ConditionBuilder() | ||
.withType(CONDITION_TYPE_RUNNING) | ||
.withStatus("False") | ||
.withReason("Missing") | ||
.withMessage("JobManager deployment not found") | ||
.build(), | ||
JobManagerDeploymentStatus.DEPLOYING.name(), | ||
new ConditionBuilder() | ||
.withType(CONDITION_TYPE_RUNNING) | ||
.withStatus("False") | ||
.withReason("Deploying") | ||
.withMessage("JobManager process is starting up") | ||
.build(), | ||
JobManagerDeploymentStatus.DEPLOYED_NOT_READY.name(), | ||
new ConditionBuilder() | ||
.withType(CONDITION_TYPE_RUNNING) | ||
.withStatus("False") | ||
.withReason("DeployedNotReady") | ||
.withMessage( | ||
"JobManager is running but not ready yet to receive REST API calls") | ||
.build(), | ||
JobManagerDeploymentStatus.ERROR.name(), | ||
new ConditionBuilder() | ||
.withType(CONDITION_TYPE_RUNNING) | ||
.withStatus("False") | ||
.withReason("Error") | ||
.withMessage("JobManager deployment failed") | ||
.build()); | ||
|
||
public static final Map<String, Condition> APPLICATION_MODE_CONDITION = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To me this entire mapping feels like that it should be replaced with a method,
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, I have a them in method. As reason is expected to be in camelcase, I have added a method to make it as camecase from status.name(). |
||
Map.of( | ||
JobStatus.RECONCILING.name(), | ||
new ConditionBuilder() | ||
.withType(CONDITION_TYPE_RUNNING) | ||
.withStatus("False") | ||
.withReason("Reconciling") | ||
.withMessage("Job is currently reconciling") | ||
.build(), | ||
JobStatus.CREATED.name(), | ||
new ConditionBuilder() | ||
.withType(CONDITION_TYPE_RUNNING) | ||
.withStatus("False") | ||
.withReason("JobCreated") | ||
.withMessage("Job is created") | ||
.build(), | ||
JobStatus.RUNNING.name(), | ||
new ConditionBuilder() | ||
.withType(CONDITION_TYPE_RUNNING) | ||
.withStatus("True") | ||
.withReason("JobRunning") | ||
.withMessage("Job is running") | ||
.build(), | ||
JobStatus.FAILING.name(), | ||
new ConditionBuilder() | ||
.withType(CONDITION_TYPE_RUNNING) | ||
.withStatus("False") | ||
.withReason("JobFailing") | ||
.withMessage("Job has failed") | ||
.build(), | ||
JobStatus.RESTARTING.name(), | ||
new ConditionBuilder() | ||
.withType(CONDITION_TYPE_RUNNING) | ||
.withStatus("False") | ||
.withReason("JobRestarting") | ||
.withMessage("The job is currently restarting") | ||
.build(), | ||
JobStatus.FAILED.name(), | ||
new ConditionBuilder() | ||
.withType(CONDITION_TYPE_RUNNING) | ||
.withStatus("False") | ||
.withReason("JobFailed") | ||
.withMessage("The job has failed with a non-recoverable task failure") | ||
.build(), | ||
JobStatus.FINISHED.name(), | ||
new ConditionBuilder() | ||
.withType(CONDITION_TYPE_RUNNING) | ||
.withStatus("False") | ||
.withReason("JobFinished") | ||
.withMessage("Job's tasks have successfully finished") | ||
.build(), | ||
JobStatus.CANCELED.name(), | ||
new ConditionBuilder() | ||
.withType(CONDITION_TYPE_RUNNING) | ||
.withStatus("False") | ||
.withReason("JobCancelled") | ||
.withMessage("Job has been cancelled") | ||
.build(), | ||
JobStatus.SUSPENDED.name(), | ||
new ConditionBuilder() | ||
.withType(CONDITION_TYPE_RUNNING) | ||
.withStatus("False") | ||
.withReason("JobSuspended") | ||
.withMessage("The job has been suspended") | ||
.build()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
} else if (jobStatus != null) {
->else {