public static Container fromContainerDescriptionToPodContainer( ContainerDescription description) { if (description == null) { return null; } Container podContainer = new Container(); podContainer.name = description.name; podContainer.image = description.image; podContainer.workingDir = description.workingDir; podContainer.env = fromContainerDescriptionEnvsToPodContainersEnvs(description.env); podContainer.ports = fromContainerDescriptionPortsToPodContainerPorts( description.portBindings); podContainer.livenessProbe = fromContainerDescriptionHealthConfigToPodContainerProbe (description.healthConfig); setContainerDescriptionResourcesToPodContainerResources(description, podContainer); if (!isNullOrEmpty(description.command)) { // Container hold it's command as 2 separate string arrays - one for command // and one for it's args. In this approach we assume that the command is the first // element and rest elements are it's args, for ContainerDescription's command. String[] splittedCommand = description.command[0].split(" "); podContainer.command = Collections.singletonList(splittedCommand[0]); podContainer.args = Arrays.stream(splittedCommand).skip(1) .collect(Collectors.toList()); } if (description.privileged != null) { podContainer.securityContext = new SecurityContext(); podContainer.securityContext.privileged = description.privileged; } return podContainer; }
private Container createPodContainer() { Container podContainer = new Container(); podContainer.name = CONTAINER_NAME; podContainer.image = CONTAINER_NAME; podContainer.command = Arrays.asList("app.sh"); podContainer.args = Arrays.asList("start"); podContainer.workingDir = CONTAINER_WORKING_DIR; ContainerPort port = new ContainerPort(); port.containerPort = 80; port.protocol = "TCP"; port.hostPort = 8080; podContainer.ports = Arrays.asList(port); EnvVar env = new EnvVar(); env.name = "name"; env.value = "value"; podContainer.env = Arrays.asList(env); SecurityContext ctx = new SecurityContext(); ctx.privileged = Boolean.TRUE; podContainer.securityContext = ctx; Probe probe = new Probe(); probe.tcpSocket = new TCPSocketAction(); probe.timeoutSeconds = 60; probe.failureThreshold = 3; podContainer.livenessProbe = probe; return podContainer; }