use of io.kubernetes.client.models.V1VolumeMount 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;
}
use of io.kubernetes.client.models.V1VolumeMount in project incubator-heron by apache.
the class AppsV1beta1Controller method mountVolumeIfPresent.
private void mountVolumeIfPresent(V1Container container) {
final Config config = getConfiguration();
if (KubernetesContext.hasContainerVolume(config)) {
final V1VolumeMount mount = new V1VolumeMount().name(KubernetesContext.getContainerVolumeName(config)).mountPath(KubernetesContext.getContainerVolumeMountPath(config));
container.volumeMounts(Collections.singletonList(mount));
}
}
Aggregations