Search in sources :

Example 21 with FlinkDeployment

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)));
}
Also used : FlinkDeployment(org.apache.flink.kubernetes.operator.crd.FlinkDeployment) Test(org.junit.jupiter.api.Test)

Example 22 with FlinkDeployment

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));
}
Also used : FlinkDeployment(org.apache.flink.kubernetes.operator.crd.FlinkDeployment) Configuration(org.apache.flink.configuration.Configuration) KubernetesHaServicesFactory(org.apache.flink.kubernetes.highavailability.KubernetesHaServicesFactory) Test(org.junit.jupiter.api.Test)

Example 23 with FlinkDeployment

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));
}
Also used : FlinkDeployment(org.apache.flink.kubernetes.operator.crd.FlinkDeployment) ReconciliationStatus(org.apache.flink.kubernetes.operator.crd.status.ReconciliationStatus) Test(org.junit.jupiter.api.Test)

Example 24 with FlinkDeployment

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());
    }
}
Also used : FlinkDeployment(org.apache.flink.kubernetes.operator.crd.FlinkDeployment) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 25 with FlinkDeployment

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());
}
Also used : FlinkDeployment(org.apache.flink.kubernetes.operator.crd.FlinkDeployment) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

FlinkDeployment (org.apache.flink.kubernetes.operator.crd.FlinkDeployment)66 Test (org.junit.jupiter.api.Test)44 TestingFlinkService (org.apache.flink.kubernetes.operator.TestingFlinkService)19 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)19 Configuration (org.apache.flink.configuration.Configuration)16 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)13 Context (io.javaoperatorsdk.operator.api.reconciler.Context)11 JobStatus (org.apache.flink.kubernetes.operator.crd.status.JobStatus)9 FlinkDeploymentStatus (org.apache.flink.kubernetes.operator.crd.status.FlinkDeploymentStatus)8 FlinkOperatorConfiguration (org.apache.flink.kubernetes.operator.config.FlinkOperatorConfiguration)6 FlinkDeploymentSpec (org.apache.flink.kubernetes.operator.crd.spec.FlinkDeploymentSpec)6 DeploymentFailedException (org.apache.flink.kubernetes.operator.exception.DeploymentFailedException)5 JobID (org.apache.flink.api.common.JobID)4 TestingClusterClient (org.apache.flink.kubernetes.operator.TestingClusterClient)4 EnumSource (org.junit.jupiter.params.provider.EnumSource)4 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)3 Pod (io.fabric8.kubernetes.api.model.Pod)3 File (java.io.File)3 ArrayList (java.util.ArrayList)3 CompletableFuture (java.util.concurrent.CompletableFuture)3