Search in sources :

Example 21 with FlinkPod

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

the class KubernetesUtilsTest method testLoadPodFromTemplateAndCheckVolumes.

@Test
public void testLoadPodFromTemplateAndCheckVolumes() {
    final FlinkPod flinkPod = KubernetesUtils.loadPodFromTemplateFile(flinkKubeClient, KubernetesPodTemplateTestUtils.getPodTemplateFile(), KubernetesPodTemplateTestUtils.TESTING_MAIN_CONTAINER_NAME);
    assertThat(flinkPod.getPodWithoutMainContainer().getSpec().getVolumes(), containsInAnyOrder(KubernetesPodTemplateTestUtils.createVolumes()));
}
Also used : FlinkPod(org.apache.flink.kubernetes.kubeclient.FlinkPod) Test(org.junit.Test)

Example 22 with FlinkPod

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

the class KubernetesUtilsTest method testLoadPodFromTemplateAndCheckSideCarContainer.

@Test
public void testLoadPodFromTemplateAndCheckSideCarContainer() {
    final FlinkPod flinkPod = KubernetesUtils.loadPodFromTemplateFile(flinkKubeClient, KubernetesPodTemplateTestUtils.getPodTemplateFile(), KubernetesPodTemplateTestUtils.TESTING_MAIN_CONTAINER_NAME);
    assertThat(flinkPod.getPodWithoutMainContainer().getSpec().getContainers().size(), is(1));
    assertThat(flinkPod.getPodWithoutMainContainer().getSpec().getContainers().get(0), is(KubernetesPodTemplateTestUtils.createSideCarContainer()));
}
Also used : FlinkPod(org.apache.flink.kubernetes.kubeclient.FlinkPod) Test(org.junit.Test)

Example 23 with FlinkPod

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

the class KubernetesUtilsTest method testLoadPodFromTemplateAndCheckMainContainer.

@Test
public void testLoadPodFromTemplateAndCheckMainContainer() {
    final FlinkPod flinkPod = KubernetesUtils.loadPodFromTemplateFile(flinkKubeClient, KubernetesPodTemplateTestUtils.getPodTemplateFile(), KubernetesPodTemplateTestUtils.TESTING_MAIN_CONTAINER_NAME);
    assertThat(flinkPod.getMainContainer().getName(), is(KubernetesPodTemplateTestUtils.TESTING_MAIN_CONTAINER_NAME));
    assertThat(flinkPod.getMainContainer().getVolumeMounts(), containsInAnyOrder(KubernetesPodTemplateTestUtils.createVolumeMount()));
}
Also used : FlinkPod(org.apache.flink.kubernetes.kubeclient.FlinkPod) Test(org.junit.Test)

Example 24 with FlinkPod

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

the class FlinkConfMountDecorator method decorateFlinkPod.

@Override
public FlinkPod decorateFlinkPod(FlinkPod flinkPod) {
    final Pod mountedPod = decoratePod(flinkPod.getPodWithoutMainContainer());
    final Container mountedMainContainer = new ContainerBuilder(flinkPod.getMainContainer()).addNewVolumeMount().withName(FLINK_CONF_VOLUME).withMountPath(kubernetesComponentConf.getFlinkConfDirInPod()).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)

Example 25 with FlinkPod

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

the class InitJobManagerDecorator method decorateFlinkPod.

@Override
public FlinkPod decorateFlinkPod(FlinkPod flinkPod) {
    final PodBuilder basicPodBuilder = new PodBuilder(flinkPod.getPodWithoutMainContainer());
    // Overwrite fields
    final String serviceAccountName = KubernetesUtils.resolveUserDefinedValue(flinkConfig, KubernetesConfigOptions.JOB_MANAGER_SERVICE_ACCOUNT, kubernetesJobManagerParameters.getServiceAccount(), KubernetesUtils.getServiceAccount(flinkPod), "service account");
    if (flinkPod.getPodWithoutMainContainer().getSpec().getRestartPolicy() != null) {
        logger.info("The restart policy of JobManager pod will be overwritten to 'always' " + "since it is controlled by the Kubernetes deployment.");
    }
    basicPodBuilder.withApiVersion(API_VERSION).editOrNewSpec().withServiceAccount(serviceAccountName).withServiceAccountName(serviceAccountName).withHostNetwork(kubernetesJobManagerParameters.isHostNetworkEnabled()).withDnsPolicy(kubernetesJobManagerParameters.isHostNetworkEnabled() ? DNS_PLOICY_HOSTNETWORK : DNS_PLOICY_DEFAULT).endSpec();
    // Merge fields
    basicPodBuilder.editOrNewMetadata().addToLabels(kubernetesJobManagerParameters.getLabels()).addToAnnotations(kubernetesJobManagerParameters.getAnnotations()).endMetadata().editOrNewSpec().addToImagePullSecrets(kubernetesJobManagerParameters.getImagePullSecrets()).addToNodeSelector(kubernetesJobManagerParameters.getNodeSelector()).addAllToTolerations(kubernetesJobManagerParameters.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 : EnvVar(io.fabric8.kubernetes.api.model.EnvVar) Arrays(java.util.Arrays) Container(io.fabric8.kubernetes.api.model.Container) DNS_PLOICY_DEFAULT(org.apache.flink.kubernetes.utils.Constants.DNS_PLOICY_DEFAULT) POD_IP_FIELD_PATH(org.apache.flink.kubernetes.utils.Constants.POD_IP_FIELD_PATH) ResourceRequirements(io.fabric8.kubernetes.api.model.ResourceRequirements) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) ENV_FLINK_POD_IP_ADDRESS(org.apache.flink.kubernetes.utils.Constants.ENV_FLINK_POD_IP_ADDRESS) EnvVarSourceBuilder(io.fabric8.kubernetes.api.model.EnvVarSourceBuilder) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) Preconditions.checkNotNull(org.apache.flink.util.Preconditions.checkNotNull) KubernetesJobManagerParameters(org.apache.flink.kubernetes.kubeclient.parameters.KubernetesJobManagerParameters) KubernetesUtils(org.apache.flink.kubernetes.utils.KubernetesUtils) KubernetesConfigOptions(org.apache.flink.kubernetes.configuration.KubernetesConfigOptions) Configuration(org.apache.flink.configuration.Configuration) EnvVarBuilder(io.fabric8.kubernetes.api.model.EnvVarBuilder) FlinkPod(org.apache.flink.kubernetes.kubeclient.FlinkPod) Collectors(java.util.stream.Collectors) ContainerPort(io.fabric8.kubernetes.api.model.ContainerPort) List(java.util.List) KubernetesToleration(org.apache.flink.kubernetes.kubeclient.resources.KubernetesToleration) Optional(java.util.Optional) DNS_PLOICY_HOSTNETWORK(org.apache.flink.kubernetes.utils.Constants.DNS_PLOICY_HOSTNETWORK) Constants(org.apache.flink.kubernetes.utils.Constants) ContainerPortBuilder(io.fabric8.kubernetes.api.model.ContainerPortBuilder) Collections(java.util.Collections) API_VERSION(org.apache.flink.kubernetes.utils.Constants.API_VERSION) Container(io.fabric8.kubernetes.api.model.Container) FlinkPod(org.apache.flink.kubernetes.kubeclient.FlinkPod) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder)

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