use of io.fabric8.kubernetes.api.model.KeyToPathBuilder in project flink by apache.
the class HadoopConfMountDecorator method decorateFlinkPod.
@Override
public FlinkPod decorateFlinkPod(FlinkPod flinkPod) {
Volume hadoopConfVolume;
final Optional<String> existingConfigMap = kubernetesParameters.getExistingHadoopConfigurationConfigMap();
if (existingConfigMap.isPresent()) {
hadoopConfVolume = new VolumeBuilder().withName(Constants.HADOOP_CONF_VOLUME).withNewConfigMap().withName(existingConfigMap.get()).endConfigMap().build();
} else {
final Optional<String> localHadoopConfigurationDirectory = kubernetesParameters.getLocalHadoopConfigurationDirectory();
if (!localHadoopConfigurationDirectory.isPresent()) {
return flinkPod;
}
final List<File> hadoopConfigurationFileItems = getHadoopConfigurationFileItems(localHadoopConfigurationDirectory.get());
if (hadoopConfigurationFileItems.isEmpty()) {
LOG.warn("Found 0 files in directory {}, skip to mount the Hadoop Configuration ConfigMap.", localHadoopConfigurationDirectory.get());
return flinkPod;
}
final List<KeyToPath> keyToPaths = hadoopConfigurationFileItems.stream().map(file -> new KeyToPathBuilder().withKey(file.getName()).withPath(file.getName()).build()).collect(Collectors.toList());
hadoopConfVolume = new VolumeBuilder().withName(Constants.HADOOP_CONF_VOLUME).withNewConfigMap().withName(getHadoopConfConfigMapName(kubernetesParameters.getClusterId())).withItems(keyToPaths).endConfigMap().build();
}
final Pod podWithHadoopConf = new PodBuilder(flinkPod.getPodWithoutMainContainer()).editOrNewSpec().addNewVolumeLike(hadoopConfVolume).endVolume().endSpec().build();
final Container containerWithHadoopConf = new ContainerBuilder(flinkPod.getMainContainer()).addNewVolumeMount().withName(Constants.HADOOP_CONF_VOLUME).withMountPath(Constants.HADOOP_CONF_DIR_IN_POD).endVolumeMount().addNewEnv().withName(Constants.ENV_HADOOP_CONF_DIR).withValue(Constants.HADOOP_CONF_DIR_IN_POD).endEnv().build();
return new FlinkPod.Builder(flinkPod).withPod(podWithHadoopConf).withMainContainer(containerWithHadoopConf).build();
}
use of io.fabric8.kubernetes.api.model.KeyToPathBuilder in project flink by apache.
the class KerberosMountDecorator method decorateFlinkPod.
@Override
public FlinkPod decorateFlinkPod(FlinkPod flinkPod) {
PodBuilder podBuilder = new PodBuilder(flinkPod.getPodWithoutMainContainer());
ContainerBuilder containerBuilder = new ContainerBuilder(flinkPod.getMainContainer());
if (!StringUtils.isNullOrWhitespaceOnly(securityConfig.getKeytab()) && !StringUtils.isNullOrWhitespaceOnly(securityConfig.getPrincipal())) {
podBuilder = podBuilder.editOrNewSpec().addNewVolume().withName(Constants.KERBEROS_KEYTAB_VOLUME).withNewSecret().withSecretName(getKerberosKeytabSecretName(kubernetesParameters.getClusterId())).endSecret().endVolume().endSpec();
containerBuilder = containerBuilder.addNewVolumeMount().withName(Constants.KERBEROS_KEYTAB_VOLUME).withMountPath(Constants.KERBEROS_KEYTAB_MOUNT_POINT).endVolumeMount();
}
if (!StringUtils.isNullOrWhitespaceOnly(kubernetesParameters.getFlinkConfiguration().get(SecurityOptions.KERBEROS_KRB5_PATH))) {
final File krb5Conf = new File(kubernetesParameters.getFlinkConfiguration().get(SecurityOptions.KERBEROS_KRB5_PATH));
podBuilder = podBuilder.editOrNewSpec().addNewVolume().withName(Constants.KERBEROS_KRB5CONF_VOLUME).withNewConfigMap().withName(getKerberosKrb5confConfigMapName(kubernetesParameters.getClusterId())).withItems(new KeyToPathBuilder().withKey(krb5Conf.getName()).withPath(KERBEROS_KRB5CONF_FILE).build()).endConfigMap().endVolume().endSpec();
containerBuilder = containerBuilder.addNewVolumeMount().withName(Constants.KERBEROS_KRB5CONF_VOLUME).withMountPath(Constants.KERBEROS_KRB5CONF_MOUNT_DIR + "/" + KERBEROS_KRB5CONF_FILE).withSubPath(KERBEROS_KRB5CONF_FILE).endVolumeMount();
}
return new FlinkPod(podBuilder.build(), containerBuilder.build());
}
use of io.fabric8.kubernetes.api.model.KeyToPathBuilder in project flink by apache.
the class PodTemplateMountDecorator method decoratePod.
private Pod decoratePod(Pod pod) {
final List<KeyToPath> keyToPaths = new ArrayList<>();
keyToPaths.add(new KeyToPathBuilder().withKey(TASK_MANAGER_POD_TEMPLATE_FILE_NAME).withPath(TASK_MANAGER_POD_TEMPLATE_FILE_NAME).build());
final Volume podTemplateVolume = new VolumeBuilder().withName(POD_TEMPLATE_VOLUME).withNewConfigMap().withName(podTemplateConfigMapName).withItems(keyToPaths).endConfigMap().build();
return new PodBuilder(pod).editSpec().addNewVolumeLike(podTemplateVolume).endVolume().endSpec().build();
}
use of io.fabric8.kubernetes.api.model.KeyToPathBuilder in project flink by apache.
the class PodTemplateMountDecoratorTest method testDecoratedFlinkPodWithTaskManagerPodTemplate.
@Test
public void testDecoratedFlinkPodWithTaskManagerPodTemplate() throws Exception {
KubernetesTestUtils.createTemporyFile(POD_TEMPLATE_DATA, flinkConfDir, POD_TEMPLATE_FILE_NAME);
final FlinkPod resultFlinkPod = podTemplateMountDecorator.decorateFlinkPod(baseFlinkPod);
final List<KeyToPath> expectedKeyToPaths = Collections.singletonList(new KeyToPathBuilder().withKey(TASK_MANAGER_POD_TEMPLATE_FILE_NAME).withPath(TASK_MANAGER_POD_TEMPLATE_FILE_NAME).build());
final List<Volume> expectedVolumes = getExpectedVolumes(expectedKeyToPaths);
assertThat(resultFlinkPod.getPodWithoutMainContainer().getSpec().getVolumes(), containsInAnyOrder(expectedVolumes.toArray()));
final List<VolumeMount> expectedVolumeMounts = Collections.singletonList(new VolumeMountBuilder().withName(Constants.POD_TEMPLATE_VOLUME).withMountPath(Constants.POD_TEMPLATE_DIR_IN_POD).build());
assertThat(resultFlinkPod.getMainContainer().getVolumeMounts(), containsInAnyOrder(expectedVolumeMounts.toArray()));
}
use of io.fabric8.kubernetes.api.model.KeyToPathBuilder 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());
}
Aggregations