Search in sources :

Example 16 with FlinkDeployment

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

the class ApplicationReconcilerTest method testRandomJobResultStorePath.

@Test
public void testRandomJobResultStorePath() throws Exception {
    TestingFlinkService flinkService = new TestingFlinkService();
    ApplicationReconciler reconciler = new ApplicationReconciler(kubernetesClient, flinkService, configManager);
    FlinkDeployment flinkApp = TestUtils.buildApplicationCluster();
    final String haStoragePath = "file:///flink-data/ha";
    flinkApp.getSpec().getFlinkConfiguration().put(HighAvailabilityOptions.HA_STORAGE_PATH.key(), haStoragePath);
    ObjectMeta deployMeta = flinkApp.getMetadata();
    FlinkDeploymentStatus status = flinkApp.getStatus();
    FlinkDeploymentSpec spec = flinkApp.getSpec();
    JobSpec jobSpec = spec.getJob();
    Configuration deployConfig = configManager.getDeployConfig(deployMeta, spec);
    status.getJobStatus().setState(org.apache.flink.api.common.JobStatus.FINISHED.name());
    status.setJobManagerDeploymentStatus(JobManagerDeploymentStatus.READY);
    reconciler.deployFlinkJob(deployMeta, jobSpec, status, deployConfig, Optional.empty(), false);
    String path1 = deployConfig.get(JobResultStoreOptions.STORAGE_PATH);
    Assertions.assertTrue(path1.startsWith(haStoragePath));
    status.getJobStatus().setState(org.apache.flink.api.common.JobStatus.FINISHED.name());
    status.setJobManagerDeploymentStatus(JobManagerDeploymentStatus.READY);
    reconciler.deployFlinkJob(deployMeta, jobSpec, status, deployConfig, Optional.empty(), false);
    String path2 = deployConfig.get(JobResultStoreOptions.STORAGE_PATH);
    Assertions.assertTrue(path2.startsWith(haStoragePath));
    assertNotEquals(path1, path2);
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) FlinkDeployment(org.apache.flink.kubernetes.operator.crd.FlinkDeployment) FlinkDeploymentStatus(org.apache.flink.kubernetes.operator.crd.status.FlinkDeploymentStatus) FlinkDeploymentSpec(org.apache.flink.kubernetes.operator.crd.spec.FlinkDeploymentSpec) Configuration(org.apache.flink.configuration.Configuration) TestingFlinkService(org.apache.flink.kubernetes.operator.TestingFlinkService) JobSpec(org.apache.flink.kubernetes.operator.crd.spec.JobSpec) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 17 with FlinkDeployment

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

the class SessionReconcilerTest method testStartSession.

@Test
public void testStartSession() throws Exception {
    Context context = TestUtils.createEmptyContext();
    var count = new AtomicInteger(0);
    TestingFlinkService flinkService = new TestingFlinkService() {

        @Override
        public void submitSessionCluster(Configuration conf) {
            super.submitSessionCluster(conf);
            count.addAndGet(1);
        }
    };
    SessionReconciler reconciler = new SessionReconciler(null, flinkService, configManager);
    FlinkDeployment deployment = TestUtils.buildSessionCluster();
    reconciler.reconcile(deployment, context);
    assertEquals(1, count.get());
}
Also used : Context(io.javaoperatorsdk.operator.api.reconciler.Context) FlinkDeployment(org.apache.flink.kubernetes.operator.crd.FlinkDeployment) Configuration(org.apache.flink.configuration.Configuration) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestingFlinkService(org.apache.flink.kubernetes.operator.TestingFlinkService) Test(org.junit.jupiter.api.Test)

Example 18 with FlinkDeployment

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

the class FlinkServiceTest method testCancelJobWithStatelessUpgradeMode.

@Test
public void testCancelJobWithStatelessUpgradeMode() throws Exception {
    final TestingClusterClient<String> testingClusterClient = new TestingClusterClient<>(configuration, TestUtils.TEST_DEPLOYMENT_NAME);
    final CompletableFuture<JobID> cancelFuture = new CompletableFuture<>();
    testingClusterClient.setCancelFunction(jobID -> {
        cancelFuture.complete(jobID);
        return CompletableFuture.completedFuture(Acknowledge.get());
    });
    final FlinkService flinkService = createFlinkService(testingClusterClient);
    JobID jobID = JobID.generate();
    FlinkDeployment deployment = TestUtils.buildApplicationCluster();
    JobStatus jobStatus = deployment.getStatus().getJobStatus();
    jobStatus.setJobId(jobID.toHexString());
    ReconciliationUtils.updateForSpecReconciliationSuccess(deployment, JobState.RUNNING);
    deployment.getStatus().setJobManagerDeploymentStatus(JobManagerDeploymentStatus.READY);
    deployment.getStatus().getJobStatus().setState("RUNNING");
    flinkService.cancelJob(deployment, UpgradeMode.STATELESS);
    assertTrue(cancelFuture.isDone());
    assertEquals(jobID, cancelFuture.get());
    assertNull(jobStatus.getSavepointInfo().getLastSavepoint());
}
Also used : JobStatus(org.apache.flink.kubernetes.operator.crd.status.JobStatus) CompletableFuture(java.util.concurrent.CompletableFuture) FlinkDeployment(org.apache.flink.kubernetes.operator.crd.FlinkDeployment) TestingClusterClient(org.apache.flink.kubernetes.operator.TestingClusterClient) JobID(org.apache.flink.api.common.JobID) Test(org.junit.jupiter.api.Test)

Example 19 with FlinkDeployment

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

the class IngressUtilsTest method testIngress.

@Test
public void testIngress() {
    FlinkDeployment appCluster = TestUtils.buildApplicationCluster();
    Configuration config = new FlinkConfigManager(new Configuration()).getDeployConfig(appCluster.getMetadata(), appCluster.getSpec());
    // no ingress when ingressDomain is empty
    IngressUtils.updateIngressRules(appCluster.getMetadata(), appCluster.getSpec(), config, client);
    assertNull(client.network().v1().ingresses().inNamespace(appCluster.getMetadata().getNamespace()).withName(appCluster.getMetadata().getName()).get());
    // host based routing
    IngressSpec.IngressSpecBuilder builder = IngressSpec.builder();
    builder.template("{{name}}.{{namespace}}.example.com");
    appCluster.getSpec().setIngress(builder.build());
    IngressUtils.updateIngressRules(appCluster.getMetadata(), appCluster.getSpec(), config, client);
    Ingress ingress = client.network().v1().ingresses().inNamespace(appCluster.getMetadata().getNamespace()).withName(appCluster.getMetadata().getName()).get();
    List<IngressRule> rules = ingress.getSpec().getRules();
    assertEquals(1, rules.size());
    assertEquals(appCluster.getMetadata().getName() + "." + appCluster.getMetadata().getNamespace() + ".example.com", rules.get(0).getHost());
    assertNull(rules.get(0).getHttp().getPaths().get(0).getPath());
    // path based routing
    builder.template("/{{namespace}}/{{name}}(/|$)(.*)");
    builder.className("nginx");
    builder.annotations(Map.of("nginx.ingress.kubernetes.io/rewrite-target", "/$2"));
    appCluster.getSpec().setIngress(builder.build());
    IngressUtils.updateIngressRules(appCluster.getMetadata(), appCluster.getSpec(), config, client);
    ingress = client.network().v1().ingresses().inNamespace(appCluster.getMetadata().getNamespace()).withName(appCluster.getMetadata().getName()).get();
    rules = ingress.getSpec().getRules();
    assertEquals(1, rules.size());
    assertNull(rules.get(0).getHost());
    assertEquals(1, rules.get(0).getHttp().getPaths().size());
    assertEquals("/" + appCluster.getMetadata().getNamespace() + "/" + appCluster.getMetadata().getName() + "(/|$)(.*)", rules.get(0).getHttp().getPaths().get(0).getPath());
    assertEquals(Map.of("nginx.ingress.kubernetes.io/rewrite-target", "/$2"), ingress.getMetadata().getAnnotations());
    assertEquals("nginx", ingress.getSpec().getIngressClassName());
    // host + path based routing
    builder.template("example.com/{{namespace}}/{{name}}(/|$)(.*)");
    builder.className("nginx");
    appCluster.getSpec().setIngress(builder.build());
    IngressUtils.updateIngressRules(appCluster.getMetadata(), appCluster.getSpec(), config, client);
    ingress = client.network().v1().ingresses().inNamespace(appCluster.getMetadata().getNamespace()).withName(appCluster.getMetadata().getName()).get();
    rules = ingress.getSpec().getRules();
    assertEquals(1, rules.size());
    assertEquals(1, rules.get(0).getHttp().getPaths().size());
    assertEquals("/" + appCluster.getMetadata().getNamespace() + "/" + appCluster.getMetadata().getName() + "(/|$)(.*)", rules.get(0).getHttp().getPaths().get(0).getPath());
    assertEquals(Map.of("nginx.ingress.kubernetes.io/rewrite-target", "/$2"), ingress.getMetadata().getAnnotations());
    assertEquals("nginx", ingress.getSpec().getIngressClassName());
}
Also used : IngressSpec(org.apache.flink.kubernetes.operator.crd.spec.IngressSpec) FlinkDeployment(org.apache.flink.kubernetes.operator.crd.FlinkDeployment) IngressRule(io.fabric8.kubernetes.api.model.networking.v1.IngressRule) Configuration(org.apache.flink.configuration.Configuration) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) FlinkConfigManager(org.apache.flink.kubernetes.operator.config.FlinkConfigManager) Test(org.junit.jupiter.api.Test)

Example 20 with FlinkDeployment

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

the class ReconciliationUtilsTest method testRescheduleUpgradeImmediately.

@Test
public void testRescheduleUpgradeImmediately() {
    FlinkDeployment app = TestUtils.buildApplicationCluster();
    app.getSpec().getJob().setState(JobState.RUNNING);
    FlinkDeployment previous = ReconciliationUtils.clone(app);
    FlinkDeployment current = ReconciliationUtils.clone(app);
    current.getStatus().getReconciliationStatus().serializeAndSetLastReconciledSpec(ReconciliationUtils.clone(current.getSpec()));
    ReconciliationUtils.updateForSpecReconciliationSuccess(current, JobState.SUSPENDED);
    UpdateControl<FlinkDeployment> updateControl = ReconciliationUtils.toUpdateControl(operatorConfiguration, current, previous, true);
    assertFalse(updateControl.isUpdateResource());
    assertFalse(updateControl.isUpdateStatus());
    assertEquals(0, updateControl.getScheduleDelay().get());
    updateControl = ReconciliationUtils.toUpdateControl(operatorConfiguration, current, current, true);
    assertFalse(updateControl.isUpdateResource());
    assertFalse(updateControl.isUpdateStatus());
    assertNotEquals(0, updateControl.getScheduleDelay().get());
}
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