Search in sources :

Example 11 with FlinkPod

use of org.apache.flink.kubernetes.kubeclient.FlinkPod in project flink by apache.

the class CmdJobManagerDecoratorTest method testContainerIsDecorated.

@Test
public void testContainerIsDecorated() {
    flinkConfig.set(DeploymentOptions.TARGET, KubernetesDeploymentTarget.SESSION.getName());
    final FlinkPod resultFlinkPod = cmdJobManagerDecorator.decorateFlinkPod(baseFlinkPod);
    assertThat(resultFlinkPod.getPodWithoutMainContainer(), is(equalTo(baseFlinkPod.getPodWithoutMainContainer())));
    assertThat(resultFlinkPod.getMainContainer(), not(equalTo(baseFlinkPod.getMainContainer())));
}
Also used : FlinkPod(org.apache.flink.kubernetes.kubeclient.FlinkPod) Test(org.junit.Test)

Example 12 with FlinkPod

use of org.apache.flink.kubernetes.kubeclient.FlinkPod in project flink by apache.

the class HadoopConfMountDecoratorTest method testPodWithHadoopConfVolume.

@Test
public void testPodWithHadoopConfVolume() throws IOException {
    setHadoopConfDirEnv();
    generateHadoopConfFileItems();
    final FlinkPod resultFlinkPod = hadoopConfMountDecorator.decorateFlinkPod(baseFlinkPod);
    final List<Volume> resultVolumes = resultFlinkPod.getPodWithoutMainContainer().getSpec().getVolumes();
    assertEquals(1, resultVolumes.size());
    final Volume resultVolume = resultVolumes.get(0);
    assertEquals(Constants.HADOOP_CONF_VOLUME, resultVolume.getName());
    final ConfigMapVolumeSource resultVolumeConfigMap = resultVolume.getConfigMap();
    assertEquals(HadoopConfMountDecorator.getHadoopConfConfigMapName(CLUSTER_ID), resultVolumeConfigMap.getName());
    final Map<String, String> expectedKeyToPaths = new HashMap<String, String>() {

        {
            put("hdfs-site.xml", "hdfs-site.xml");
            put("core-site.xml", "core-site.xml");
        }
    };
    final Map<String, String> resultKeyToPaths = resultVolumeConfigMap.getItems().stream().collect(Collectors.toMap(KeyToPath::getKey, KeyToPath::getPath));
    assertEquals(expectedKeyToPaths, resultKeyToPaths);
}
Also used : FlinkPod(org.apache.flink.kubernetes.kubeclient.FlinkPod) Volume(io.fabric8.kubernetes.api.model.Volume) HashMap(java.util.HashMap) ConfigMapVolumeSource(io.fabric8.kubernetes.api.model.ConfigMapVolumeSource) Test(org.junit.Test)

Example 13 with FlinkPod

use of org.apache.flink.kubernetes.kubeclient.FlinkPod in project flink by apache.

the class HadoopConfMountDecoratorTest method testExistingConfigMapPrecedeOverHadoopConfEnv.

@Test
public void testExistingConfigMapPrecedeOverHadoopConfEnv() throws IOException {
    // set existing ConfigMap
    flinkConfig.set(KubernetesConfigOptions.HADOOP_CONF_CONFIG_MAP, EXISTING_HADOOP_CONF_CONFIG_MAP);
    // set HADOOP_CONF_DIR
    setHadoopConfDirEnv();
    generateHadoopConfFileItems();
    assertEquals(0, hadoopConfMountDecorator.buildAccompanyingKubernetesResources().size());
    final FlinkPod resultFlinkPod = hadoopConfMountDecorator.decorateFlinkPod(baseFlinkPod);
    final List<Volume> volumes = resultFlinkPod.getPodWithoutMainContainer().getSpec().getVolumes();
    assertTrue(volumes.stream().anyMatch(volume -> volume.getConfigMap().getName().equals(EXISTING_HADOOP_CONF_CONFIG_MAP)));
    assertFalse(volumes.stream().anyMatch(volume -> volume.getConfigMap().getName().equals(HadoopConfMountDecorator.getHadoopConfConfigMapName(CLUSTER_ID))));
}
Also used : VolumeMount(io.fabric8.kubernetes.api.model.VolumeMount) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) KubernetesConfigOptions(org.apache.flink.kubernetes.configuration.KubernetesConfigOptions) KeyToPath(io.fabric8.kubernetes.api.model.KeyToPath) KubernetesJobManagerTestBase(org.apache.flink.kubernetes.kubeclient.KubernetesJobManagerTestBase) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) HashMap(java.util.HashMap) FlinkPod(org.apache.flink.kubernetes.kubeclient.FlinkPod) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Collectors(java.util.stream.Collectors) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) Map(java.util.Map) ConfigMapVolumeSource(io.fabric8.kubernetes.api.model.ConfigMapVolumeSource) Constants(org.apache.flink.kubernetes.utils.Constants) Assert.assertEquals(org.junit.Assert.assertEquals) Volume(io.fabric8.kubernetes.api.model.Volume) FlinkPod(org.apache.flink.kubernetes.kubeclient.FlinkPod) Volume(io.fabric8.kubernetes.api.model.Volume) Test(org.junit.Test)

Example 14 with FlinkPod

use of org.apache.flink.kubernetes.kubeclient.FlinkPod in project flink by apache.

the class CmdTaskManagerDecoratorTest method testContainerIsDecorated.

@Test
public void testContainerIsDecorated() {
    final FlinkPod resultFlinkPod = cmdTaskManagerDecorator.decorateFlinkPod(this.baseFlinkPod);
    assertThat(resultFlinkPod.getPodWithoutMainContainer(), is(equalTo(baseFlinkPod.getPodWithoutMainContainer())));
    assertThat(resultFlinkPod.getMainContainer(), not(equalTo(baseFlinkPod.getMainContainer())));
}
Also used : FlinkPod(org.apache.flink.kubernetes.kubeclient.FlinkPod) Test(org.junit.Test)

Example 15 with FlinkPod

use of org.apache.flink.kubernetes.kubeclient.FlinkPod in project flink by apache.

the class FlinkConfMountDecoratorTest method testDecoratedFlinkPodWithoutLog4jAndLogback.

@Test
public void testDecoratedFlinkPodWithoutLog4jAndLogback() {
    final FlinkPod resultFlinkPod = flinkConfMountDecorator.decorateFlinkPod(baseFlinkPod);
    final List<KeyToPath> expectedKeyToPaths = Collections.singletonList(new KeyToPathBuilder().withKey(FLINK_CONF_FILENAME).withPath(FLINK_CONF_FILENAME).build());
    final List<Volume> expectedVolumes = Collections.singletonList(new VolumeBuilder().withName(Constants.FLINK_CONF_VOLUME).withNewConfigMap().withName(getFlinkConfConfigMapName(CLUSTER_ID)).withItems(expectedKeyToPaths).endConfigMap().build());
    assertEquals(expectedVolumes, resultFlinkPod.getPodWithoutMainContainer().getSpec().getVolumes());
    final List<VolumeMount> expectedVolumeMounts = Collections.singletonList(new VolumeMountBuilder().withName(Constants.FLINK_CONF_VOLUME).withMountPath(FLINK_CONF_DIR_IN_POD).build());
    assertEquals(expectedVolumeMounts, resultFlinkPod.getMainContainer().getVolumeMounts());
}
Also used : KeyToPath(io.fabric8.kubernetes.api.model.KeyToPath) FlinkPod(org.apache.flink.kubernetes.kubeclient.FlinkPod) Volume(io.fabric8.kubernetes.api.model.Volume) KeyToPathBuilder(io.fabric8.kubernetes.api.model.KeyToPathBuilder) VolumeMount(io.fabric8.kubernetes.api.model.VolumeMount) VolumeBuilder(io.fabric8.kubernetes.api.model.VolumeBuilder) VolumeMountBuilder(io.fabric8.kubernetes.api.model.VolumeMountBuilder) Test(org.junit.Test)

Aggregations

FlinkPod (org.apache.flink.kubernetes.kubeclient.FlinkPod)54 Test (org.junit.Test)35 Container (io.fabric8.kubernetes.api.model.Container)15 List (java.util.List)14 Constants (org.apache.flink.kubernetes.utils.Constants)13 HashMap (java.util.HashMap)12 Collectors (java.util.stream.Collectors)12 KubernetesConfigOptions (org.apache.flink.kubernetes.configuration.KubernetesConfigOptions)12 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)11 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)10 Volume (io.fabric8.kubernetes.api.model.Volume)10 IOException (java.io.IOException)10 Collections (java.util.Collections)10 Map (java.util.Map)10 KubernetesJobManagerSpecification (org.apache.flink.kubernetes.kubeclient.KubernetesJobManagerSpecification)9 KubernetesJobManagerTestBase (org.apache.flink.kubernetes.kubeclient.KubernetesJobManagerTestBase)9 FlinkConfMountDecorator (org.apache.flink.kubernetes.kubeclient.decorators.FlinkConfMountDecorator)9 HadoopConfMountDecorator (org.apache.flink.kubernetes.kubeclient.decorators.HadoopConfMountDecorator)9 KerberosMountDecorator (org.apache.flink.kubernetes.kubeclient.decorators.KerberosMountDecorator)9 Assert.assertEquals (org.junit.Assert.assertEquals)9