public DoneableContainer(Container item){ super(item);this.builder=new ContainerBuilder(this, item);this.function=new Function<Container, Container>() { public Container apply(Container item) { return item; } } ; }
public DoneableContainer(Function<Container,Container> function){ super();this.builder=new ContainerBuilder(this);this.function=function; } public DoneableContainer(Container item,Function<Container,Container> function){
@Override public StatefulSet updateImage(String image) { StatefulSet oldRC = get(); if (oldRC == null) { throw new KubernetesClientException("Existing StatefulSet doesn't exist"); } if (oldRC.getSpec().getTemplate().getSpec().getContainers().size() > 1) { throw new KubernetesClientException("Image update is not supported for multicontainer pods"); } if (oldRC.getSpec().getTemplate().getSpec().getContainers().size() == 0) { throw new KubernetesClientException("Pod has no containers!"); } Container updatedContainer = new ContainerBuilder(oldRC.getSpec().getTemplate().getSpec().getContainers().iterator().next()).withImage(image).build(); StatefulSetBuilder newRCBuilder = new StatefulSetBuilder(oldRC); newRCBuilder.editMetadata().withResourceVersion(null).endMetadata() .editSpec().editTemplate().editSpec().withContainers(Collections.singletonList(updatedContainer)) .endSpec().endTemplate().endSpec(); return new StatefulSetRollingUpdater(client, config, namespace).rollUpdate(oldRC, newRCBuilder.build()); }
@Override public ReplicaSet updateImage(String image) { ReplicaSet oldRC = get(); if (oldRC == null) { throw new KubernetesClientException("Existing replica set doesn't exist"); } if (oldRC.getSpec().getTemplate().getSpec().getContainers().size() > 1) { throw new KubernetesClientException("Image update is not supported for multicontainer pods"); } if (oldRC.getSpec().getTemplate().getSpec().getContainers().size() == 0) { throw new KubernetesClientException("Pod has no containers!"); } Container updatedContainer = new ContainerBuilder(oldRC.getSpec().getTemplate().getSpec().getContainers().iterator().next()).withImage(image).build(); ReplicaSetBuilder newRCBuilder = new ReplicaSetBuilder(oldRC); newRCBuilder.editMetadata().withResourceVersion(null).endMetadata() .editSpec().editTemplate().editSpec().withContainers(Collections.singletonList(updatedContainer)) .endSpec().endTemplate().endSpec(); return new ReplicaSetRollingUpdater(client, config, namespace).rollUpdate(oldRC, newRCBuilder.build()); }
@Override public ReplicationController updateImage(String image) { ReplicationController oldRC = get(); if (oldRC == null) { throw new KubernetesClientException("Existing replication controller doesn't exist"); } if (oldRC.getSpec().getTemplate().getSpec().getContainers().size() > 1) { throw new KubernetesClientException("Image update is not supported for multicontainer pods"); } if (oldRC.getSpec().getTemplate().getSpec().getContainers().size() == 0) { throw new KubernetesClientException("Pod has no containers!"); } Container updatedContainer = new ContainerBuilder(oldRC.getSpec().getTemplate().getSpec().getContainers().iterator().next()).withImage(image).build(); ReplicationControllerBuilder newRCBuilder = new ReplicationControllerBuilder(oldRC); newRCBuilder.editMetadata().withResourceVersion(null).endMetadata() .editSpec().editTemplate().editSpec().withContainers(Collections.singletonList(updatedContainer)) .endSpec().endTemplate().endSpec(); return new ReplicationControllerRollingUpdater(client, config, namespace).rollUpdate(oldRC, newRCBuilder.build()); }
public T addToContainers( Container item){ if (item != null) {ContainerBuilder builder = new ContainerBuilder(item);_visitables.add(builder);this.containers.add(builder);} return (T)this; } public List<Container> getContainers(){
public T addToContainers( Container item){ if (item != null) {ContainerBuilder builder = new ContainerBuilder(item);_visitables.add(builder);this.containers.add(builder);} return (T)this; } public List<Container> getContainers(){
public A removeFromContainers(Container... items){ for (Container item : items) {ContainerBuilder builder = new ContainerBuilder(item);_visitables.remove(builder);this.containers.remove(builder);} return (A)this; }
public static void main(String args[]) throws InterruptedException { String master = "https://192.168.99.100:8443/"; if (args.length == 1) { master = args[0]; } log("Using master with url ", master); Config config = new ConfigBuilder().withMasterUrl(master).build(); try (final KubernetesClient client = new DefaultKubernetesClient(config)) { PriorityClass priorityClass = new PriorityClassBuilder() .withNewMetadata().withName("high-priority").endMetadata() .withValue(new Integer(100000)) .withGlobalDefault(false) .withDescription("This priority class should be used for XYZ service pods only.") .build(); client.scheduling().priorityClass().create(priorityClass); client.pods().inNamespace("default").create(new PodBuilder() .withNewMetadata().withName("nginx").withLabels(Collections.singletonMap("env", "test")).endMetadata() .withNewSpec() .addToContainers(new ContainerBuilder().withName("nginx").withImage("nginx").withImagePullPolicy("IfNotPresent").build()) .withPriorityClassName("high-priority") .endSpec() .build() ); } catch (KubernetesClientException e) { e.printStackTrace(); log("Could not create resource", e.getMessage()); } }
@Override protected List<Container> getContainers() { List<Container> containers = new ArrayList<>(); Container container = new ContainerBuilder() .withName(name) .withImage(getImage()) .withEnv(getEnvVars()) .withPorts(getContainerPortList()) .withVolumeMounts(getVolumeMounts()) .withResources(ModelUtils.resources(getResources())) .build(); containers.add(container); return containers; }
private Container createInitContainer() { return new ContainerBuilder() .withName(getConfig(Config.pemToJKSInitContainerName)) .withImage(getConfig(Config.pemToJKSInitContainerImage)) .withImagePullPolicy("IfNotPresent") .withArgs(createArgsArray()) .withVolumeMounts(createMounts()) .build(); }
private Container createInitContainer() { return new ContainerBuilder() .withName(getConfig(Config.pemToJKSInitContainerName)) .withImage(getConfig(Config.pemToJKSInitContainerImage)) .withImagePullPolicy("IfNotPresent") .withArgs(createArgsArray()) .withVolumeMounts(createMounts()) .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(); }
@Override protected List<Container> getContainers() { return Collections.singletonList(new ContainerBuilder() .withName(USER_OPERATOR_CONTAINER_NAME) .withImage(getImage()) .withEnv(getEnvVars()) .withPorts(singletonList(createContainerPort(HEALTHCHECK_PORT_NAME, HEALTHCHECK_PORT, "TCP"))) .withLivenessProbe(createHttpProbe(livenessPath + "healthy", HEALTHCHECK_PORT_NAME, livenessInitialDelay, livenessTimeout)) .withReadinessProbe(createHttpProbe(readinessPath + "ready", HEALTHCHECK_PORT_NAME, readinessInitialDelay, readinessTimeout)) .withResources(ModelUtils.resources(getResources())) .withVolumeMounts(getVolumeMounts()) .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(); }
@Override protected List<Container> getContainers() { return Collections.singletonList(new ContainerBuilder() .withName(TOPIC_OPERATOR_CONTAINER_NAME) .withImage(getImage()) .withEnv(getEnvVars()) .withPorts(singletonList(createContainerPort(HEALTHCHECK_PORT_NAME, HEALTHCHECK_PORT, "TCP"))) .withLivenessProbe(createHttpProbe(livenessPath + "healthy", HEALTHCHECK_PORT_NAME, livenessInitialDelay, livenessTimeout)) .withReadinessProbe(createHttpProbe(readinessPath + "ready", HEALTHCHECK_PORT_NAME, readinessInitialDelay, readinessTimeout)) .withResources(ModelUtils.resources(getResources())) .withVolumeMounts(getVolumeMounts()) .build()); }
private Container generateContainer(JobModel jobModel) { return new ContainerBuilder() .withName(jobModel.getName()) .withImage(jobModel.getImage()) .withImagePullPolicy(jobModel.getImagePullPolicy()) .withEnv(populateEnvVar(jobModel.getEnv())) .build(); }
private ContainerBuilder containerBuilder() { return new ContainerBuilder().withNewSecurityContext().endSecurityContext().withNewResources() .withLimits(ImmutableMap.of("cpu", new Quantity(), "memory", new Quantity())) .withRequests(ImmutableMap.of("cpu", new Quantity(), "memory", new Quantity())).endResources(); }
private Container generateContainer(DeploymentModel deploymentModel, List<ContainerPort> containerPorts) { return new ContainerBuilder() .withName(deploymentModel.getName()) .withImage(deploymentModel.getImage()) .withImagePullPolicy(deploymentModel.getImagePullPolicy()) .withPorts(containerPorts) .withEnv(populateEnvVar(deploymentModel.getEnv())) .withVolumeMounts(populateVolumeMounts(deploymentModel)) .withLivenessProbe(generateLivenessProbe(deploymentModel)) .build(); }
@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()); }