@Override public void eventReceived(Action action, ReplicationController resource) { logger.info("{}: {}", action, resource.getMetadata().getResourceVersion()); }
@Override public void create(String kubeName, String namespace, ReplicationController controller, Map<String, String> labels) throws RepositoryException { if (labels != null) { final Map<String, String> currentLabels = controller.getMetadata().getLabels(); currentLabels.putAll(labels); controller.getMetadata().setLabels(currentLabels); } this.create(kubeName, namespace, controller); }
@Override public void create(String kubeName, String namespace, ReplicationController replController) throws RepositoryException { if (LOGGER.isLoggable(Level.CONFIG) ) { LOGGER.config("Creating Replication Controller: " + replController.getMetadata().getName() ); } kubeRepository.getClient(kubeName).replicationControllers().inNamespace(namespace).create(replController); }
/** * 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); }
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(); }; }
@Override ReplicationController applyResource(ReplicationController original, ReplicationController current) { return client .replicationControllers() .inNamespace(getNamespace()) .withName(current.getMetadata().getName()) .edit() .withMetadata(current.getMetadata()) .withSpec(current.getSpec()) .done(); }
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); } } };
@Override public void delete(String kubeName, String namespace, ReplicationController replController) throws RepositoryException { String replControllerName = replController.getMetadata().getName(); if (LOGGER.isLoggable(Level.CONFIG) ) { LOGGER.config("Deleting Replication Controller and associated Pods: " + replControllerName); } final KubernetesClient client = kubeRepository.getClient(kubeName); client.replicationControllers().inNamespace(namespace).withName(replControllerName).scale(0, true); client.replicationControllers().inNamespace(namespace).delete(replController); } }
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); } }
@Test public void testReplicationControllersInjection() { assertNotNull(controllerList); assertEquals(1, controllerList.getItems().size()); assertEquals("test-controller", controllerList.getItems().get(0).getMetadata().getName()); assertNotNull(controller); assertEquals("test-controller", controller.getMetadata().getName()); assertNotNull(controller); assertEquals("test-controller-second", controllerInSecondaryNamespace.getMetadata().getName()); assertEquals("test-secondary-namespace", controllerInSecondaryNamespace.getMetadata().getNamespace()); } }
/** * 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 ReplicationControllerFluentImpl(ReplicationController instance){ this.withApiVersion(instance.getApiVersion()); this.withKind(instance.getKind()); this.withMetadata(instance.getMetadata()); this.withSpec(instance.getSpec()); this.withStatus(instance.getStatus()); }
public ReplicationControllerBuilder( ReplicationControllerFluent<?> fluent , ReplicationController instance ){ this.fluent = fluent; fluent.withApiVersion(instance.getApiVersion()); fluent.withKind(instance.getKind()); fluent.withMetadata(instance.getMetadata()); fluent.withSpec(instance.getSpec()); fluent.withStatus(instance.getStatus()); } public ReplicationControllerBuilder( ReplicationController instance ){
public ReplicationControllerBuilder( ReplicationController instance ){ this.fluent = this; this.withApiVersion(instance.getApiVersion()); this.withKind(instance.getKind()); this.withMetadata(instance.getMetadata()); this.withSpec(instance.getSpec()); this.withStatus(instance.getStatus()); }
public ReplicationControllerBuilder(ReplicationControllerFluent<?> fluent,ReplicationController instance,Boolean validationEnabled){ this.fluent = fluent; fluent.withApiVersion(instance.getApiVersion()); fluent.withKind(instance.getKind()); fluent.withMetadata(instance.getMetadata()); fluent.withSpec(instance.getSpec()); fluent.withStatus(instance.getStatus()); this.validationEnabled = validationEnabled; } public ReplicationControllerBuilder(ReplicationController instance){
public ReplicationControllerBuilder(ReplicationController instance,Boolean validationEnabled){ this.fluent = this; this.withApiVersion(instance.getApiVersion()); this.withKind(instance.getKind()); this.withMetadata(instance.getMetadata()); this.withSpec(instance.getSpec()); this.withStatus(instance.getStatus()); this.validationEnabled = validationEnabled; }
public ReplicationControllerBuilder( ReplicationControllerFluent<?> fluent , ReplicationController instance ){ this.fluent = fluent; fluent.withApiVersion(instance.getApiVersion()); fluent.withKind(instance.getKind()); fluent.withMetadata(instance.getMetadata()); fluent.withSpec(instance.getSpec()); fluent.withStatus(instance.getStatus()); } public ReplicationControllerBuilder( ReplicationController instance ){
public ReplicationControllerBuilder( ReplicationController instance ){ this.fluent = this; this.withApiVersion(instance.getApiVersion()); this.withKind(instance.getKind()); this.withMetadata(instance.getMetadata()); this.withSpec(instance.getSpec()); this.withStatus(instance.getStatus()); }
version); if (replicationController.isPresent()) { podName = replicationController.get().getMetadata().getAnnotations().get(DEPLOYER_POD_NAME_ANNOTATION); if (podName != null) { final Pod deployerPod = getPod(podName);