Search in sources :

Example 1 with DNS_PLOICY_DEFAULT

use of org.apache.flink.kubernetes.utils.Constants.DNS_PLOICY_DEFAULT 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)

Example 2 with DNS_PLOICY_DEFAULT

use of org.apache.flink.kubernetes.utils.Constants.DNS_PLOICY_DEFAULT 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)

Aggregations

Container (io.fabric8.kubernetes.api.model.Container)2 ContainerBuilder (io.fabric8.kubernetes.api.model.ContainerBuilder)2 ContainerPort (io.fabric8.kubernetes.api.model.ContainerPort)2 ContainerPortBuilder (io.fabric8.kubernetes.api.model.ContainerPortBuilder)2 EnvVar (io.fabric8.kubernetes.api.model.EnvVar)2 PodBuilder (io.fabric8.kubernetes.api.model.PodBuilder)2 ResourceRequirements (io.fabric8.kubernetes.api.model.ResourceRequirements)2 Collections (java.util.Collections)2 List (java.util.List)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 Configuration (org.apache.flink.configuration.Configuration)2 KubernetesConfigOptions (org.apache.flink.kubernetes.configuration.KubernetesConfigOptions)2 FlinkPod (org.apache.flink.kubernetes.kubeclient.FlinkPod)2 KubernetesToleration (org.apache.flink.kubernetes.kubeclient.resources.KubernetesToleration)2 Constants (org.apache.flink.kubernetes.utils.Constants)2 DNS_PLOICY_DEFAULT (org.apache.flink.kubernetes.utils.Constants.DNS_PLOICY_DEFAULT)2 DNS_PLOICY_HOSTNETWORK (org.apache.flink.kubernetes.utils.Constants.DNS_PLOICY_HOSTNETWORK)2 KubernetesUtils (org.apache.flink.kubernetes.utils.KubernetesUtils)2 Preconditions.checkNotNull (org.apache.flink.util.Preconditions.checkNotNull)2