@Override protected ReplicationController setReplicas(ReplicationController obj, int replicas) { return new ReplicationControllerBuilder(obj).editSpec().withReplicas(replicas).endSpec().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()); }
@Override protected ReplicationController createClone(ReplicationController obj, String newName, String newDeploymentHash) { return new ReplicationControllerBuilder(obj) .editMetadata() .withResourceVersion(null) .withName(newName) .endMetadata() .editSpec() .withReplicas(0).addToSelector(DEPLOYMENT_KEY, newDeploymentHash) .editTemplate().editMetadata().addToLabels(DEPLOYMENT_KEY, newDeploymentHash).endMetadata().endTemplate() .endSpec() .build(); }
@Test public void testResourceCompareEqualsFalse() throws Exception { final ReplicationController rc = new ReplicationControllerBuilder() .withNewMetadata().withName("repl1").withNamespace("test").endMetadata() .withNewSpec().withReplicas(2).endSpec() .build(); final KubernetesList kubeList2 = new KubernetesListBuilder(kubeList).withItems(pod, service, rc).build(); assertThat(ResourceCompare.equals(kubeList, kubeList2), is(false)); } }
public ReplicationController done(){ return function.apply(builder.build()); }
@Before public void setup() { pod = new PodBuilder().withNewMetadata().withName("pod1").withNamespace("test").and().build(); service = new ServiceBuilder() .withNewMetadata().withName("service1").withNamespace("test").and() .build(); final ReplicationController rc = new ReplicationControllerBuilder() .withNewMetadata().withName("repl1").withNamespace("test").endMetadata() .withNewSpec().withReplicas(1).endSpec() .build(); kubeList = new KubernetesListBuilder().withItems(pod, service, rc).build(); }
@Override protected ReplicationController setReplicas(ReplicationController obj, int replicas) { return new ReplicationControllerBuilder(obj).editSpec().withReplicas(replicas).endSpec().build(); }
ReplicationController rcCreating = new ReplicationControllerBuilder() .withNewMetadata().withName(rcName).withLabels(labels) .endMetadata().withSpec(rcSpec).build(); rc = getEndpoint().getKubernetesClient().replicationControllers() .inNamespace(namespaceName).create(rcCreating);
public ReplicationController getReplicationController(ResourceConfig config, List<ImageConfiguration> images) { return new ReplicationControllerBuilder() .withMetadata(createRcMetaData(config)) .withSpec(createRcSpec(config, images)) .build(); }
.endSpec() .endTemplate() .endSpec().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()); }
@Override public HasMetadata convert(HasMetadata item, boolean trimImageInContainerSpec, boolean enableAutomaticTrigger) { ReplicaSet resource = (ReplicaSet) item; ReplicationControllerBuilder builder = new ReplicationControllerBuilder(); builder.withMetadata(resource.getMetadata()); ReplicaSetSpec spec = resource.getSpec(); if (spec != null) { ReplicationControllerFluent.SpecNested<ReplicationControllerBuilder> specBuilder = builder.withNewSpec(); Integer replicas = spec.getReplicas(); if (replicas != null) { specBuilder.withReplicas(replicas); } LabelSelector selector = spec.getSelector(); if (selector != null) { Map<String, String> matchLabels = selector.getMatchLabels(); if (matchLabels != null && !matchLabels.isEmpty()) { specBuilder.withSelector(matchLabels); } } PodTemplateSpec template = spec.getTemplate(); if (template != null) { specBuilder.withTemplate(template); } specBuilder.endSpec(); } return builder.build(); } }
@Override protected ReplicationController createClone(ReplicationController obj, String newName, String newDeploymentHash) { return new ReplicationControllerBuilder(obj) .editMetadata() .withResourceVersion(null) .withName(newName) .endMetadata() .editSpec() .withReplicas(0).addToSelector(DEPLOYMENT_KEY, newDeploymentHash) .editTemplate().editMetadata().addToLabels(DEPLOYMENT_KEY, newDeploymentHash).endMetadata().endTemplate() .endSpec() .build(); }