private List<Container> generateInitContainer(DeploymentModel deploymentModel) throws KubernetesPluginException { List<Container> initContainers = new ArrayList<>(); for (String dependsOn : deploymentModel.getDependsOn()) { String serviceName = KubernetesContext.getInstance().getServiceName(dependsOn); List<String> commands = new ArrayList<>(); commands.add("sh"); commands.add("-c"); commands.add("until nslookup " + serviceName + "; do echo waiting for " + serviceName + "; sleep 2; done;"); initContainers.add(new ContainerBuilder() .withName("wait-for-" + serviceName) .withImage("busybox") .withCommand(commands) .build()); } return initContainers; }
/** * For StatefulSets, create an init container to parse ${HOSTNAME} to get the `instance.index` and write it to * config/application.properties on a shared volume so the main container has it. Using the legacy annotation * configuration since the current client version does not directly support InitContainers. * * Since 1.8 the annotation method has been removed, and the initContainer API is supported since 1.6 * * @return a container definition with the above mentioned configuration */ private Container createInitContainer() { List<String> command = new LinkedList<>(); String commandString = String .format("%s && %s", setIndexProperty("INSTANCE_INDEX"), setIndexProperty("spring.application.index")); command.add("sh"); command.add("-c"); command.add(commandString); return new ContainerBuilder().withName("index-provider") .withImage("busybox") .withImagePullPolicy("IfNotPresent") .withCommand(command) .withVolumeMounts(new VolumeMountBuilder().withName("config").withMountPath("/config").build()) .build(); }
container.withCommand(containerCommand);
private Container createPvInitContainer(PodSpec podSpec) { Map<String, String> mountPoints = extractMountPoints(podSpec); return new ContainerBuilder() .withName(ENRICHER_NAME) .withImage("busybox") .withImagePullPolicy("IfNotPresent") .withCommand(createChmodCommandArray(mountPoints)) .withVolumeMounts(createMounts(mountPoints)) .build(); }
private Container createPvInitContainer(PodSpec podSpec) { Map<String, String> mountPoints = extractMountPoints(podSpec); return new ContainerBuilder() .withName(ENRICHER_NAME) .withImage("busybox") .withImagePullPolicy("IfNotPresent") .withCommand(createChmodCommandArray(mountPoints)) .withVolumeMounts(createMounts(mountPoints)) .build(); }
.withEnv(env) .withWorkingDir(buildWorkspace) .withCommand(split(c.getCommand())) .withArgs(split(c.getArgs())) .withTty(c.isTtyEnabled())
.addToEnv(envVars) .addToPorts(ports) .withCommand(parseDockerCommand(containerTemplate.getCommand())) .withArgs(arguments) .withLivenessProbe(livenessProbe)
public ContainerBuilder( Container instance ){ this.fluent = this; this.withArgs(instance.getArgs()); this.withCommand(instance.getCommand()); this.withEnv(instance.getEnv()); this.withImage(instance.getImage()); this.withImagePullPolicy(instance.getImagePullPolicy()); this.withLifecycle(instance.getLifecycle()); this.withLivenessProbe(instance.getLivenessProbe()); this.withName(instance.getName()); this.withPorts(instance.getPorts()); this.withReadinessProbe(instance.getReadinessProbe()); this.withResources(instance.getResources()); this.withSecurityContext(instance.getSecurityContext()); this.withTerminationMessagePath(instance.getTerminationMessagePath()); this.withVolumeMounts(instance.getVolumeMounts()); this.withWorkingDir(instance.getWorkingDir()); }
public ContainerBuilder( Container instance ){ this.fluent = this; this.withArgs(instance.getArgs()); this.withCapabilities(instance.getCapabilities()); this.withCommand(instance.getCommand()); this.withEnv(instance.getEnv()); this.withImage(instance.getImage()); this.withImagePullPolicy(instance.getImagePullPolicy()); this.withLifecycle(instance.getLifecycle()); this.withLivenessProbe(instance.getLivenessProbe()); this.withName(instance.getName()); this.withPorts(instance.getPorts()); this.withPrivileged(instance.getPrivileged()); this.withReadinessProbe(instance.getReadinessProbe()); this.withResources(instance.getResources()); this.withSecurityContext(instance.getSecurityContext()); this.withTerminationMessagePath(instance.getTerminationMessagePath()); this.withVolumeMounts(instance.getVolumeMounts()); this.withWorkingDir(instance.getWorkingDir()); }
@Before public void configureCloud() throws Exception { client = setupCloud(this).connect(); deletePods(client, getLabels(this), false); String image = "busybox"; Container c = new ContainerBuilder().withName(image).withImagePullPolicy("IfNotPresent").withImage(image) .withCommand("cat").withTty(true).build(); String podName = "test-command-execution-" + RandomStringUtils.random(5, "bcdfghjklmnpqrstvwxz0123456789"); pod = client.pods().create(new PodBuilder().withNewMetadata().withName(podName).withLabels(getLabels(this)) .endMetadata().withNewSpec().withContainers(c).endSpec().build()); System.out.println("Created pod: " + pod.getMetadata().getName()); decorator = new ContainerExecDecorator(client, pod.getMetadata().getName(), image, client.getNamespace()); }
public ContainerBuilder(Container instance,Boolean validationEnabled){ this.fluent = this; this.withArgs(instance.getArgs()); this.withCommand(instance.getCommand()); this.withEnv(instance.getEnv()); this.withImage(instance.getImage()); this.withImagePullPolicy(instance.getImagePullPolicy()); this.withLifecycle(instance.getLifecycle()); this.withLivenessProbe(instance.getLivenessProbe()); this.withName(instance.getName()); this.withPorts(instance.getPorts()); this.withReadinessProbe(instance.getReadinessProbe()); this.withResources(instance.getResources()); this.withSecurityContext(instance.getSecurityContext()); this.withStdin(instance.getStdin()); this.withStdinOnce(instance.getStdinOnce()); this.withTerminationMessagePath(instance.getTerminationMessagePath()); this.withTty(instance.getTty()); this.withVolumeMounts(instance.getVolumeMounts()); this.withWorkingDir(instance.getWorkingDir()); this.validationEnabled = validationEnabled; }