Refine search
@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 void eventReceived(Action action, ReplicationController resource) { logger.info("{}: {}", action, resource.getMetadata().getResourceVersion()); }
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(); }
public ReplicationControllerFluentImpl(ReplicationController instance){ this.withApiVersion(instance.getApiVersion()); this.withKind(instance.getKind()); this.withMetadata(instance.getMetadata()); this.withSpec(instance.getSpec()); this.withStatus(instance.getStatus()); }
public void run() { try { ReplicationController rc = get(); //If the rc is gone, we shouldn't wait. if (rc == null) { if (count == 0) { queue.put(true); return; } else { queue.put(new IllegalStateException("Can't wait for ReplicationController: " + checkName(getItem()) + " in namespace: " + checkName(getItem()) + " to scale. Resource is no longer available.")); } } replicasRef.set(rc.getStatus().getReplicas()); if (Objects.equals(rc.getSpec().getReplicas(), rc.getStatus().getReplicas())) { queue.put(true); } else { LOG.debug("Only {}/{} replicas scheduled for ReplicationController: {} in namespace: {} seconds so waiting...", rc.getStatus().getReplicas(), rc.getSpec().getReplicas(), rc.getMetadata().getName(), namespace); } } catch (Throwable t) { LOG.error("Error while waiting for ReplicationController to be scaled.", t); } } };
PodTemplateSpec podTemplateSpec = NodeHelper.getPodTemplateSpec(replicationController); if (podTemplateSpec == null) { LOG.warn("Cannot instantiate replication controller: " + getName(replicationController) + " due to missing PodTemplate.PodStatus!"); continue; ReplicationControllerSpec spec = replicationController.getSpec(); if (spec != null) { Integer replicas = spec.getReplicas(); if (replicas != null && replicas > 0) { replicaCount = replicas; Map<String, String> replicaSelector = spec.getSelector(); ImmutableList<Pod> allPods = model.getPods(replicaSelector); List<Pod> pods = Filters.filter(allPods, podHasNotTerminated());
if (entity instanceof Pod) { Pod pod = (Pod) entity; log.status("Applying pod:" + getName(pod)); Set<Secret> secrets = generateSecrets(client, session, pod.getMetadata()); String serviceAccountName = pod.getSpec().getServiceAccountName(); } else if (entity instanceof Service) { Service service = (Service) entity; String serviceName = getName(service); log.status("Applying service:" + serviceName); controller.applyService(service, session.getId()); log.status("Applying replication controller:" + getName(replicationController)); Set<Secret> secrets = generateSecrets(client, session, replicationController.getSpec().getTemplate().getMetadata()); String serviceAccountName = replicationController.getSpec().getTemplate().getSpec().getServiceAccountName(); if (Strings.isNotBlank(serviceAccountName)) { generateServiceAccount(client, session, secrets, serviceAccountName);
protected void replicationControllerChanged(ReplicationController entity, boolean remove) { if (remove) { String id = getName(entity); if (Strings.isNotBlank(id)) { memoryModel.deleteReplicationController(id, KubernetesHelper.getNamespace(entity)); replicationControllerListeners.entityDeleted(id, entity); } } else { String id = memoryModel.getOrCreateId(getName(entity), NodeHelper.KIND_REPLICATION_CONTROLLER); if (entity.getMetadata().getUid() == null) { entity.getMetadata().setUid(getNamespace() + '/' + id); } memoryModel.updateReplicationController(id, entity); replicationControllerListeners.entityChanged(id, entity); } }
@Override protected int getReplicas(ReplicationController obj) { return obj.getSpec().getReplicas(); }
public void createBroker() { int desiredNumber = model.getBrokerCount() + 1; if (scalingInProgress.startWork(desiredNumber)) { try { ReplicationController replicationController = getBrokerReplicationController(); ReplicationControllerSpec spec = replicationController.getSpec(); int currentDesiredNumber = 0; if (spec != null) { currentDesiredNumber = spec.getReplicas(); } else { spec = new ReplicationControllerSpec(); replicationController.setSpec(spec); } if (desiredNumber == (currentDesiredNumber + 1)) { replicationController.getSpec().setReplicas(desiredNumber); kubernetes.replicationControllers().inNamespace(namespace).withName(getReplicationControllerId()).replace(replicationController); LOG.info("Updated Broker Replication Controller desired state from " + currentDesiredNumber + " to " + desiredNumber); } } catch (Throwable e) { LOG.error("Failed to create a Broker", e); } } }
@Override protected PodList listSelectedPods(ReplicationController obj) { return pods().inNamespace(namespace).withLabels(obj.getSpec().getSelector()).list(); }
private static EntityPatcher<ReplicationController> rcPatcher() { return (KubernetesClient client, String namespace, ReplicationController newObj, ReplicationController oldObj) -> { if (UserConfigurationCompare.configEqual(newObj, oldObj)) { return oldObj; } DoneableReplicationController entity = client.replicationControllers() .inNamespace(namespace) .withName(oldObj.getMetadata().getName()) .edit(); if (!UserConfigurationCompare.configEqual(newObj.getMetadata(), oldObj.getMetadata())) { entity.withMetadata(newObj.getMetadata()); } if(!UserConfigurationCompare.configEqual(newObj.getSpec(), oldObj.getSpec())) { entity.withSpec(newObj.getSpec()); } return entity.done(); }; }
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); 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()) {
public void destroyBroker(BrokerModel brokerModel) { int desiredNumber = model.getBrokerCount() - 1; if (scalingInProgress.startWork(desiredNumber)) { try { ReplicationController replicationController = getBrokerReplicationController(); int currentDesiredNumber = replicationController.getSpec().getReplicas(); if (desiredNumber == (currentDesiredNumber - 1)) { replicationController.getSpec().setReplicas(desiredNumber); model.remove(brokerModel); //Todo update when Kubernetes allows you to target exact pod to discard from replication controller //kubernetes.deletePod(brokerModel.getPod(),kubernetes.getNamespace()); Pod pod = brokerModel.getPod(); pod.getStatus().setStartTime("0"); //kubernetes.updateReplicationController(getReplicationControllerId(), replicationController,kubernetes.getNamespace()); LOG.info("Updated Broker Replication Controller desired state from " + currentDesiredNumber + " to " + desiredNumber + " and removed Broker " + brokerModel); } } catch (Throwable e) { LOG.error("Failed to create a Broker", e); } } }
public static PodTemplateSpec getPodTemplateSpec(ReplicationController replicationController) { if (replicationController != null) { return getPodTemplateSpec(replicationController.getSpec()); } return null; }
/** * Returns a client for the first working pod for the given replication controller */ public J4pClient clientForReplicationController(ReplicationController replicationController) { Objects.requireNonNull(replicationController, "ReplicationController"); PodList podList = kubernetes.pods().inNamespace(replicationController.getMetadata().getNamespace()).list(); List<Pod> items = null; if (podList != null) { items = podList.getItems(); } if (items == null || items.isEmpty()) { throw new IllegalArgumentException("No pods found for ReplicationController " + KubernetesHelper.summaryText(replicationController)); } List<Pod> pods = KubernetesHelper.getPodsForReplicationController(replicationController, items); return clientForPod(pods); }
/** * Returns all the clients for the first working pod for the given replication controller */ public List<J4pClient> clientsForReplicationController(ReplicationController replicationController) { List<Pod> pods = KubernetesHelper.getPodsForReplicationController(replicationController, kubernetes.pods().inNamespace(replicationController.getMetadata().getNamespace()).list().getItems()); return clientsForPod(pods); }
public static ReplicationControllerStatus getOrCreatetStatus(ReplicationController replicationController) { ReplicationControllerStatus currentState = replicationController.getStatus(); if (currentState == null) { currentState = new ReplicationControllerStatus(); replicationController.setStatus(currentState); } return currentState; }
public ReplicationControllerBuilder(){ this(new ReplicationController()); } public ReplicationControllerBuilder( ReplicationControllerFluent<?> fluent ){