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);
}
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());
}
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());
}
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());
}
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());
}
Aggregations