Search in sources :

Example 26 with FlinkDeployment

use of org.apache.flink.kubernetes.operator.crd.FlinkDeployment in project flink-kubernetes-operator by apache.

the class FlinkDeploymentControllerTest method cleanUpNewDeployment.

@Test
public void cleanUpNewDeployment() {
    FlinkDeployment flinkDeployment = TestUtils.buildApplicationCluster();
    var deleteControl = testController.cleanup(flinkDeployment, context);
    assertNotNull(deleteControl);
}
Also used : FlinkDeployment(org.apache.flink.kubernetes.operator.crd.FlinkDeployment) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 27 with FlinkDeployment

use of org.apache.flink.kubernetes.operator.crd.FlinkDeployment in project flink-kubernetes-operator by apache.

the class FlinkDeploymentControllerTest method verifyInProgressDeploymentWithCrashLoopBackoff.

@Test
public void verifyInProgressDeploymentWithCrashLoopBackoff() throws Exception {
    String crashLoopMessage = "container fails";
    var validatingResponseProvider = new TestUtils.ValidatingResponseProvider<>(new EventBuilder().withNewMetadata().endMetadata().build(), r -> {
        String recordedRequestBody = r.getBody().readUtf8();
        assertTrue(recordedRequestBody.contains(DeploymentFailedException.REASON_CRASH_LOOP_BACKOFF));
        assertTrue(recordedRequestBody.contains(crashLoopMessage));
    });
    mockServer.expect().post().withPath("/api/v1/namespaces/flink-operator-test/events").andReply(validatingResponseProvider).once();
    flinkService.setJmPodList(TestUtils.createFailedPodList(crashLoopMessage));
    FlinkDeployment appCluster = TestUtils.buildApplicationCluster();
    UpdateControl<FlinkDeployment> updateControl;
    testController.reconcile(appCluster, context);
    updateControl = testController.reconcile(appCluster, TestUtils.createContextWithInProgressDeployment());
    assertFalse(updateControl.isUpdateStatus());
    assertEquals(Optional.of(configManager.getOperatorConfiguration().getReconcileInterval().toMillis()), updateControl.getScheduleDelay());
    assertEquals(JobManagerDeploymentStatus.ERROR, appCluster.getStatus().getJobManagerDeploymentStatus());
    assertEquals(org.apache.flink.api.common.JobStatus.RECONCILING.name(), appCluster.getStatus().getJobStatus().getState());
    // Validate status status
    assertNotNull(appCluster.getStatus().getError());
    // next cycle should not create another event
    updateControl = testController.reconcile(appCluster, TestUtils.createContextWithFailedJobManagerDeployment());
    assertEquals(JobManagerDeploymentStatus.ERROR, appCluster.getStatus().getJobManagerDeploymentStatus());
    assertFalse(updateControl.isUpdateStatus());
    assertEquals(JobManagerDeploymentStatus.READY.rescheduleAfter(appCluster, configManager.getOperatorConfiguration()).toMillis(), updateControl.getScheduleDelay().get());
    validatingResponseProvider.assertValidated();
}
Also used : EventBuilder(io.fabric8.kubernetes.api.model.EventBuilder) FlinkDeployment(org.apache.flink.kubernetes.operator.crd.FlinkDeployment) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 28 with FlinkDeployment

use of org.apache.flink.kubernetes.operator.crd.FlinkDeployment in project flink-kubernetes-operator by apache.

the class FlinkDeploymentControllerTest method testSuccessfulObservationShouldClearErrors.

@Test
public void testSuccessfulObservationShouldClearErrors() throws Exception {
    final String crashLoopMessage = "deploy errors";
    flinkService.setJmPodList(TestUtils.createFailedPodList(crashLoopMessage));
    FlinkDeployment appCluster = TestUtils.buildApplicationCluster();
    testController.reconcile(appCluster, context);
    testController.reconcile(appCluster, TestUtils.createContextWithInProgressDeployment());
    assertNull(appCluster.getStatus().getReconciliationStatus().getLastStableSpec());
    // Failed JobManager deployment should set errors to the status
    assertEquals(JobManagerDeploymentStatus.ERROR, appCluster.getStatus().getJobManagerDeploymentStatus());
    assertEquals(crashLoopMessage, appCluster.getStatus().getError());
    // JobManager deployment becomes ready and successful observation should clear the errors
    testController.reconcile(appCluster, context);
    assertNull(appCluster.getStatus().getReconciliationStatus().getLastStableSpec());
    testController.reconcile(appCluster, context);
    assertEquals(JobManagerDeploymentStatus.READY, appCluster.getStatus().getJobManagerDeploymentStatus());
    assertNull(appCluster.getStatus().getError());
    assertEquals(appCluster.getStatus().getReconciliationStatus().getLastReconciledSpec(), appCluster.getStatus().getReconciliationStatus().getLastStableSpec());
}
Also used : FlinkDeployment(org.apache.flink.kubernetes.operator.crd.FlinkDeployment) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 29 with FlinkDeployment

use of org.apache.flink.kubernetes.operator.crd.FlinkDeployment in project flink-kubernetes-operator by apache.

the class FlinkDeploymentControllerTest method verifyFailedDeployment.

@Test
public void verifyFailedDeployment() throws Exception {
    var validatingResponseProvider = new TestUtils.ValidatingResponseProvider<>(new EventBuilder().withNewMetadata().endMetadata().build(), r -> {
        assertTrue(r.getBody().readUtf8().contains(TestUtils.DEPLOYMENT_ERROR));
    });
    mockServer.expect().post().withPath("/api/v1/namespaces/flink-operator-test/events").andReply(validatingResponseProvider).once();
    FlinkDeployment appCluster = TestUtils.buildApplicationCluster();
    UpdateControl<FlinkDeployment> updateControl;
    testController.reconcile(appCluster, context);
    updateControl = testController.reconcile(appCluster, TestUtils.createContextWithFailedJobManagerDeployment());
    assertFalse(updateControl.isUpdateStatus());
    assertEquals(Optional.of(configManager.getOperatorConfiguration().getReconcileInterval().toMillis()), updateControl.getScheduleDelay());
    assertEquals(JobManagerDeploymentStatus.ERROR, appCluster.getStatus().getJobManagerDeploymentStatus());
    validatingResponseProvider.assertValidated();
    // Validate status
    assertNotNull(appCluster.getStatus().getError());
    // next cycle should not create another event
    updateControl = testController.reconcile(appCluster, TestUtils.createContextWithFailedJobManagerDeployment());
    assertEquals(JobManagerDeploymentStatus.ERROR, appCluster.getStatus().getJobManagerDeploymentStatus());
    assertFalse(updateControl.isUpdateStatus());
    assertEquals(JobManagerDeploymentStatus.ERROR.rescheduleAfter(appCluster, configManager.getOperatorConfiguration()).toMillis(), updateControl.getScheduleDelay().get());
}
Also used : EventBuilder(io.fabric8.kubernetes.api.model.EventBuilder) FlinkDeployment(org.apache.flink.kubernetes.operator.crd.FlinkDeployment) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 30 with FlinkDeployment

use of org.apache.flink.kubernetes.operator.crd.FlinkDeployment in project flink-kubernetes-operator by apache.

the class FlinkOperatorITCase method test.

@Test
public void test() {
    FlinkDeployment flinkDeployment = buildSessionCluster();
    LOG.info("Deploying {}", flinkDeployment.getMetadata().getName());
    client.resource(flinkDeployment).createOrReplace();
    await().atMost(1, MINUTES).untilAsserted(() -> {
        assertThat(client.apps().deployments().inNamespace(TEST_NAMESPACE).withName(flinkDeployment.getMetadata().getName()).isReady(), is(true));
    });
}
Also used : FlinkDeployment(org.apache.flink.kubernetes.operator.crd.FlinkDeployment) Test(org.junit.jupiter.api.Test)

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