|
26 | 26 | import org.apache.flink.kubernetes.operator.api.FlinkSessionJob; |
27 | 27 | import org.apache.flink.kubernetes.operator.api.lifecycle.ResourceLifecycleState; |
28 | 28 | import org.apache.flink.kubernetes.operator.api.spec.JobState; |
| 29 | +import org.apache.flink.kubernetes.operator.api.status.JobManagerDeploymentStatus; |
29 | 30 | import org.apache.flink.kubernetes.operator.api.status.ReconciliationState; |
30 | 31 | import org.apache.flink.kubernetes.operator.config.FlinkOperatorConfiguration; |
31 | 32 | import org.apache.flink.kubernetes.operator.metrics.CustomResourceMetrics; |
@@ -71,8 +72,28 @@ public void lifecycleStateTest() { |
71 | 72 | ReconciliationUtils.updateStatusForDeployedSpec(application, new Configuration()); |
72 | 73 | assertEquals(DEPLOYED, application.getStatus().getLifecycleState()); |
73 | 74 |
|
| 75 | + application.getStatus().setJobManagerDeploymentStatus(JobManagerDeploymentStatus.DEPLOYING); |
74 | 76 | application.getStatus().getReconciliationStatus().markReconciledSpecAsStable(); |
75 | | - assertEquals(STABLE, application.getStatus().getLifecycleState()); |
| 77 | + assertEquals( |
| 78 | + STABLE, |
| 79 | + application.getStatus().getLifecycleState(), |
| 80 | + "JobManager Deployment is in DEPLOYING state, hence application is STABLE"); |
| 81 | + |
| 82 | + application |
| 83 | + .getStatus() |
| 84 | + .setJobManagerDeploymentStatus(JobManagerDeploymentStatus.DEPLOYED_NOT_READY); |
| 85 | + application.getStatus().getReconciliationStatus().markReconciledSpecAsStable(); |
| 86 | + assertEquals( |
| 87 | + STABLE, |
| 88 | + application.getStatus().getLifecycleState(), |
| 89 | + "JobManager Deployment is in DEPLOYED_NOT_READY state, hence application is STABLE"); |
| 90 | + |
| 91 | + application.getStatus().setJobManagerDeploymentStatus(JobManagerDeploymentStatus.READY); |
| 92 | + application.getStatus().getReconciliationStatus().markReconciledSpecAsStable(); |
| 93 | + assertEquals( |
| 94 | + STABLE, |
| 95 | + application.getStatus().getLifecycleState(), |
| 96 | + "JobManager Deployment is in READY state, hence application is STABLE"); |
76 | 97 |
|
77 | 98 | application.getStatus().setError("errr"); |
78 | 99 | assertEquals(STABLE, application.getStatus().getLifecycleState()); |
@@ -337,4 +358,57 @@ private Map<ResourceLifecycleState, List<Histogram>> initTimeHistos() { |
337 | 358 | } |
338 | 359 | return histos; |
339 | 360 | } |
| 361 | + |
| 362 | + @Test |
| 363 | + public void testUnrecoverableDeploymentLifecycleState() { |
| 364 | + var application = TestUtils.buildApplicationCluster(); |
| 365 | + |
| 366 | + // Setup the deployment to simulate it has been deployed (so isBeforeFirstDeployment = |
| 367 | + // false) |
| 368 | + ReconciliationUtils.updateStatusForDeployedSpec(application, new Configuration()); |
| 369 | + application.getStatus().getReconciliationStatus().markReconciledSpecAsStable(); |
| 370 | + |
| 371 | + application.getStatus().setJobManagerDeploymentStatus(JobManagerDeploymentStatus.ERROR); |
| 372 | + application.getStatus().setError(null); |
| 373 | + assertEquals( |
| 374 | + FAILED, |
| 375 | + application.getStatus().getLifecycleState(), |
| 376 | + "ERROR deployment should always be FAILED (terminal error state)"); |
| 377 | + |
| 378 | + application.getStatus().setJobManagerDeploymentStatus(JobManagerDeploymentStatus.ERROR); |
| 379 | + application.getStatus().setError("JobManager deployment failed to start"); |
| 380 | + assertEquals( |
| 381 | + FAILED, |
| 382 | + application.getStatus().getLifecycleState(), |
| 383 | + "ERROR deployment with error message should also be FAILED"); |
| 384 | + |
| 385 | + application.getStatus().setJobManagerDeploymentStatus(JobManagerDeploymentStatus.MISSING); |
| 386 | + application |
| 387 | + .getStatus() |
| 388 | + .setError("JobManager deployment was deleted and cannot be recovered"); |
| 389 | + assertEquals( |
| 390 | + FAILED, |
| 391 | + application.getStatus().getLifecycleState(), |
| 392 | + "MISSING deployment with error should be FAILED"); |
| 393 | + |
| 394 | + application.getStatus().setError(null); |
| 395 | + application.getStatus().setJobManagerDeploymentStatus(JobManagerDeploymentStatus.MISSING); |
| 396 | + assertEquals( |
| 397 | + FAILED, |
| 398 | + application.getStatus().getLifecycleState(), |
| 399 | + "MISSING deployment with stable reconciliation should be FAILED"); |
| 400 | + |
| 401 | + application.getStatus().setError(null); |
| 402 | + application.getStatus().setJobManagerDeploymentStatus(JobManagerDeploymentStatus.MISSING); |
| 403 | + // Reset to DEPLOYED state (not stable yet) to simulate ongoing deployment |
| 404 | + application.getStatus().getReconciliationStatus().setState(ReconciliationState.DEPLOYED); |
| 405 | + application |
| 406 | + .getStatus() |
| 407 | + .getReconciliationStatus() |
| 408 | + .setLastStableSpec(null); // Mark as not stable |
| 409 | + assertEquals( |
| 410 | + DEPLOYED, |
| 411 | + application.getStatus().getLifecycleState(), |
| 412 | + "MISSING deployment before stability should not be FAILED yet (still deploying)"); |
| 413 | + } |
340 | 414 | } |
0 commit comments