Java Code Examples for io.kubernetes.client.openapi.models.V1Container#setImagePullPolicy()
The following examples show how to use
io.kubernetes.client.openapi.models.V1Container#setImagePullPolicy() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JobMasterRequestObject.java From twister2 with Apache License 2.0 | 4 votes |
/** * construct a container */ public static V1Container constructContainer() { // construct container and add it to podSpec V1Container container = new V1Container(); container.setName("twister2-job-master-0"); String containerImage = KubernetesContext.twister2DockerImageForK8s(config); if (containerImage == null) { throw new RuntimeException("Container Image name is null. Config parameter: " + "twister2.resource.kubernetes.docker.image can not be null"); } container.setImage(containerImage); container.setImagePullPolicy(KubernetesContext.imagePullPolicy(config)); container.setCommand(Arrays.asList("/bin/bash")); container.setArgs(Arrays.asList("-c", "./init.sh")); int jmRam = JobMasterContext.jobMasterRAM(config) + 128; V1ResourceRequirements resReq = new V1ResourceRequirements(); resReq.putRequestsItem("cpu", new Quantity(JobMasterContext.jobMasterCpu(config) + "")); resReq.putRequestsItem("memory", new Quantity(jmRam + "Mi")); container.setResources(resReq); ArrayList<V1VolumeMount> volumeMounts = new ArrayList<>(); V1VolumeMount memoryVolumeMount = new V1VolumeMount(); memoryVolumeMount.setName(KubernetesConstants.POD_MEMORY_VOLUME_NAME); memoryVolumeMount.setMountPath(KubernetesConstants.POD_MEMORY_VOLUME); volumeMounts.add(memoryVolumeMount); if (JobMasterContext.volatileVolumeRequested(config)) { V1VolumeMount volatileVolumeMount = new V1VolumeMount(); volatileVolumeMount.setName(KubernetesConstants.POD_VOLATILE_VOLUME_NAME); volatileVolumeMount.setMountPath(KubernetesConstants.POD_VOLATILE_VOLUME); volumeMounts.add(volatileVolumeMount); } if (JobMasterContext.persistentVolumeRequested(config)) { V1VolumeMount persVolumeMount = new V1VolumeMount(); persVolumeMount.setName(KubernetesConstants.PERSISTENT_VOLUME_NAME); persVolumeMount.setMountPath(KubernetesConstants.PERSISTENT_VOLUME_MOUNT); volumeMounts.add(persVolumeMount); } container.setVolumeMounts(volumeMounts); V1ContainerPort port = new V1ContainerPort(); port.name("job-master-port"); port.containerPort(JobMasterContext.jobMasterPort(config)); port.setProtocol("TCP"); container.setPorts(Arrays.asList(port)); container.setEnv(constructEnvironmentVariables(JobMasterContext.jobMasterRAM(config))); return container; }
Example 2
Source File: AppsV1Controller.java From incubator-heron with Apache License 2.0 | 4 votes |
private V1Container getContainer(List<String> executorCommand, Resource resource, int numberOfInstances) { final Config configuration = getConfiguration(); final V1Container container = new V1Container().name("executor"); // set up the container images container.setImage(KubernetesContext.getExecutorDockerImage(configuration)); // set up the container command container.setCommand(executorCommand); if (KubernetesContext.hasImagePullPolicy(configuration)) { container.setImagePullPolicy(KubernetesContext.getKubernetesImagePullPolicy(configuration)); } // setup the environment variables for the container final V1EnvVar envVarHost = new V1EnvVar(); envVarHost.name(KubernetesConstants.ENV_HOST) .valueFrom(new V1EnvVarSource() .fieldRef(new V1ObjectFieldSelector() .fieldPath(KubernetesConstants.POD_IP))); final V1EnvVar envVarPodName = new V1EnvVar(); envVarPodName.name(KubernetesConstants.ENV_POD_NAME) .valueFrom(new V1EnvVarSource() .fieldRef(new V1ObjectFieldSelector() .fieldPath(KubernetesConstants.POD_NAME))); container.setEnv(Arrays.asList(envVarHost, envVarPodName)); // set container resources final V1ResourceRequirements resourceRequirements = new V1ResourceRequirements(); final Map<String, Quantity> requests = new HashMap<>(); requests.put(KubernetesConstants.MEMORY, Quantity.fromString(KubernetesUtils.Megabytes(resource.getRam()))); requests.put(KubernetesConstants.CPU, Quantity.fromString(Double.toString(roundDecimal(resource.getCpu(), 3)))); resourceRequirements.setRequests(requests); container.setResources(resourceRequirements); // set container ports final boolean debuggingEnabled = TopologyUtils.getTopologyRemoteDebuggingEnabled( Runtime.topology(getRuntimeConfiguration())); container.setPorts(getContainerPorts(debuggingEnabled, numberOfInstances)); // setup volume mounts mountVolumeIfPresent(container); return container; }