Search in sources :

Example 26 with FlinkPod

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

the class InitTaskManagerDecorator method decorateFlinkPod.

@Override
public FlinkPod decorateFlinkPod(FlinkPod flinkPod) {
    final PodBuilder basicPodBuilder = new PodBuilder(flinkPod.getPodWithoutMainContainer());
    // Overwrite fields
    final String serviceAccountName = KubernetesUtils.resolveUserDefinedValue(flinkConfig, KubernetesConfigOptions.TASK_MANAGER_SERVICE_ACCOUNT, kubernetesTaskManagerParameters.getServiceAccount(), KubernetesUtils.getServiceAccount(flinkPod), "service account");
    if (flinkPod.getPodWithoutMainContainer().getSpec().getRestartPolicy() != null) {
        logger.info("The restart policy of TaskManager pod will be overwritten to 'never' " + "since it should not be restarted.");
    }
    basicPodBuilder.withApiVersion(Constants.API_VERSION).editOrNewMetadata().withName(kubernetesTaskManagerParameters.getPodName()).endMetadata().editOrNewSpec().withServiceAccount(serviceAccountName).withServiceAccountName(serviceAccountName).withRestartPolicy(Constants.RESTART_POLICY_OF_NEVER).withHostNetwork(kubernetesTaskManagerParameters.isHostNetworkEnabled()).withDnsPolicy(kubernetesTaskManagerParameters.isHostNetworkEnabled() ? DNS_PLOICY_HOSTNETWORK : DNS_PLOICY_DEFAULT).endSpec();
    // Merge fields
    basicPodBuilder.editOrNewMetadata().addToLabels(kubernetesTaskManagerParameters.getLabels()).addToAnnotations(kubernetesTaskManagerParameters.getAnnotations()).endMetadata().editOrNewSpec().addToImagePullSecrets(kubernetesTaskManagerParameters.getImagePullSecrets()).addToNodeSelector(kubernetesTaskManagerParameters.getNodeSelector()).addAllToTolerations(kubernetesTaskManagerParameters.getTolerations().stream().map(e -> KubernetesToleration.fromMap(e).getInternalResource()).collect(Collectors.toList())).endSpec();
    final Container basicMainContainer = decorateMainContainer(flinkPod.getMainContainer());
    return new FlinkPod.Builder(flinkPod).withPod(basicPodBuilder.build()).withMainContainer(basicMainContainer).build();
}
Also used : KubernetesUtils(org.apache.flink.kubernetes.utils.KubernetesUtils) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) KubernetesConfigOptions(org.apache.flink.kubernetes.configuration.KubernetesConfigOptions) Container(io.fabric8.kubernetes.api.model.Container) DNS_PLOICY_DEFAULT(org.apache.flink.kubernetes.utils.Constants.DNS_PLOICY_DEFAULT) Configuration(org.apache.flink.configuration.Configuration) FlinkPod(org.apache.flink.kubernetes.kubeclient.FlinkPod) Collectors(java.util.stream.Collectors) ContainerPort(io.fabric8.kubernetes.api.model.ContainerPort) List(java.util.List) ResourceRequirements(io.fabric8.kubernetes.api.model.ResourceRequirements) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) KubernetesToleration(org.apache.flink.kubernetes.kubeclient.resources.KubernetesToleration) KubernetesTaskManagerParameters(org.apache.flink.kubernetes.kubeclient.parameters.KubernetesTaskManagerParameters) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) Optional(java.util.Optional) DNS_PLOICY_HOSTNETWORK(org.apache.flink.kubernetes.utils.Constants.DNS_PLOICY_HOSTNETWORK) Preconditions.checkNotNull(org.apache.flink.util.Preconditions.checkNotNull) Constants(org.apache.flink.kubernetes.utils.Constants) ContainerPortBuilder(io.fabric8.kubernetes.api.model.ContainerPortBuilder) Collections(java.util.Collections) Container(io.fabric8.kubernetes.api.model.Container) FlinkPod(org.apache.flink.kubernetes.kubeclient.FlinkPod) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder)

Example 27 with FlinkPod

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

the class KubernetesTaskManagerFactory method buildTaskManagerKubernetesPod.

public static KubernetesPod buildTaskManagerKubernetesPod(FlinkPod podTemplate, KubernetesTaskManagerParameters kubernetesTaskManagerParameters) {
    FlinkPod flinkPod = Preconditions.checkNotNull(podTemplate).copy();
    final KubernetesStepDecorator[] stepDecorators = new KubernetesStepDecorator[] { new InitTaskManagerDecorator(kubernetesTaskManagerParameters), new EnvSecretsDecorator(kubernetesTaskManagerParameters), new MountSecretsDecorator(kubernetesTaskManagerParameters), new CmdTaskManagerDecorator(kubernetesTaskManagerParameters), new HadoopConfMountDecorator(kubernetesTaskManagerParameters), new KerberosMountDecorator(kubernetesTaskManagerParameters), new FlinkConfMountDecorator(kubernetesTaskManagerParameters) };
    for (KubernetesStepDecorator stepDecorator : stepDecorators) {
        flinkPod = stepDecorator.decorateFlinkPod(flinkPod);
    }
    final Pod resolvedPod = new PodBuilder(flinkPod.getPodWithoutMainContainer()).editOrNewSpec().addToContainers(flinkPod.getMainContainer()).endSpec().build();
    return new KubernetesPod(resolvedPod);
}
Also used : KubernetesStepDecorator(org.apache.flink.kubernetes.kubeclient.decorators.KubernetesStepDecorator) EnvSecretsDecorator(org.apache.flink.kubernetes.kubeclient.decorators.EnvSecretsDecorator) Pod(io.fabric8.kubernetes.api.model.Pod) FlinkPod(org.apache.flink.kubernetes.kubeclient.FlinkPod) KubernetesPod(org.apache.flink.kubernetes.kubeclient.resources.KubernetesPod) FlinkPod(org.apache.flink.kubernetes.kubeclient.FlinkPod) InitTaskManagerDecorator(org.apache.flink.kubernetes.kubeclient.decorators.InitTaskManagerDecorator) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) CmdTaskManagerDecorator(org.apache.flink.kubernetes.kubeclient.decorators.CmdTaskManagerDecorator) FlinkConfMountDecorator(org.apache.flink.kubernetes.kubeclient.decorators.FlinkConfMountDecorator) HadoopConfMountDecorator(org.apache.flink.kubernetes.kubeclient.decorators.HadoopConfMountDecorator) KerberosMountDecorator(org.apache.flink.kubernetes.kubeclient.decorators.KerberosMountDecorator) MountSecretsDecorator(org.apache.flink.kubernetes.kubeclient.decorators.MountSecretsDecorator) KubernetesPod(org.apache.flink.kubernetes.kubeclient.resources.KubernetesPod)

Example 28 with FlinkPod

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

the class KubernetesUtils method loadPodFromTemplateFile.

public static FlinkPod loadPodFromTemplateFile(FlinkKubeClient kubeClient, File podTemplateFile, String mainContainerName) {
    final KubernetesPod pod = kubeClient.loadPodFromTemplateFile(podTemplateFile);
    final List<Container> otherContainers = new ArrayList<>();
    Container mainContainer = null;
    for (Container container : pod.getInternalResource().getSpec().getContainers()) {
        if (mainContainerName.equals(container.getName())) {
            mainContainer = container;
        } else {
            otherContainers.add(container);
        }
    }
    if (mainContainer == null) {
        LOG.info("Could not find main container {} in pod template, using empty one to initialize.", mainContainerName);
        mainContainer = new ContainerBuilder().build();
    }
    pod.getInternalResource().getSpec().setContainers(otherContainers);
    return new FlinkPod(pod.getInternalResource(), mainContainer);
}
Also used : Container(io.fabric8.kubernetes.api.model.Container) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) FlinkPod(org.apache.flink.kubernetes.kubeclient.FlinkPod) ArrayList(java.util.ArrayList) KubernetesPod(org.apache.flink.kubernetes.kubeclient.resources.KubernetesPod)

Example 29 with FlinkPod

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

the class KerberosMountDecoratorTest method testDecoratedFlinkPodVolumes.

@Test
public void testDecoratedFlinkPodVolumes() {
    final FlinkPod resultFlinkPod = kerberosMountDecorator.decorateFlinkPod(baseFlinkPod);
    List<Volume> volumes = resultFlinkPod.getPodWithoutMainContainer().getSpec().getVolumes();
    assertEquals(2, volumes.size());
    final Volume keytabVolume = volumes.stream().filter(x -> x.getName().equals(Constants.KERBEROS_KEYTAB_VOLUME)).collect(Collectors.toList()).get(0);
    final Volume krb5ConfVolume = volumes.stream().filter(x -> x.getName().equals(Constants.KERBEROS_KRB5CONF_VOLUME)).collect(Collectors.toList()).get(0);
    assertNotNull(keytabVolume.getSecret());
    assertEquals(KerberosMountDecorator.getKerberosKeytabSecretName(testingKubernetesParameters.getClusterId()), keytabVolume.getSecret().getSecretName());
    assertNotNull(krb5ConfVolume.getConfigMap());
    assertEquals(KerberosMountDecorator.getKerberosKrb5confConfigMapName(testingKubernetesParameters.getClusterId()), krb5ConfVolume.getConfigMap().getName());
    assertEquals(1, krb5ConfVolume.getConfigMap().getItems().size());
    assertEquals(CUSTOM_KRB5_CONF_FILE, krb5ConfVolume.getConfigMap().getItems().get(0).getKey());
    assertEquals(KRB5_CONF_FILE, krb5ConfVolume.getConfigMap().getItems().get(0).getPath());
}
Also used : FlinkPod(org.apache.flink.kubernetes.kubeclient.FlinkPod) Volume(io.fabric8.kubernetes.api.model.Volume) Test(org.junit.Test) AbstractKubernetesParametersTest(org.apache.flink.kubernetes.kubeclient.parameters.AbstractKubernetesParametersTest)

Example 30 with FlinkPod

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

the class KerberosMountDecoratorTest method testWhetherPodOrContainerIsDecorated.

@Test
public void testWhetherPodOrContainerIsDecorated() {
    final FlinkPod resultFlinkPod = kerberosMountDecorator.decorateFlinkPod(baseFlinkPod);
    assertNotEquals(baseFlinkPod.getPodWithoutMainContainer(), resultFlinkPod.getPodWithoutMainContainer());
    assertNotEquals(baseFlinkPod.getMainContainer(), resultFlinkPod.getMainContainer());
}
Also used : FlinkPod(org.apache.flink.kubernetes.kubeclient.FlinkPod) Test(org.junit.Test) AbstractKubernetesParametersTest(org.apache.flink.kubernetes.kubeclient.parameters.AbstractKubernetesParametersTest)

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