-
Notifications
You must be signed in to change notification settings - Fork 498
[FLINK-28648][Kubernetes Operator] Allow session deletion to block on any running job #994
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2c2515c
[FLINK-28648][Flink-Kubernetes-Operator] Fix Cleanup Process for Sess…
9fb1bb6
[FLINK-28648][Flink-Kubernetes-Operator] Fix Cleanup Process for Sess…
8a12352
[FLINK-28648][Flink-Kubernetes-Operator] Fix Cleanup Process for Sess…
8ed2ea4
[FLINK-28648][Flink-Kubernetes-Operator] Add java docs for the added …
ff26986
[FLINK-28648][Flink-Kubernetes-Operator] Changed getUnManagedJobs -> …
07d5c1a
[FLINK-28648][Flink-Kubernetes-Operator] Changed getUnManagedJobs -> …
7175b2b
[FLINK-28648][Flink-Kubernetes-Operator] Cleanup Comments
fb9776e
[FLINK-28648][Kubernetes Operator] Addressed minor comments
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
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 |
|---|---|---|
|
|
@@ -17,6 +17,8 @@ | |
|
|
||
| package org.apache.flink.kubernetes.operator.reconciler.deployment; | ||
|
|
||
| import org.apache.flink.annotation.VisibleForTesting; | ||
| import org.apache.flink.api.common.JobID; | ||
| import org.apache.flink.autoscaler.NoopJobAutoscaler; | ||
| import org.apache.flink.configuration.Configuration; | ||
| import org.apache.flink.kubernetes.operator.api.FlinkDeployment; | ||
|
|
@@ -25,11 +27,16 @@ | |
| import org.apache.flink.kubernetes.operator.api.spec.FlinkDeploymentSpec; | ||
| import org.apache.flink.kubernetes.operator.api.status.FlinkDeploymentStatus; | ||
| import org.apache.flink.kubernetes.operator.api.status.JobManagerDeploymentStatus; | ||
| import org.apache.flink.kubernetes.operator.config.KubernetesOperatorConfigOptions; | ||
| import org.apache.flink.kubernetes.operator.controller.FlinkResourceContext; | ||
| import org.apache.flink.kubernetes.operator.reconciler.ReconciliationUtils; | ||
| import org.apache.flink.kubernetes.operator.utils.EventRecorder; | ||
| import org.apache.flink.kubernetes.operator.utils.IngressUtils; | ||
| import org.apache.flink.kubernetes.operator.utils.StatusRecorder; | ||
| import org.apache.flink.runtime.messages.webmonitor.JobDetails; | ||
| import org.apache.flink.runtime.rest.messages.EmptyMessageParameters; | ||
| import org.apache.flink.runtime.rest.messages.EmptyRequestBody; | ||
| import org.apache.flink.runtime.rest.messages.JobsOverviewHeaders; | ||
|
|
||
| import io.javaoperatorsdk.operator.api.reconciler.DeleteControl; | ||
| import org.slf4j.Logger; | ||
|
|
@@ -120,6 +127,37 @@ private void recoverSession(FlinkResourceContext<FlinkDeployment> ctx) throws Ex | |
| .setJobManagerDeploymentStatus(JobManagerDeploymentStatus.DEPLOYING); | ||
| } | ||
|
|
||
| // Detects jobs which are not in globally terminated states | ||
| @VisibleForTesting | ||
| Set<JobID> getNonTerminalJobs(FlinkResourceContext<FlinkDeployment> ctx) { | ||
| LOG.debug("Starting nonTerminal jobs detection for session cluster"); | ||
| try { | ||
| // Get all jobs running in the Flink cluster | ||
| var flinkService = ctx.getFlinkService(); | ||
| var clusterClient = flinkService.getClusterClient(ctx.getObserveConfig()); | ||
| var allJobs = | ||
| clusterClient | ||
| .sendRequest( | ||
| JobsOverviewHeaders.getInstance(), | ||
| EmptyMessageParameters.getInstance(), | ||
| EmptyRequestBody.getInstance()) | ||
| .get() | ||
| .getJobs(); | ||
|
|
||
| // running job Ids | ||
| Set<JobID> nonTerminalJobIds = | ||
| allJobs.stream() | ||
| .filter(job -> !job.getStatus().isGloballyTerminalState()) | ||
| .map(JobDetails::getJobId) | ||
| .collect(Collectors.toSet()); | ||
|
|
||
| return nonTerminalJobIds; | ||
| } catch (Exception e) { | ||
| LOG.warn("Failed to detect nonTerminal jobs in session cluster", e); | ||
| return Set.of(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public DeleteControl cleanupInternal(FlinkResourceContext<FlinkDeployment> ctx) { | ||
| Set<FlinkSessionJob> sessionJobs = | ||
|
|
@@ -143,13 +181,41 @@ public DeleteControl cleanupInternal(FlinkResourceContext<FlinkDeployment> ctx) | |
| } | ||
| return DeleteControl.noFinalizerRemoval() | ||
| .rescheduleAfter(ctx.getOperatorConfig().getReconcileInterval().toMillis()); | ||
| } else { | ||
| LOG.info("Stopping session cluster"); | ||
| var conf = ctx.getDeployConfig(ctx.getResource().getSpec()); | ||
| ctx.getFlinkService() | ||
| .deleteClusterDeployment( | ||
| deployment.getMetadata(), deployment.getStatus(), conf, true); | ||
| return DeleteControl.defaultDelete(); | ||
| } | ||
|
|
||
| // Check for non-terminated jobs if the option is enabled (Enabled by default) , after | ||
| // sessionJobs are deleted | ||
| boolean blockOnUnmanagedJobs = | ||
| ctx.getObserveConfig() | ||
| .getBoolean(KubernetesOperatorConfigOptions.BLOCK_ON_UNMANAGED_JOBS); | ||
| if (blockOnUnmanagedJobs) { | ||
| Set<JobID> nonTerminalJobs = getNonTerminalJobs(ctx); | ||
| if (!nonTerminalJobs.isEmpty()) { | ||
| var error = | ||
| String.format( | ||
| "The session cluster has non terminated jobs %s that should be cancelled first", | ||
| nonTerminalJobs.stream() | ||
| .map(JobID::toHexString) | ||
| .collect(Collectors.toList())); | ||
| if (eventRecorder.triggerEvent( | ||
| deployment, | ||
| EventRecorder.Type.Warning, | ||
| EventRecorder.Reason.CleanupFailed, | ||
| EventRecorder.Component.Operator, | ||
| error, | ||
| ctx.getKubernetesClient())) { | ||
| LOG.warn(error); | ||
| } | ||
| return DeleteControl.noFinalizerRemoval() | ||
| .rescheduleAfter(ctx.getOperatorConfig().getReconcileInterval().toMillis()); | ||
| } | ||
| } | ||
|
|
||
| LOG.info("Stopping session cluster"); | ||
| var conf = ctx.getDeployConfig(ctx.getResource().getSpec()); | ||
| ctx.getFlinkService() | ||
| .deleteClusterDeployment( | ||
| deployment.getMetadata(), deployment.getStatus(), conf, true); | ||
|
||
| return DeleteControl.defaultDelete(); | ||
| } | ||
| } | ||
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
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.
we can remove the if branch and the logging. Event triggering already creates logs we don't need both I think
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.
@gyfora I see this for sessionjob event as well , should we remove here too.