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();
}
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);
}
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);
}
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());
}
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());
}
Aggregations