Search in sources :

Example 1 with FlinkConfigManager

use of org.apache.flink.kubernetes.operator.config.FlinkConfigManager 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 2 with FlinkConfigManager

use of org.apache.flink.kubernetes.operator.config.FlinkConfigManager in project flink-kubernetes-operator by apache.

the class ArtifactManagerTest method setup.

@BeforeEach
public void setup() {
    Configuration configuration = new Configuration();
    configuration.setString(KubernetesOperatorConfigOptions.OPERATOR_USER_ARTIFACTS_BASE_DIR, tempDir.toAbsolutePath().toString());
    artifactManager = new ArtifactManager(new FlinkConfigManager(configuration));
}
Also used : Configuration(org.apache.flink.configuration.Configuration) FlinkConfigManager(org.apache.flink.kubernetes.operator.config.FlinkConfigManager) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with FlinkConfigManager

use of org.apache.flink.kubernetes.operator.config.FlinkConfigManager in project flink-kubernetes-operator by apache.

the class RollbackTest method setup.

@BeforeEach
public void setup() {
    flinkService = new TestingFlinkService();
    context = flinkService.getContext();
    testController = TestUtils.createTestController(new FlinkConfigManager(new Configuration()), kubernetesClient, flinkService);
    kubernetesClient.resource(TestUtils.buildApplicationCluster()).createOrReplace();
}
Also used : Configuration(org.apache.flink.configuration.Configuration) TestingFlinkService(org.apache.flink.kubernetes.operator.TestingFlinkService) FlinkConfigManager(org.apache.flink.kubernetes.operator.config.FlinkConfigManager) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with FlinkConfigManager

use of org.apache.flink.kubernetes.operator.config.FlinkConfigManager in project flink-kubernetes-operator by apache.

the class ValidatorUtilsTest method testDiscoverValidators.

@Test
public void testDiscoverValidators() throws IOException {
    File validatorRootFolder = temporaryFolder.newFolder();
    File testValidatorFolder = new File(validatorRootFolder, VALIDATOR_NAME);
    assertTrue(testValidatorFolder.mkdirs());
    File testValidatorJar = new File("target", VALIDATOR_JAR);
    assertTrue(testValidatorJar.exists());
    Files.copy(testValidatorJar.toPath(), Paths.get(testValidatorFolder.toString(), VALIDATOR_JAR));
    Map<String, String> originalEnv = System.getenv();
    try {
        Map<String, String> systemEnv = new HashMap<>(originalEnv);
        systemEnv.put(ConfigConstants.ENV_FLINK_PLUGINS_DIR, validatorRootFolder.getPath());
        TestUtils.setEnv(systemEnv);
        assertEquals(new HashSet<>(Arrays.asList(DefaultValidator.class.getName(), TestValidator.class.getName())), ValidatorUtils.discoverValidators(new FlinkConfigManager(new Configuration())).stream().map(v -> v.getClass().getName()).collect(Collectors.toSet()));
    } finally {
        TestUtils.setEnv(originalEnv);
    }
}
Also used : DefaultValidator(org.apache.flink.kubernetes.operator.validation.DefaultValidator) TestValidator(org.apache.flink.kubernetes.operator.validation.TestValidator) Configuration(org.apache.flink.configuration.Configuration) HashMap(java.util.HashMap) FlinkConfigManager(org.apache.flink.kubernetes.operator.config.FlinkConfigManager) File(java.io.File) Test(org.junit.Test)

Example 5 with FlinkConfigManager

use of org.apache.flink.kubernetes.operator.config.FlinkConfigManager in project flink-kubernetes-operator by apache.

the class DefaultValidatorTest method testValidationWithDefaultConfig.

@Test
public void testValidationWithDefaultConfig() {
    final Configuration defaultFlinkConf = new Configuration();
    defaultFlinkConf.set(HighAvailabilityOptions.HA_MODE, KubernetesHaServicesFactory.class.getCanonicalName());
    defaultFlinkConf.set(CheckpointingOptions.CHECKPOINTS_DIRECTORY, "cpdir");
    final DefaultValidator validatorWithDefaultConfig = new DefaultValidator(new FlinkConfigManager(defaultFlinkConf));
    testSuccess(dep -> {
        dep.getSpec().setFlinkConfiguration(new HashMap<>());
        dep.getSpec().getJob().setUpgradeMode(UpgradeMode.LAST_STATE);
    }, validatorWithDefaultConfig);
}
Also used : Configuration(org.apache.flink.configuration.Configuration) FlinkConfigManager(org.apache.flink.kubernetes.operator.config.FlinkConfigManager) KubernetesHaServicesFactory(org.apache.flink.kubernetes.highavailability.KubernetesHaServicesFactory) Test(org.junit.jupiter.api.Test)

Aggregations

FlinkConfigManager (org.apache.flink.kubernetes.operator.config.FlinkConfigManager)6 Configuration (org.apache.flink.configuration.Configuration)5 BeforeEach (org.junit.jupiter.api.BeforeEach)2 Test (org.junit.jupiter.api.Test)2 Ingress (io.fabric8.kubernetes.api.model.networking.v1.Ingress)1 IngressRule (io.fabric8.kubernetes.api.model.networking.v1.IngressRule)1 File (java.io.File)1 InetAddress (java.net.InetAddress)1 InetSocketAddress (java.net.InetSocketAddress)1 HashMap (java.util.HashMap)1 KubernetesHaServicesFactory (org.apache.flink.kubernetes.highavailability.KubernetesHaServicesFactory)1 TestingFlinkService (org.apache.flink.kubernetes.operator.TestingFlinkService)1 FlinkDeployment (org.apache.flink.kubernetes.operator.crd.FlinkDeployment)1 IngressSpec (org.apache.flink.kubernetes.operator.crd.spec.IngressSpec)1 DefaultValidator (org.apache.flink.kubernetes.operator.validation.DefaultValidator)1 FlinkResourceValidator (org.apache.flink.kubernetes.operator.validation.FlinkResourceValidator)1 TestValidator (org.apache.flink.kubernetes.operator.validation.TestValidator)1 ServerBootstrap (org.apache.flink.shaded.netty4.io.netty.bootstrap.ServerBootstrap)1 Channel (org.apache.flink.shaded.netty4.io.netty.channel.Channel)1 NioEventLoopGroup (org.apache.flink.shaded.netty4.io.netty.channel.nio.NioEventLoopGroup)1