Search in sources :

Example 16 with Policy

use of io.fabric8.openshift.api.model.Policy 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 17 with Policy

use of io.fabric8.openshift.api.model.Policy 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

File (java.io.File)5 Test (org.junit.Test)5 ContainerBuilder (io.fabric8.kubernetes.api.model.ContainerBuilder)4 ResourceRequirements (io.fabric8.kubernetes.api.model.ResourceRequirements)4 MavenResolver (io.fabric8.maven.MavenResolver)4 Metadata (org.apache.maven.artifact.repository.metadata.Metadata)4 IOException (java.io.IOException)3 List (java.util.List)3 MapUtils.addToMapSet (io.fabric8.agent.internal.MapUtils.addToMapSet)2 Container (io.fabric8.kubernetes.api.model.Container)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 RestartPolicy (io.fabric8.maven.docker.config.RestartPolicy)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Optional (java.util.Optional)2