Ejemplo n.º 1
0
 protected static void listReplicationControllers(Kubernetes kube) {
   System.out.println("Looking up replicationControllers");
   ReplicationControllerList replicationControllers =
       kube.getReplicationControllers(Kubernetes.NAMESPACE_ALL);
   List<ReplicationController> items = replicationControllers.getItems();
   for (ReplicationController item : items) {
     ReplicationControllerState desiredState = item.getDesiredState();
     if (desiredState != null) {
       System.out.println(
           "ReplicationController "
               + getId(item)
               + " labels: "
               + item.getLabels()
               + " replicas: "
               + desiredState.getReplicas()
               + " replicatorSelector: "
               + desiredState.getReplicaSelector()
               + " podTemplate: "
               + desiredState.getPodTemplate());
     } else {
       System.out.println(
           "ReplicationController "
               + getId(item)
               + " labels: "
               + item.getLabels()
               + " no desiredState");
     }
   }
   System.out.println();
 }
  @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 RollingUpdater(client, config, namespace).rollUpdate(oldRC, newRCBuilder.build());
  }