Search in sources :

Example 1 with FlinkPod

use of org.apache.flink.kubernetes.kubeclient.FlinkPod 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();
}
Also used : Arrays(java.util.Arrays) Container(io.fabric8.kubernetes.api.model.Container) FileUtils(org.apache.flink.util.FileUtils) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AbstractKubernetesParameters(org.apache.flink.kubernetes.kubeclient.parameters.AbstractKubernetesParameters) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) Map(java.util.Map) KeyToPathBuilder(io.fabric8.kubernetes.api.model.KeyToPathBuilder) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) Preconditions.checkNotNull(org.apache.flink.util.Preconditions.checkNotNull) Volume(io.fabric8.kubernetes.api.model.Volume) KeyToPath(io.fabric8.kubernetes.api.model.KeyToPath) Logger(org.slf4j.Logger) Pod(io.fabric8.kubernetes.api.model.Pod) IOException(java.io.IOException) VolumeBuilder(io.fabric8.kubernetes.api.model.VolumeBuilder) FlinkPod(org.apache.flink.kubernetes.kubeclient.FlinkPod) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Collectors(java.util.stream.Collectors) File(java.io.File) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) List(java.util.List) Optional(java.util.Optional) Constants(org.apache.flink.kubernetes.utils.Constants) Collections(java.util.Collections) Pod(io.fabric8.kubernetes.api.model.Pod) FlinkPod(org.apache.flink.kubernetes.kubeclient.FlinkPod) FlinkPod(org.apache.flink.kubernetes.kubeclient.FlinkPod) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) VolumeBuilder(io.fabric8.kubernetes.api.model.VolumeBuilder) KeyToPath(io.fabric8.kubernetes.api.model.KeyToPath) Container(io.fabric8.kubernetes.api.model.Container) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) Volume(io.fabric8.kubernetes.api.model.Volume) KeyToPathBuilder(io.fabric8.kubernetes.api.model.KeyToPathBuilder) File(java.io.File)

Example 2 with FlinkPod

use of org.apache.flink.kubernetes.kubeclient.FlinkPod 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());
}
Also used : ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) FlinkPod(org.apache.flink.kubernetes.kubeclient.FlinkPod) KeyToPathBuilder(io.fabric8.kubernetes.api.model.KeyToPathBuilder) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) File(java.io.File)

Example 3 with FlinkPod

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

the class MountSecretsDecorator method decorateFlinkPod.

@Override
public FlinkPod decorateFlinkPod(FlinkPod flinkPod) {
    final Pod podWithMount = decoratePod(flinkPod.getPodWithoutMainContainer());
    final Container containerWithMount = decorateMainContainer(flinkPod.getMainContainer());
    return new FlinkPod.Builder(flinkPod).withPod(podWithMount).withMainContainer(containerWithMount).build();
}
Also used : Container(io.fabric8.kubernetes.api.model.Container) Pod(io.fabric8.kubernetes.api.model.Pod) FlinkPod(org.apache.flink.kubernetes.kubeclient.FlinkPod) FlinkPod(org.apache.flink.kubernetes.kubeclient.FlinkPod)

Example 4 with FlinkPod

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

the class KubernetesJobManagerFactory method buildKubernetesJobManagerSpecification.

public static KubernetesJobManagerSpecification buildKubernetesJobManagerSpecification(FlinkPod podTemplate, KubernetesJobManagerParameters kubernetesJobManagerParameters) throws IOException {
    FlinkPod flinkPod = Preconditions.checkNotNull(podTemplate).copy();
    List<HasMetadata> accompanyingResources = new ArrayList<>();
    final KubernetesStepDecorator[] stepDecorators = new KubernetesStepDecorator[] { new InitJobManagerDecorator(kubernetesJobManagerParameters), new EnvSecretsDecorator(kubernetesJobManagerParameters), new MountSecretsDecorator(kubernetesJobManagerParameters), new CmdJobManagerDecorator(kubernetesJobManagerParameters), new InternalServiceDecorator(kubernetesJobManagerParameters), new ExternalServiceDecorator(kubernetesJobManagerParameters), new HadoopConfMountDecorator(kubernetesJobManagerParameters), new KerberosMountDecorator(kubernetesJobManagerParameters), new FlinkConfMountDecorator(kubernetesJobManagerParameters), new PodTemplateMountDecorator(kubernetesJobManagerParameters) };
    for (KubernetesStepDecorator stepDecorator : stepDecorators) {
        flinkPod = stepDecorator.decorateFlinkPod(flinkPod);
        accompanyingResources.addAll(stepDecorator.buildAccompanyingKubernetesResources());
    }
    final Deployment deployment = createJobManagerDeployment(flinkPod, kubernetesJobManagerParameters);
    return new KubernetesJobManagerSpecification(deployment, accompanyingResources);
}
Also used : InternalServiceDecorator(org.apache.flink.kubernetes.kubeclient.decorators.InternalServiceDecorator) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) KubernetesStepDecorator(org.apache.flink.kubernetes.kubeclient.decorators.KubernetesStepDecorator) EnvSecretsDecorator(org.apache.flink.kubernetes.kubeclient.decorators.EnvSecretsDecorator) FlinkPod(org.apache.flink.kubernetes.kubeclient.FlinkPod) InitJobManagerDecorator(org.apache.flink.kubernetes.kubeclient.decorators.InitJobManagerDecorator) ArrayList(java.util.ArrayList) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) PodTemplateMountDecorator(org.apache.flink.kubernetes.kubeclient.decorators.PodTemplateMountDecorator) FlinkConfMountDecorator(org.apache.flink.kubernetes.kubeclient.decorators.FlinkConfMountDecorator) HadoopConfMountDecorator(org.apache.flink.kubernetes.kubeclient.decorators.HadoopConfMountDecorator) CmdJobManagerDecorator(org.apache.flink.kubernetes.kubeclient.decorators.CmdJobManagerDecorator) KerberosMountDecorator(org.apache.flink.kubernetes.kubeclient.decorators.KerberosMountDecorator) ExternalServiceDecorator(org.apache.flink.kubernetes.kubeclient.decorators.ExternalServiceDecorator) KubernetesJobManagerSpecification(org.apache.flink.kubernetes.kubeclient.KubernetesJobManagerSpecification) MountSecretsDecorator(org.apache.flink.kubernetes.kubeclient.decorators.MountSecretsDecorator)

Example 5 with FlinkPod

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

the class PodTemplateMountDecorator method decorateFlinkPod.

@Override
public FlinkPod decorateFlinkPod(FlinkPod flinkPod) {
    if (!getTaskManagerPodTemplateFile().isPresent()) {
        return flinkPod;
    }
    final Pod mountedPod = decoratePod(flinkPod.getPodWithoutMainContainer());
    final Container mountedMainContainer = new ContainerBuilder(flinkPod.getMainContainer()).addNewVolumeMount().withName(POD_TEMPLATE_VOLUME).withMountPath(POD_TEMPLATE_DIR_IN_POD).endVolumeMount().build();
    return new FlinkPod.Builder(flinkPod).withPod(mountedPod).withMainContainer(mountedMainContainer).build();
}
Also used : Container(io.fabric8.kubernetes.api.model.Container) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) Pod(io.fabric8.kubernetes.api.model.Pod) FlinkPod(org.apache.flink.kubernetes.kubeclient.FlinkPod) FlinkPod(org.apache.flink.kubernetes.kubeclient.FlinkPod)

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