io.fabric8.kubernetes.api.model.ReplicationControllerSpec Java Examples

The following examples show how to use io.fabric8.kubernetes.api.model.ReplicationControllerSpec. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Readiness.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
public static boolean isReplicationControllerReady(ReplicationController r) {
  Utils.checkNotNull(r, "ReplicationController can't be null.");
  ReplicationControllerSpec spec = r.getSpec();
  ReplicationControllerStatus status = r.getStatus();

  if (status == null || status.getReadyReplicas() == null) {
    return false;
  }

  //Can be true in testing, so handle it to make test writing easier.
  if (spec == null || spec.getReplicas() == null) {
    return false;
  }

  return spec.getReplicas().intValue() == status.getReadyReplicas();
}
 
Example #2
Source File: ReplicationControllersList.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
private void printReplicationControllers(ReplicationControllerList replicationControllers, PrintStream out) {
    TablePrinter table = new TablePrinter();
    table.columns("id", "labels", "replicas", "replica selector");
    List<ReplicationController> items = replicationControllers.getItems();
    if (items == null) {
        items = Collections.EMPTY_LIST;
    }
    Filter<ReplicationController> filter = KubernetesHelper.createReplicationControllerFilter(filterText.getValue());
    for (ReplicationController item : items) {
        if (filter.matches(item)) {
            String id = KubernetesHelper.getName(item);
            String labels = KubernetesHelper.toLabelsString(item.getMetadata().getLabels());
            Integer replicas = null;
            ReplicationControllerSpec desiredState = item.getSpec();
            ReplicationControllerStatus currentState = item.getStatus();
            String selector = null;
            if (desiredState != null) {
                selector = KubernetesHelper.toLabelsString(desiredState.getSelector());
            }
            if (currentState != null) {
                replicas = currentState.getReplicas();
            }
            table.row(id, labels, toPositiveNonZeroText(replicas), selector);
        }
    }
    table.print();
}
 
Example #3
Source File: ReplicationControllerHandler.java    From jkube with Eclipse Public License 2.0 4 votes vote down vote up
private ReplicationControllerSpec createRcSpec(ResourceConfig config, List<ImageConfiguration> images) {
    return new ReplicationControllerSpecBuilder()
        .withReplicas(config.getReplicas())
        .withTemplate(podTemplateHandler.getPodTemplate(config,images))
        .build();
}
 
Example #4
Source File: ApplyService.java    From jkube with Eclipse Public License 2.0 4 votes vote down vote up
public void applyReplicationController(ReplicationController replicationController, String sourceName) throws Exception {
    String namespace = getNamespace();
    String id = getName(replicationController);
    Objects.requireNonNull(id, "No name for " + replicationController + " " + sourceName);
    if (isServicesOnlyMode()) {
        log.debug("Only processing Services right now so ignoring ReplicationController: " + namespace + ":" + id);
        return;
    }
    ReplicationController old = kubernetesClient.replicationControllers().inNamespace(namespace).withName(id).get();
    if (isRunning(old)) {
        if (UserConfigurationCompare.configEqual(replicationController, old)) {
            log.info("ReplicationController has not changed so not doing anything");
        } else {
            ReplicationControllerSpec newSpec = replicationController.getSpec();
            ReplicationControllerSpec oldSpec = old.getSpec();
            if (rollingUpgrade) {
                log.info("Rolling upgrade of the ReplicationController: " + namespace + "/" + id);
                // lets preserve the number of replicas currently running in the environment we are about to upgrade
                if (rollingUpgradePreserveScale && newSpec != null && oldSpec != null) {
                    Integer replicas = oldSpec.getReplicas();
                    if (replicas != null) {
                        newSpec.setReplicas(replicas);
                    }
                }
                log.info("rollingUpgradePreserveScale " + rollingUpgradePreserveScale + " new replicas is " + (newSpec != null ? newSpec.getReplicas() : "<null>"));
                kubernetesClient.replicationControllers().inNamespace(namespace).withName(id).rolling().replace(replicationController);
            } else if (isRecreateMode()) {
                log.info("Deleting ReplicationController: " + id);
                kubernetesClient.replicationControllers().inNamespace(namespace).withName(id).delete();
                doCreateReplicationController(replicationController, namespace, sourceName);
            } else {
                log.info("Updating ReplicationController from " + sourceName + " namespace " + namespace + " name " + getName(replicationController));
                try {
                    Object answer = patchService.compareAndPatchEntity(namespace, replicationController, old);
                    logGeneratedEntity("Updated replicationController: ", namespace, replicationController, answer);

                    if (deletePodsOnReplicationControllerUpdate) {
                        kubernetesClient.pods().inNamespace(namespace).withLabels(newSpec.getSelector()).delete();
                        log.info("Deleting any pods for the replication controller to ensure they use the new configuration");
                    } else {
                        log.info("Warning not deleted any pods so they could well be running with the old configuration!");
                    }
                } catch (Exception e) {
                    onApplyError("Failed to update ReplicationController from " + sourceName + ". " + e + ". " + replicationController, e);
                }
            }
        }
    } else {
        if (!isAllowCreate()) {
            log.warn("Creation disabled so not creating a ReplicationController from " + sourceName + " namespace " + namespace + " name " + getName(replicationController));
        } else {
            doCreateReplicationController(replicationController, namespace, sourceName);
        }
    }
}