public String deployReplicationController(String name, String env, RCContext context) throws Exception { List<Container> containers = getContainers(name, context); Map<String, String> podLabels = new HashMap<>(); podLabels.put("name", name + "-pod"); podLabels.putAll(context.getLabels()); PodTemplateSpec podTemplate = createPodTemplateSpec(podLabels, containers, context.getMountSecret()); Map<String, String> selector = Collections.singletonMap("name", name + "-pod"); Map<String, String> labels = Collections.singletonMap("name", name + "Controller"); ReplicationController rc = createReplicationController(name + "rc", configuration.getApiVersion(), labels, context.getReplicas(), selector, podTemplate); return client.replicationControllers() .inNamespace(configuration.getNamespace()) .create(rc) .getMetadata() .getName(); }
private ReplicationController createReplicationController(String name, String apiVersion, Map<String, String> labels, int replicas, Map<String, String> selector, PodTemplateSpec podTemplate) throws Exception { ReplicationController rc = new ReplicationController(); rc.setApiVersion(apiVersion); ObjectMeta objectMeta = new ObjectMeta(); rc.setMetadata(objectMeta); objectMeta.setName(name); objectMeta.setLabels(labels); ReplicationControllerSpec spec = new ReplicationControllerSpec(); rc.setSpec(spec); spec.setReplicas(replicas); spec.setSelector(selector); spec.setTemplate(podTemplate); return rc; }
/** * Scaling the application to given replicas * * @param applicationName name of the application to scale * @param replicas to scale the application */ public void scale(final String applicationName, final int replicas) { final ReplicationController replicationController = this.client .replicationControllers() .inNamespace(this.namespace) .withName(applicationName) .scale(replicas); final int availableReplicas = replicationController.getStatus().getAvailableReplicas(); log.info(String.format("Scaling replicas from %d to %d for application %s.", availableReplicas, replicas, applicationName)); awaitApplicationReadinessOrFail(applicationName); }
return client.pods() .inNamespace(resource.getMetadata().getNamespace()) .withLabels(((ReplicationController) resource).getSpec().getSelector()) .list(); } else if (resource instanceof ReplicaSet) {
return client.pods() .inNamespace(resource.getMetadata().getNamespace()) .withLabels(((ReplicationController) resource).getSpec().getSelector()) .list(); } else if (resource instanceof ReplicaSet) {
private void cleanDeployments(Map<String, String> labels) throws Exception { final ReplicationControllerList rcs = client.replicationControllers().inNamespace(configuration.getNamespace()).withLabels(labels).list(); try { for (ReplicationController rc : rcs.getItems()) { String rcId = getName(rc.getMetadata()); client.replicationControllers().inNamespace(configuration.getNamespace()).withName(rcId).scale(0, true); boolean exists = client.replicationControllers().inNamespace(configuration.getNamespace()).withName(rcId).delete(); log.info(String.format("ReplicationController [%s] delete: %s.", rcId, exists)); } } catch (Exception e) { log.log(Level.WARNING, String.format("Exception while deleting rc [%s]: %s", labels, e), e); } }
public <T extends HasMetadata> PodList podsOf(T resource) { if (resource instanceof Pod) { return new PodListBuilder().withItems((Pod) resource).build(); } else if (resource instanceof Endpoints) { return podsOf(client.services() .inNamespace(resource.getMetadata().getNamespace()) .withName(resource.getMetadata().getName()) .get()); } else if (resource instanceof Service) { return client.pods() .inNamespace(resource.getMetadata().getNamespace()) .withLabels(((Service) resource).getSpec().getSelector()) .list(); } else if (resource instanceof ReplicationController) { return client.pods() .inNamespace(resource.getMetadata().getNamespace()) .withLabels(((ReplicationController) resource).getSpec().getSelector()) .list(); } else if (resource instanceof ReplicaSet) { return findMatching((ReplicaSet) resource); } else if (resource instanceof Deployment) { return findMatching((Deployment) resource); } else if (resource instanceof DeploymentConfig) { return client.pods().inNamespace(resource.getMetadata().getName()).withLabel("deploymentconfig", resource.getMetadata().getName()).list(); } else { return new PodListBuilder().build(); } }
/** * Scaling the application to given replicas * * @param applicationName name of the application to scale * @param replicas to scale the application */ public void scale(final String applicationName, final int replicas) { final ReplicationController replicationController = this.client .replicationControllers() .inNamespace(this.namespace) .withName(applicationName) .scale(replicas); final int availableReplicas = replicationController.getStatus().getAvailableReplicas(); log.info(String.format("Scaling replicas from %d to %d for application %s.", availableReplicas, replicas, applicationName)); awaitApplicationReadinessOrFail(applicationName); }
for (ReplicationController replicationController : replicationControllerList.getItems()) { session.getLogger() .info("Replication controller: [" + replicationController.getMetadata().getName() + "]");
for (ReplicationController replicationController : replicationControllerList.getItems()) { session.getLogger() .info("Replication controller: [" + replicationController.getMetadata().getName() + "]");