Search in sources :

Example 6 with KeyToPathBuilder

use of io.fabric8.kubernetes.api.model.KeyToPathBuilder in project flink by apache.

the class FlinkConfMountDecorator method decoratePod.

private Pod decoratePod(Pod pod) {
    final List<KeyToPath> keyToPaths = getLocalLogConfFiles().stream().map(file -> new KeyToPathBuilder().withKey(file.getName()).withPath(file.getName()).build()).collect(Collectors.toList());
    keyToPaths.add(new KeyToPathBuilder().withKey(FLINK_CONF_FILENAME).withPath(FLINK_CONF_FILENAME).build());
    final Volume flinkConfVolume = new VolumeBuilder().withName(FLINK_CONF_VOLUME).withNewConfigMap().withName(getFlinkConfConfigMapName(kubernetesComponentConf.getClusterId())).withItems(keyToPaths).endConfigMap().build();
    return new PodBuilder(pod).editSpec().addNewVolumeLike(flinkConfVolume).endVolume().endSpec().build();
}
Also used : CONFIG_MAP_PREFIX(org.apache.flink.kubernetes.utils.Constants.CONFIG_MAP_PREFIX) Container(io.fabric8.kubernetes.api.model.Container) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AbstractKubernetesParameters(org.apache.flink.kubernetes.kubeclient.parameters.AbstractKubernetesParameters) TaskManagerOptions(org.apache.flink.configuration.TaskManagerOptions) CONFIG_FILE_LOG4J_NAME(org.apache.flink.kubernetes.utils.Constants.CONFIG_FILE_LOG4J_NAME) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) DeploymentOptionsInternal(org.apache.flink.configuration.DeploymentOptionsInternal) FLINK_CONF_VOLUME(org.apache.flink.kubernetes.utils.Constants.FLINK_CONF_VOLUME) Map(java.util.Map) KeyToPathBuilder(io.fabric8.kubernetes.api.model.KeyToPathBuilder) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) RestOptions(org.apache.flink.configuration.RestOptions) Preconditions.checkNotNull(org.apache.flink.util.Preconditions.checkNotNull) Volume(io.fabric8.kubernetes.api.model.Volume) FLINK_CONF_FILENAME(org.apache.flink.configuration.GlobalConfiguration.FLINK_CONF_FILENAME) PrintWriter(java.io.PrintWriter) KubernetesConfigOptions(org.apache.flink.kubernetes.configuration.KubernetesConfigOptions) KeyToPath(io.fabric8.kubernetes.api.model.KeyToPath) StringWriter(java.io.StringWriter) Configuration(org.apache.flink.configuration.Configuration) Pod(io.fabric8.kubernetes.api.model.Pod) IOException(java.io.IOException) VolumeBuilder(io.fabric8.kubernetes.api.model.VolumeBuilder) JobManagerOptions(org.apache.flink.configuration.JobManagerOptions) FlinkPod(org.apache.flink.kubernetes.kubeclient.FlinkPod) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Collectors(java.util.stream.Collectors) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) VisibleForTesting(org.apache.flink.annotation.VisibleForTesting) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) List(java.util.List) Files(org.apache.flink.shaded.guava30.com.google.common.io.Files) CONFIG_FILE_LOGBACK_NAME(org.apache.flink.kubernetes.utils.Constants.CONFIG_FILE_LOGBACK_NAME) Constants(org.apache.flink.kubernetes.utils.Constants) Collections(java.util.Collections) KeyToPath(io.fabric8.kubernetes.api.model.KeyToPath) Volume(io.fabric8.kubernetes.api.model.Volume) KeyToPathBuilder(io.fabric8.kubernetes.api.model.KeyToPathBuilder) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) VolumeBuilder(io.fabric8.kubernetes.api.model.VolumeBuilder)

Example 7 with KeyToPathBuilder

use of io.fabric8.kubernetes.api.model.KeyToPathBuilder in project flink by apache.

the class FlinkConfMountDecoratorTest method testDecoratedFlinkPodWithLog4jAndLogback.

@Test
public void testDecoratedFlinkPodWithLog4jAndLogback() throws IOException {
    KubernetesTestUtils.createTemporyFile("some data", flinkConfDir, CONFIG_FILE_LOG4J_NAME);
    KubernetesTestUtils.createTemporyFile("some data", flinkConfDir, CONFIG_FILE_LOGBACK_NAME);
    final FlinkPod resultFlinkPod = flinkConfMountDecorator.decorateFlinkPod(baseFlinkPod);
    final List<KeyToPath> expectedKeyToPaths = Arrays.asList(new KeyToPathBuilder().withKey(CONFIG_FILE_LOGBACK_NAME).withPath(CONFIG_FILE_LOGBACK_NAME).build(), new KeyToPathBuilder().withKey(CONFIG_FILE_LOG4J_NAME).withPath(CONFIG_FILE_LOG4J_NAME).build(), 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());
}
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) VolumeBuilder(io.fabric8.kubernetes.api.model.VolumeBuilder) Test(org.junit.Test)

Example 8 with KeyToPathBuilder

use of io.fabric8.kubernetes.api.model.KeyToPathBuilder in project flink by apache.

the class FlinkConfMountDecoratorTest method testDecoratedFlinkPodWithLog4j.

@Test
public void testDecoratedFlinkPodWithLog4j() throws IOException {
    KubernetesTestUtils.createTemporyFile("some data", flinkConfDir, CONFIG_FILE_LOG4J_NAME);
    final FlinkPod resultFlinkPod = flinkConfMountDecorator.decorateFlinkPod(baseFlinkPod);
    final List<KeyToPath> expectedKeyToPaths = Arrays.asList(new KeyToPathBuilder().withKey(CONFIG_FILE_LOG4J_NAME).withPath(CONFIG_FILE_LOG4J_NAME).build(), 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());
}
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) VolumeBuilder(io.fabric8.kubernetes.api.model.VolumeBuilder) Test(org.junit.Test)

Example 9 with KeyToPathBuilder

use of io.fabric8.kubernetes.api.model.KeyToPathBuilder in project flink by apache.

the class FlinkConfMountDecoratorTest method testDecoratedFlinkPodWithLogback.

@Test
public void testDecoratedFlinkPodWithLogback() throws IOException {
    KubernetesTestUtils.createTemporyFile("some data", flinkConfDir, CONFIG_FILE_LOGBACK_NAME);
    final FlinkPod resultFlinkPod = flinkConfMountDecorator.decorateFlinkPod(baseFlinkPod);
    final List<KeyToPath> expectedKeyToPaths = Arrays.asList(new KeyToPathBuilder().withKey(CONFIG_FILE_LOGBACK_NAME).withPath(CONFIG_FILE_LOGBACK_NAME).build(), 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());
}
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) VolumeBuilder(io.fabric8.kubernetes.api.model.VolumeBuilder) Test(org.junit.Test)

Aggregations

KeyToPathBuilder (io.fabric8.kubernetes.api.model.KeyToPathBuilder)9 KeyToPath (io.fabric8.kubernetes.api.model.KeyToPath)8 Volume (io.fabric8.kubernetes.api.model.Volume)8 FlinkPod (org.apache.flink.kubernetes.kubeclient.FlinkPod)8 VolumeBuilder (io.fabric8.kubernetes.api.model.VolumeBuilder)7 Test (org.junit.Test)5 PodBuilder (io.fabric8.kubernetes.api.model.PodBuilder)4 ContainerBuilder (io.fabric8.kubernetes.api.model.ContainerBuilder)3 File (java.io.File)3 ArrayList (java.util.ArrayList)3 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)2 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)2 Container (io.fabric8.kubernetes.api.model.Container)2 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)2 Pod (io.fabric8.kubernetes.api.model.Pod)2 VolumeMount (io.fabric8.kubernetes.api.model.VolumeMount)2 VolumeMountBuilder (io.fabric8.kubernetes.api.model.VolumeMountBuilder)2 IOException (java.io.IOException)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2