Search in sources :

Example 1 with V1ContainerPort

use of io.kubernetes.client.models.V1ContainerPort in project twister2 by DSC-SPIDAL.

the class KubernetesUtils method constructContainer.

/**
 * construct a container
 * @param containerIndex
 * @param reqContainer
 * @param jobFileSize
 * @param containerPort
 * @param config
 * @return
 */
public static V1Container constructContainer(int containerIndex, ResourceContainer reqContainer, long jobFileSize, int containerPort, Config config) {
    // construct container and add it to podSpec
    V1Container container = new V1Container();
    String containerName = createContainerName(containerIndex);
    container.setName(containerName);
    container.setImage(TWISTER2_DOCKER_IMAGE);
    // by default: IfNotPresent
    // can be set to Always from client.yaml
    container.setImagePullPolicy(KubernetesContext.imagePullPolicy(config));
    // container.setArgs(Arrays.asList("1000000")); parameter to the main method
    // container.setCommand(Arrays.asList("java", TWISTER2_WORKER_CLASS));
    V1EnvVar var1 = new V1EnvVar().name(KubernetesField.JOB_PACKAGE_FILENAME + "").value(SchedulerContext.jobPackageFileName(config));
    V1EnvVar var2 = new V1EnvVar().name(KubernetesField.JOB_PACKAGE_FILE_SIZE + "").value(jobFileSize + "");
    V1EnvVar var3 = new V1EnvVar().name(KubernetesField.CONTAINER_NAME + "").value(containerName);
    V1EnvVar var4 = new V1EnvVar().name(KubernetesField.USER_JOB_JAR_FILE + "").value(SchedulerContext.userJobJarFile(config));
    V1EnvVar var5 = new V1EnvVar().name(KubernetesField.JOB_DESCRIPTION_FILE + "").value(SchedulerContext.jobDescriptionFile(config));
    // POD_IP with downward API
    V1ObjectFieldSelector fieldSelector = new V1ObjectFieldSelector();
    fieldSelector.setFieldPath("status.podIP");
    V1EnvVarSource varSource = new V1EnvVarSource();
    varSource.setFieldRef(fieldSelector);
    V1EnvVar var6 = new V1EnvVar().name(KubernetesField.POD_IP + "").valueFrom(varSource);
    container.setEnv(Arrays.asList(var1, var2, var3, var4, var5, var6));
    V1ResourceRequirements resReq = new V1ResourceRequirements();
    resReq.putRequestsItem("cpu", reqContainer.getNoOfCpus() + "");
    resReq.putRequestsItem("memory", reqContainer.getMemoryMegaBytes() + "Mi");
    container.setResources(resReq);
    V1VolumeMount volumeMount = new V1VolumeMount();
    volumeMount.setName(POD_SHARED_VOLUME_NAME);
    volumeMount.setMountPath(POD_SHARED_VOLUME);
    container.setVolumeMounts(Arrays.asList(volumeMount));
    V1ContainerPort port = new V1ContainerPort().name("port1").containerPort(containerPort);
    port.setProtocol("TCP");
    container.setPorts(Arrays.asList(port));
    return container;
}
Also used : V1Container(io.kubernetes.client.models.V1Container) V1EnvVarSource(io.kubernetes.client.models.V1EnvVarSource) V1ContainerPort(io.kubernetes.client.models.V1ContainerPort) V1ObjectFieldSelector(io.kubernetes.client.models.V1ObjectFieldSelector) IntOrString(io.kubernetes.client.custom.IntOrString) V1EnvVar(io.kubernetes.client.models.V1EnvVar) V1ResourceRequirements(io.kubernetes.client.models.V1ResourceRequirements) V1VolumeMount(io.kubernetes.client.models.V1VolumeMount)

Example 2 with V1ContainerPort

use of io.kubernetes.client.models.V1ContainerPort in project incubator-heron by apache.

the class AppsV1beta1Controller method getContainerPorts.

private List<V1ContainerPort> getContainerPorts(boolean remoteDebugEnabled, int numberOfInstances) {
    List<V1ContainerPort> ports = new ArrayList<>();
    KubernetesConstants.EXECUTOR_PORTS.forEach((p, v) -> {
        final V1ContainerPort port = new V1ContainerPort();
        port.setName(p.getName());
        port.setContainerPort(v);
        ports.add(port);
    });
    if (remoteDebugEnabled) {
        IntStream.range(0, numberOfInstances).forEach(i -> {
            final String portName = KubernetesConstants.JVM_REMOTE_DEBUGGER_PORT_NAME + "-" + String.valueOf(i);
            final V1ContainerPort port = new V1ContainerPort();
            port.setName(portName);
            port.setContainerPort(KubernetesConstants.JVM_REMOTE_DEBUGGER_PORT + i);
            ports.add(port);
        });
    }
    return ports;
}
Also used : V1ContainerPort(io.kubernetes.client.models.V1ContainerPort) ArrayList(java.util.ArrayList)

Aggregations

V1ContainerPort (io.kubernetes.client.models.V1ContainerPort)2 IntOrString (io.kubernetes.client.custom.IntOrString)1 V1Container (io.kubernetes.client.models.V1Container)1 V1EnvVar (io.kubernetes.client.models.V1EnvVar)1 V1EnvVarSource (io.kubernetes.client.models.V1EnvVarSource)1 V1ObjectFieldSelector (io.kubernetes.client.models.V1ObjectFieldSelector)1 V1ResourceRequirements (io.kubernetes.client.models.V1ResourceRequirements)1 V1VolumeMount (io.kubernetes.client.models.V1VolumeMount)1 ArrayList (java.util.ArrayList)1