-
Notifications
You must be signed in to change notification settings - Fork 500
[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
Open
lajith2006
wants to merge
19
commits into
apache:main
Choose a base branch
from
lajith2006:33634-status
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
afdf40b
[FLINK-33634] Add Conditions to Flink CRD's Status field
lajith2006 1d84164
[FLINK-33634] Add Conditions to Flink CRD's Status field
lajith2006 727bb4b
[FLINK-33634] Add Conditions to Flink CRD's Status field
lajith2006 c66fd1f
[FLINK-33634] Add Conditions to Flink CRD's Status field
lajith2006 c623f33
[FLINK-33634] Add Conditions to Flink CRD's Status field
lajith2006 196c494
[FLINK-33634] Add Conditions to Flink CRD's Status field
lajith2006 32294f4
[FLINK-33634] Add Conditions to Flink CRD's Status field
lajith2006 7b6d6a1
[FLINK-33634] Add Conditions to Flink CRD's Status field
lajith2006 4f6679b
[FLINK-33634] Add Conditions to Flink CRD's Status field
lajith2006 93be98a
[FLINK-33634] Add Conditions to Flink CRD's Status field
lajith2006 9faab16
[FLINK-33634] Add Conditions to Flink CRD's Status field
lajith2006 b40dcf3
[FLINK-33634] Add Conditions to Flink CRD's Status field
lajith2006 70030db
[FLINK-33634] Add Conditions to Flink CRD's Status field
lajith2006 9311031
[FLINK-33634] Add Conditions to Flink CRD's Status field
lajith2006 9349ea4
Merge branch 'main' into 33634-status
lajith2006 00f5541
[FLINK-33634] Add Conditions to Flink CRD's Status field
lajith2006 b748ec7
[FLINK-33634] Add Conditions to Flink CRD's Status field
lajith2006 642e799
[FLINK-33634] Add Conditions to Flink CRD's Status field
lajith2006 9d2d48c
Merge branch 'apache:main' into 33634-status
lajith2006 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
...ator-api/src/main/java/org/apache/flink/kubernetes/operator/api/utils/ConditionUtils.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| /* | ||
| * 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.Mode; | ||
| import org.apache.flink.kubernetes.operator.api.spec.FlinkDeploymentSpec; | ||
| import org.apache.flink.kubernetes.operator.api.status.FlinkDeploymentReconciliationStatus; | ||
| import org.apache.flink.kubernetes.operator.api.status.FlinkDeploymentStatus; | ||
| 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.time.Instant; | ||
| import java.util.List; | ||
|
|
||
| import static org.apache.flink.api.common.JobStatus.RUNNING; | ||
| import static org.apache.flink.kubernetes.operator.api.status.JobManagerDeploymentStatus.READY; | ||
|
|
||
| /** Creates a condition object with the type, status, message and reason. */ | ||
| public class ConditionUtils { | ||
| public static final String CONDITION_TYPE_RUNNING = "Running"; | ||
|
|
||
| /** | ||
| * Creates a List of Condition object based on the provided FlinkDeploymentStatus. | ||
| * | ||
| * @param flinkDeploymentStatus the FlinkDeploymentStatus object containing job status | ||
| * information | ||
| * @return a list of Condition object representing the current status of the Flink deployment | ||
| */ | ||
| public static List<Condition> createConditionFromStatus( | ||
| FlinkDeploymentStatus flinkDeploymentStatus) { | ||
|
|
||
| FlinkDeploymentReconciliationStatus reconciliationStatus = | ||
| flinkDeploymentStatus.getReconciliationStatus(); | ||
| Condition conditionToAdd = null; | ||
|
|
||
| if (reconciliationStatus != null) { | ||
| FlinkDeploymentSpec deploymentSpec = | ||
| reconciliationStatus.deserializeLastReconciledSpec(); | ||
|
|
||
| if (deploymentSpec != null) { | ||
| switch (Mode.getMode(deploymentSpec)) { | ||
| case APPLICATION: | ||
| conditionToAdd = | ||
| getApplicationModeCondition( | ||
| flinkDeploymentStatus.getJobStatus().getState()); | ||
| break; | ||
| case SESSION: | ||
| conditionToAdd = | ||
| getSessionModeCondition( | ||
| flinkDeploymentStatus.getJobManagerDeploymentStatus()); | ||
| } | ||
| updateLastTransitionTime(flinkDeploymentStatus.getConditions(), conditionToAdd); | ||
| } | ||
| } | ||
| return conditionToAdd == null ? List.of() : List.of(conditionToAdd); | ||
| } | ||
|
|
||
| private static void updateLastTransitionTime(List<Condition> conditions, Condition condition) { | ||
| if (condition == null) { | ||
| return; | ||
| } | ||
| Condition existingCondition = | ||
| conditions.stream() | ||
| .filter(c -> c.getType().equals(condition.getType())) | ||
| .findFirst() | ||
| .orElse(null); | ||
| condition.setLastTransitionTime(getLastTransitionTimeStamp(existingCondition, condition)); | ||
| } | ||
|
|
||
| private static Condition getApplicationModeCondition(JobStatus jobStatus) { | ||
| return new ConditionBuilder() | ||
| .withType(CONDITION_TYPE_RUNNING) | ||
| .withStatus(jobStatus == RUNNING ? "True" : "False") | ||
| .withReason(toCamelCase(jobStatus.name())) | ||
| .withMessage("Job status " + jobStatus.name()) | ||
| .build(); | ||
| } | ||
|
|
||
| private static Condition getSessionModeCondition(JobManagerDeploymentStatus jmStatus) { | ||
| return new ConditionBuilder() | ||
| .withType(CONDITION_TYPE_RUNNING) | ||
| .withStatus(jmStatus == READY ? "True" : "False") | ||
| .withReason(jmStatus.getReason()) | ||
| .withMessage(jmStatus.getMessage()) | ||
| .build(); | ||
| } | ||
|
|
||
| /** | ||
| * Reason in the condition object should be a CamelCase string, so need to convert JobStatus as | ||
| * all the keywords are one noun, so we only need to upper case the first letter. | ||
| * | ||
| * @return CamelCase reason as String | ||
| */ | ||
| private static String toCamelCase(String reason) { | ||
| reason = reason.toLowerCase(); | ||
| return reason.substring(0, 1).toUpperCase() + reason.substring(1); | ||
| } | ||
|
|
||
| /** | ||
| * get the last transition time for the condition , returns the current time if there is no | ||
| * existing condition or if the condition status has changed, otherwise returns existing | ||
| * condition LastTransitionTime. | ||
| * | ||
| * @param existingCondition The current condition object, may be null. | ||
| * @param condition The new condition object to compare against the existing one. | ||
| * @return A string representing the last transition time in ISO 8601 format with nanosecond | ||
| * precision (e.g., "2025-10-30T07:35:35.189752790Z"). Returns a new timestamp if the | ||
| * existing condition is null or the status has changed, otherwise returns the last | ||
| * transition time of the existing condition. | ||
| */ | ||
| private static String getLastTransitionTimeStamp( | ||
| Condition existingCondition, Condition condition) { | ||
| String lastTransitionTime; | ||
| if (existingCondition == null | ||
| || !existingCondition.getStatus().equals(condition.getStatus())) { | ||
| lastTransitionTime = Instant.now().toString(); | ||
| } else { | ||
| lastTransitionTime = existingCondition.getLastTransitionTime(); | ||
| } | ||
| return lastTransitionTime; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Camel case is not just upper casing the first letter. We may need to upper case in the string as well. I suggest mapping the lower case to the appropriate camel cased reason.
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.
Right, but not as of now as per here. If we go with mapping, we end up with new method, do we required them?.