use of org.apache.flink.kubernetes.operator.crd.FlinkDeployment in project flink-kubernetes-operator by apache.
the class SavepointUtilsTest method testTriggering.
@Test
public void testTriggering() {
FlinkDeployment deployment = TestUtils.buildApplicationCluster(FlinkVersion.v1_15);
deployment.getMetadata().setCreationTimestamp(Instant.now().minus(Duration.ofMinutes(15)).toString());
deployment.getStatus().getJobStatus().setState(JobStatus.RUNNING.name());
deployment.getStatus().setJobManagerDeploymentStatus(JobManagerDeploymentStatus.READY);
deployment.getStatus().getReconciliationStatus().serializeAndSetLastReconciledSpec(deployment.getSpec());
assertEquals(Optional.empty(), SavepointUtils.shouldTriggerSavepoint(deployment, configManager.getObserveConfig(deployment)));
deployment.getSpec().getFlinkConfiguration().put(KubernetesOperatorConfigOptions.PERIODIC_SAVEPOINT_INTERVAL.key(), "10m");
deployment.getStatus().getReconciliationStatus().serializeAndSetLastReconciledSpec(deployment.getSpec());
assertEquals(Optional.of(SavepointTriggerType.PERIODIC), SavepointUtils.shouldTriggerSavepoint(deployment, configManager.getObserveConfig(deployment)));
deployment.getStatus().getJobStatus().getSavepointInfo().resetTrigger();
deployment.getSpec().getJob().setSavepointTriggerNonce(123L);
assertEquals(Optional.of(SavepointTriggerType.MANUAL), SavepointUtils.shouldTriggerSavepoint(deployment, configManager.getObserveConfig(deployment)));
}
use of org.apache.flink.kubernetes.operator.crd.FlinkDeployment in project flink-kubernetes-operator by apache.
the class FlinkConfigBuilderTest method testApplyFlinkConfiguration.
@Test
public void testApplyFlinkConfiguration() {
Configuration configuration = new FlinkConfigBuilder(flinkDeployment, new Configuration()).applyFlinkConfiguration().build();
Assertions.assertEquals(2, (int) configuration.get(TaskManagerOptions.NUM_TASK_SLOTS));
Assertions.assertEquals(KubernetesConfigOptions.ServiceExposedType.ClusterIP, configuration.get(KubernetesConfigOptions.REST_SERVICE_EXPOSED_TYPE));
Assertions.assertEquals(false, configuration.get(WebOptions.CANCEL_ENABLE));
FlinkDeployment deployment = ReconciliationUtils.clone(flinkDeployment);
deployment.getSpec().setFlinkConfiguration(Map.of(KubernetesConfigOptions.REST_SERVICE_EXPOSED_TYPE.key(), KubernetesConfigOptions.ServiceExposedType.LoadBalancer.name()));
configuration = new FlinkConfigBuilder(deployment, new Configuration()).applyFlinkConfiguration().build();
Assertions.assertEquals(KubernetesConfigOptions.ServiceExposedType.LoadBalancer, configuration.get(KubernetesConfigOptions.REST_SERVICE_EXPOSED_TYPE));
deployment.getSpec().getJob().setUpgradeMode(UpgradeMode.LAST_STATE);
configuration = new FlinkConfigBuilder(deployment, new Configuration().set(HighAvailabilityOptions.HA_MODE, KubernetesHaServicesFactory.class.getCanonicalName())).applyFlinkConfiguration().build();
Assertions.assertEquals(DEFAULT_CHECKPOINTING_INTERVAL, configuration.get(ExecutionCheckpointingOptions.CHECKPOINTING_INTERVAL));
deployment = TestUtils.buildSessionCluster();
configuration = new FlinkConfigBuilder(deployment, new Configuration()).applyFlinkConfiguration().build();
Assertions.assertEquals(false, configuration.get(WebOptions.CANCEL_ENABLE));
}
use of org.apache.flink.kubernetes.operator.crd.FlinkDeployment in project flink-kubernetes-operator by apache.
the class FlinkConfigManagerTest method testConfigGeneration.
@Test
public void testConfigGeneration() {
ConfigOption<String> testConf = ConfigOptions.key("test").stringType().noDefaultValue();
FlinkConfigManager configManager = new FlinkConfigManager(Configuration.fromMap(Map.of(KubernetesOperatorConfigOptions.OPERATOR_DYNAMIC_CONFIG_ENABLED.key(), "false")));
FlinkDeployment deployment = TestUtils.buildApplicationCluster();
ReconciliationStatus reconciliationStatus = deployment.getStatus().getReconciliationStatus();
deployment.getSpec().getFlinkConfiguration().put(testConf.key(), "reconciled");
reconciliationStatus.serializeAndSetLastReconciledSpec(deployment.getSpec());
reconciliationStatus.markReconciledSpecAsStable();
deployment.getSpec().getFlinkConfiguration().put(testConf.key(), "latest");
assertEquals("latest", configManager.getDeployConfig(deployment.getMetadata(), deployment.getSpec()).get(testConf));
assertEquals("reconciled", configManager.getObserveConfig(deployment).get(testConf));
deployment.getSpec().getFlinkConfiguration().put(testConf.key(), "stable");
reconciliationStatus.serializeAndSetLastReconciledSpec(deployment.getSpec());
reconciliationStatus.markReconciledSpecAsStable();
deployment.getSpec().getFlinkConfiguration().put(testConf.key(), "rolled-back");
reconciliationStatus.serializeAndSetLastReconciledSpec(deployment.getSpec());
reconciliationStatus.setState(ReconciliationState.ROLLED_BACK);
assertEquals("stable", configManager.getObserveConfig(deployment).get(testConf));
}
use of org.apache.flink.kubernetes.operator.crd.FlinkDeployment in project flink-kubernetes-operator by apache.
the class DeploymentRecoveryTest method verifyApplicationJmRecovery.
@ParameterizedTest
@MethodSource("applicationTestParams")
public void verifyApplicationJmRecovery(FlinkVersion flinkVersion, UpgradeMode upgradeMode) throws Exception {
FlinkDeployment appCluster = TestUtils.buildApplicationCluster(flinkVersion);
appCluster.getSpec().getJob().setUpgradeMode(upgradeMode);
testController.reconcile(appCluster, context);
testController.reconcile(appCluster, context);
testController.reconcile(appCluster, context);
assertEquals(JobManagerDeploymentStatus.READY, appCluster.getStatus().getJobManagerDeploymentStatus());
// Remove deployment
flinkService.setPortReady(false);
flinkService.clear();
// Make sure we do not try to recover JM deployment errors (only missing)
testController.reconcile(appCluster, TestUtils.createContextWithFailedJobManagerDeployment());
testController.reconcile(appCluster, TestUtils.createContextWithFailedJobManagerDeployment());
assertEquals(JobManagerDeploymentStatus.ERROR, appCluster.getStatus().getJobManagerDeploymentStatus());
testController.reconcile(appCluster, context);
assertEquals(JobManagerDeploymentStatus.DEPLOYING, appCluster.getStatus().getJobManagerDeploymentStatus());
flinkService.setPortReady(true);
testController.reconcile(appCluster, context);
testController.reconcile(appCluster, context);
assertEquals(JobManagerDeploymentStatus.READY, appCluster.getStatus().getJobManagerDeploymentStatus());
assertEquals(JobStatus.RUNNING.name(), appCluster.getStatus().getJobStatus().getState());
// Remove deployment
flinkService.setPortReady(false);
flinkService.clear();
// Trigger update
appCluster.getSpec().setRestartNonce(123L);
if (upgradeMode == UpgradeMode.SAVEPOINT) {
flinkService.setHaDataAvailable(false);
}
testController.reconcile(appCluster, context);
if (upgradeMode == UpgradeMode.SAVEPOINT) {
// If deployment goes missing during an upgrade we should throw an error as savepoint
// information cannot be recovered with complete certainty
assertEquals(JobManagerDeploymentStatus.ERROR, appCluster.getStatus().getJobManagerDeploymentStatus());
} else {
flinkService.setPortReady(true);
testController.reconcile(appCluster, context);
testController.reconcile(appCluster, context);
testController.reconcile(appCluster, context);
assertEquals(JobManagerDeploymentStatus.READY, appCluster.getStatus().getJobManagerDeploymentStatus());
assertEquals("RUNNING", appCluster.getStatus().getJobStatus().getState());
assertEquals(appCluster.getSpec(), appCluster.getStatus().getReconciliationStatus().deserializeLastReconciledSpec());
}
}
use of org.apache.flink.kubernetes.operator.crd.FlinkDeployment in project flink-kubernetes-operator by apache.
the class DeploymentRecoveryTest method verifySessionJmRecovery.
@ParameterizedTest
@EnumSource(FlinkVersion.class)
public void verifySessionJmRecovery(FlinkVersion flinkVersion) throws Exception {
FlinkDeployment appCluster = TestUtils.buildSessionCluster(flinkVersion);
testController.reconcile(appCluster, context);
testController.reconcile(appCluster, context);
testController.reconcile(appCluster, context);
assertEquals(JobManagerDeploymentStatus.READY, appCluster.getStatus().getJobManagerDeploymentStatus());
// Remove deployment
flinkService.setPortReady(false);
flinkService.clear();
testController.reconcile(appCluster, context);
flinkService.setPortReady(true);
assertEquals(JobManagerDeploymentStatus.DEPLOYING, appCluster.getStatus().getJobManagerDeploymentStatus());
testController.reconcile(appCluster, context);
testController.reconcile(appCluster, context);
assertEquals(JobManagerDeploymentStatus.READY, appCluster.getStatus().getJobManagerDeploymentStatus());
}
Aggregations