@Override public MixedOperation<ReplicationController, ReplicationControllerList, DoneableReplicationController, RollableScalableResource<ReplicationController, DoneableReplicationController>> replicationControllers() { return delegate.replicationControllers(); }
Config config = new ConfigBuilder().build(); try (final KubernetesClient client = new DefaultKubernetesClient(config)) { try (Watch watch = client.replicationControllers().inNamespace("default").withName("test").watch(new Watcher<ReplicationController>() { @Override public void eventReceived(Action action, ReplicationController resource) {
@Override public MixedOperation<ReplicationController, ReplicationControllerList, DoneableReplicationController, RollableScallableResource<ReplicationController, DoneableReplicationController>> replicationControllers() { return delegate.replicationControllers(); }
try (Watch watch = client.replicationControllers().inNamespace("thisisatest").withResourceVersion("0").watch(new Watcher<ReplicationController>() { @Override public void eventReceived(Action action, ReplicationController resource) { log("Created RC", client.replicationControllers().inNamespace("thisisatest").create(rc)); client.replicationControllers().inNamespace("thisisatest").createNew() .withNewMetadata().withName("nginx2-controller").addToLabels("server", "nginx").endMetadata() .withNewSpec().withReplicas(0) ReplicationController gotRc = client.replicationControllers().inNamespace("thisisatest").withName("nginx-controller").get(); log("Get RC by name in namespace", gotRc); log("Get RC by label", client.replicationControllers().withLabel("server", "nginx").list()); log("Get RC without label", client.replicationControllers().withoutLabel("server", "apache").list()); log("Get RC with label in", client.replicationControllers().withLabelIn("server", "nginx").list()); log("Get RC with label not in", client.replicationControllers().withLabelNotIn("server", "apache").list()); log("Get RC by label in namespace", client.replicationControllers().inNamespace("thisisatest").withLabel("server", "nginx").list()); client.replicationControllers().inNamespace("thisisatest").withName("nginx-controller").cascading(false).edit().editMetadata().addToLabels("new", "label").endMetadata().done(); client.replicationControllers().inNamespace("thisisatest").withName("nginx-controller").scale(8); client.replicationControllers().inNamespace("thisisatest").withName("nginx-controller").edit().editSpec().editTemplate().withNewSpec() .addNewContainer().withName("nginx").withImage("httpd")
Config config = new ConfigBuilder().withMasterUrl(master).build(); try (final KubernetesClient client = new DefaultKubernetesClient(config)) { client.replicationControllers().inNamespace("thisisatest").createNew() .withNewMetadata().withName("nginx2-controller").addToLabels("server", "nginx").endMetadata() .withNewSpec().withReplicas(0) .withNewTemplate() .withNewMetadata().addToLabels("server", "nginx2").endMetadata() .withNewSpec() .addNewContainer().withName("nginx").withImage("nginx") .addNewPort().withContainerPort(80).endPort() .endContainer() .endSpec() .endTemplate() .endSpec().done(); } catch (Exception e) { e.printStackTrace(); logger.error(e.getMessage(), e); }
/** * Returns a client for the first working pod for the given replication controller */ public J4pClient clientForReplicationController(String replicationControllerName) { ReplicationController replicationController = kubernetes.replicationControllers().withName(replicationControllerName).get(); Objects.requireNonNull(replicationController, "No ReplicationController found for name: " + replicationControllerName); return clientForReplicationController(replicationController); }
protected ReplicationController requireReplicationController(String replicationControllerName, String namespace) { ReplicationController answer = kubernetes.replicationControllers().inNamespace(namespace).withName(replicationControllerName).get(); Objects.requireNonNull(answer, "No ReplicationController found for namespace: " + namespace + " name: " + replicationControllerName); return answer; }
private void deleteReplicationController(Map<String, String> labels) { FilterWatchListDeletable<ReplicationController, ReplicationControllerList, Boolean, Watch, Watcher<ReplicationController>> replicationControllersToDelete = client.replicationControllers() .withLabels(labels); if (replicationControllersToDelete != null && replicationControllersToDelete.list().getItems() != null) { boolean replicationControllersDeleted = replicationControllersToDelete.delete(); logger.debug(String.format("ReplicationController deleted for: %s - %b", labels, replicationControllersDeleted)); } }
private ReplicationController getBrokerReplicationController() throws InterruptedException { ReplicationController running; do { running = kubernetes.replicationControllers().inNamespace(namespace).withName(getReplicationControllerId()).get(); if (running == null) { LOG.info("Waiting for ReplicationController " + getReplicationControllerId() + " to start"); Thread.sleep(5000); } } while (running == null); return running; }
@Override ReplicationController createResource(ReplicationController current) { return client .replicationControllers() .inNamespace(getNamespace()) .create(current); }
protected void doList(Exchange exchange, String operation) throws Exception { ReplicationControllerList rcList = null; String namespaceName = exchange.getIn().getHeader( KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class); if (!ObjectHelper.isEmpty(namespaceName)) { rcList = getEndpoint().getKubernetesClient() .replicationControllers().inNamespace(namespaceName).list(); } else { rcList = getEndpoint().getKubernetesClient() .replicationControllers().inAnyNamespace().list(); } MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); exchange.getOut().setBody(rcList.getItems()); }
@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); }
@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); } }
@Override public Object lookup(ArquillianResource resource, Annotation... qualifiers) { KubernetesClient client = this.clientInstance.get(); Session session = sessionInstance.get(); Map<String, String> labels = getLabels(qualifiers); if( labels.isEmpty() ) { return client.replicationControllers().inNamespace(session.getNamespace()).list(); } else { return client.replicationControllers().inNamespace(session.getNamespace()).withLabels(labels).list(); } } }
protected void doCreateReplicationController(ReplicationController replicationController, String namespace, String sourceName) { log.info("Creating a ReplicationController from " + sourceName + " namespace " + namespace + " name " + getName(replicationController)); try { Object answer; if (StringUtils.isNotBlank(namespace)) { answer = kubernetesClient.replicationControllers().inNamespace(namespace).create(replicationController); } else { answer = kubernetesClient.replicationControllers().inNamespace(getNamespace()).create(replicationController); } logGeneratedEntity("Created ReplicationController: ", namespace, replicationController, answer); } catch (Exception e) { onApplyError("Failed to create ReplicationController from " + sourceName + ". " + e + ". " + replicationController, e); } }
@Override ReplicationController getCurrentResource() { return client .replicationControllers() .inNamespace(getNamespace()) .withName(getName()) .get(); }
@Override public Object lookup(ArquillianResource resource, Annotation... qualifiers) { KubernetesClient client = this.clientInstance.get(); Session session = sessionInstance.get(); String name = getReplicationControllerName(qualifiers); return client.replicationControllers().inNamespace(session.getNamespace()).withName(name).get(); } }
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 ReplicationController applyResource(ReplicationController original, ReplicationController current) { return client .replicationControllers() .inNamespace(getNamespace()) .withName(current.getMetadata().getName()) .edit() .withMetadata(current.getMetadata()) .withSpec(current.getSpec()) .done(); }
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(); }; }