Skip to content
Open
Show file tree
Hide file tree
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 Mar 12, 2025
1d84164
[FLINK-33634] Add Conditions to Flink CRD's Status field
lajith2006 Mar 12, 2025
727bb4b
[FLINK-33634] Add Conditions to Flink CRD's Status field
lajith2006 Mar 15, 2025
c66fd1f
[FLINK-33634] Add Conditions to Flink CRD's Status field
lajith2006 Mar 19, 2025
c623f33
[FLINK-33634] Add Conditions to Flink CRD's Status field
lajith2006 Mar 26, 2025
196c494
[FLINK-33634] Add Conditions to Flink CRD's Status field
lajith2006 Mar 28, 2025
32294f4
[FLINK-33634] Add Conditions to Flink CRD's Status field
lajith2006 Mar 28, 2025
7b6d6a1
[FLINK-33634] Add Conditions to Flink CRD's Status field
lajith2006 May 12, 2025
4f6679b
[FLINK-33634] Add Conditions to Flink CRD's Status field
lajith2006 May 12, 2025
93be98a
[FLINK-33634] Add Conditions to Flink CRD's Status field
lajith2006 May 14, 2025
9faab16
[FLINK-33634] Add Conditions to Flink CRD's Status field
lajith2006 May 14, 2025
b40dcf3
[FLINK-33634] Add Conditions to Flink CRD's Status field
lajith2006 May 16, 2025
70030db
[FLINK-33634] Add Conditions to Flink CRD's Status field
lajith2006 May 16, 2025
9311031
[FLINK-33634] Add Conditions to Flink CRD's Status field
lajith2006 May 18, 2025
9349ea4
Merge branch 'main' into 33634-status
lajith2006 Oct 7, 2025
00f5541
[FLINK-33634] Add Conditions to Flink CRD's Status field
lajith2006 Oct 9, 2025
b748ec7
[FLINK-33634] Add Conditions to Flink CRD's Status field
lajith2006 Oct 9, 2025
642e799
[FLINK-33634] Add Conditions to Flink CRD's Status field
lajith2006 Nov 13, 2025
9d2d48c
Merge branch 'apache:main' into 33634-status
lajith2006 Nov 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
* limitations under the License.
*/

package org.apache.flink.kubernetes.operator.config;
package org.apache.flink.kubernetes.operator.api;

import org.apache.flink.kubernetes.operator.api.FlinkDeployment;
import org.apache.flink.kubernetes.operator.api.spec.FlinkDeploymentSpec;

/** The mode of {@link FlinkDeployment}. */
Expand All @@ -45,7 +44,7 @@ public static Mode getMode(FlinkDeployment flinkApp) {
: getMode(lastReconciledSpec);
}

private static Mode getMode(FlinkDeploymentSpec spec) {
public static Mode getMode(FlinkDeploymentSpec spec) {
return spec.getJob() != null ? APPLICATION : SESSION;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@
import org.apache.flink.kubernetes.operator.api.spec.FlinkDeploymentSpec;

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;

/** Last observed status of the Flink deployment. */
Expand All @@ -55,4 +58,7 @@ 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<>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,36 @@
public enum JobManagerDeploymentStatus {

/** JobManager is running and ready to receive REST API calls. */
READY,
READY("JobManagerReady", "JobManager is running and ready to receive REST API calls"),

/** JobManager is running but not ready yet to receive REST API calls. */
DEPLOYED_NOT_READY,
DEPLOYED_NOT_READY(
"DeployedNotReady",
"JobManager is running but not yet ready to receive REST API calls"),

/** JobManager process is starting up. */
DEPLOYING,
DEPLOYING("JobManagerIsDeploying", "JobManager process is starting up"),

/** JobManager deployment not found, probably not started or killed by user. */
// TODO: currently a mix of SUSPENDED and ERROR, needs cleanup
MISSING,
MISSING("JobManagerDeploymentMissing", "JobManager deployment not found"),

/** Deployment in terminal error, requires spec change for reconciliation to continue. */
ERROR;
ERROR("Error", "JobManager deployment failed");

private String reason;
private String message;

JobManagerDeploymentStatus(String reason, String message) {
this.reason = reason;
this.message = message;
}

public String getReason() {
return reason;
}

public String getMessage() {
return message;
}
}
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);

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.

Copy link
Author

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

}

/**
* 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.flink.kubernetes.operator.api.utils;

import org.apache.flink.api.common.JobStatus;
import org.apache.flink.configuration.CheckpointingOptions;
import org.apache.flink.configuration.HighAvailabilityOptions;
import org.apache.flink.configuration.TaskManagerOptions;
Expand All @@ -39,8 +40,10 @@
import org.apache.flink.kubernetes.operator.api.spec.TaskManagerSpec;
import org.apache.flink.kubernetes.operator.api.spec.UpgradeMode;
import org.apache.flink.kubernetes.operator.api.status.CheckpointType;
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.FlinkSessionJobStatus;
import org.apache.flink.kubernetes.operator.api.status.JobManagerDeploymentStatus;

import io.fabric8.kubernetes.api.model.Container;
import io.fabric8.kubernetes.api.model.ObjectMetaBuilder;
Expand All @@ -49,6 +52,7 @@
import io.fabric8.kubernetes.api.model.PodTemplateSpec;

import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

Expand Down Expand Up @@ -268,4 +272,43 @@ public static FlinkStateSnapshot buildFlinkStateSnapshotCheckpoint(

return snapshot;
}

public static FlinkDeploymentStatus createApplicationModeStatus(JobStatus jobStatus) {
FlinkDeploymentStatus status = new FlinkDeploymentStatus();
org.apache.flink.kubernetes.operator.api.status.JobStatus flinkJobStatus =
new org.apache.flink.kubernetes.operator.api.status.JobStatus();
flinkJobStatus.setState(jobStatus);
status.setJobStatus(flinkJobStatus);
status.setConditions(new ArrayList<>());

FlinkDeploymentReconciliationStatus reconciliationStatus =
new FlinkDeploymentReconciliationStatus();

FlinkDeployment deployment = BaseTestUtils.buildApplicationCluster();
String serializedSpec = SpecUtils.writeSpecWithMeta(deployment.getSpec(), deployment);
reconciliationStatus.setLastReconciledSpec(serializedSpec);

status.setReconciliationStatus(reconciliationStatus);
status.setJobManagerDeploymentStatus(JobManagerDeploymentStatus.READY);

return status;
}

public static FlinkDeploymentStatus createSessionModeStatus(
JobManagerDeploymentStatus jmStatus) {
FlinkDeploymentStatus status = new FlinkDeploymentStatus();
status.setJobManagerDeploymentStatus(jmStatus);
status.setConditions(new ArrayList<>());

FlinkDeploymentReconciliationStatus reconciliationStatus =
new FlinkDeploymentReconciliationStatus();

FlinkDeployment deployment = BaseTestUtils.buildSessionCluster();
String serializedSpec = SpecUtils.writeSpecWithMeta(deployment.getSpec(), deployment);
reconciliationStatus.setLastReconciledSpec(serializedSpec);

status.setReconciliationStatus(reconciliationStatus);

return status;
}
}
Loading