@Override protected int getReplicas(ReplicaSet obj) { return obj.getSpec().getReplicas(); }
public static boolean isReplicaSetReady(ReplicaSet r) { Utils.checkNotNull(r, "ReplicationController can't be null."); ReplicaSetSpec spec = r.getSpec(); ReplicaSetStatus 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(); }
@Override protected PodList listSelectedPods(ReplicaSet obj) { FilterWatchListDeletable<Pod, PodList, Boolean, Watch, Watcher<Pod>> podLister = pods().inNamespace(namespace); if (obj.getSpec().getSelector().getMatchLabels() != null) { podLister.withLabels(obj.getSpec().getSelector().getMatchLabels()); } if (obj.getSpec().getSelector().getMatchExpressions() != null) { for (LabelSelectorRequirement req : obj.getSpec().getSelector().getMatchExpressions()) { switch (req.getOperator()) { case "In": podLister.withLabelIn(req.getKey(), req.getValues().toArray(new String[]{})); break; case "NotIn": podLister.withLabelNotIn(req.getKey(), req.getValues().toArray(new String[]{})); break; case "DoesNotExist": podLister.withoutLabel(req.getKey()); break; case "Exists": podLister.withLabel(req.getKey()); break; } } } return podLister.list(); }
@Override public ReplicaSet updateImage(String image) { ReplicaSet oldRC = get(); if (oldRC == null) { throw new KubernetesClientException("Existing replica set 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(); ReplicaSetBuilder newRCBuilder = new ReplicaSetBuilder(oldRC); newRCBuilder.editMetadata().withResourceVersion(null).endMetadata() .editSpec().editTemplate().editSpec().withContainers(Collections.singletonList(updatedContainer)) .endSpec().endTemplate().endSpec(); return new ReplicaSetRollingUpdater(client, config, namespace).rollUpdate(oldRC, newRCBuilder.build()); }
public void run() { try { ReplicaSet rc = get(); //If the rs 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 ReplicaSet: " +name + " in namespace: " + namespace + " to scale. Resource is no longer available.")); return; } } replicasRef.set(rc.getStatus().getReplicas()); long generation = rc.getMetadata().getGeneration() != null ? rc.getMetadata().getGeneration() : 0; long observedGeneration = rc.getStatus() != null && rc.getStatus().getObservedGeneration() != null ? rc.getStatus().getObservedGeneration() : -1; if (observedGeneration >= generation && Objects.equals(rc.getSpec().getReplicas(), rc.getStatus().getReplicas())) { queue.put(true); } LOG.debug("Only {}/{} replicas scheduled for ReplicaSet: {} in namespace: {} seconds so waiting...", rc.getStatus().getReplicas(), rc.getSpec().getReplicas(), rc.getMetadata().getName(), namespace); } catch (Throwable t) { LOG.error("Error while waiting for ReplicaSet to be scaled.", t); } } };
public ReplicaSetFluentImpl(ReplicaSet instance){ this.withApiVersion(instance.getApiVersion()); this.withKind(instance.getKind()); this.withMetadata(instance.getMetadata()); this.withSpec(instance.getSpec()); this.withStatus(instance.getStatus()); }
public ReplicaSetBuilder(ReplicaSetFluent<?> fluent,ReplicaSet 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 ReplicaSetBuilder(ReplicaSet instance){
public ReplicaSetBuilder(ReplicaSet 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; }
@Override ReplicaSet applyResource(ReplicaSet original, ReplicaSet current) { return client .extensions() .replicaSets() .inNamespace(getNamespace()) .withName(current.getMetadata().getName()) .edit() .withMetadata(current.getMetadata()) .withSpec(current.getSpec()) .done(); }
private boolean enableDebug(HasMetadata entity) { if (entity instanceof Deployment) { Deployment resource = (Deployment) entity; DeploymentSpec spec = resource.getSpec(); if (spec != null) { return enableDebugging(entity, spec.getTemplate()); } } else if (entity instanceof ReplicaSet) { ReplicaSet resource = (ReplicaSet) entity; ReplicaSetSpec spec = resource.getSpec(); if (spec != null) { return enableDebugging(entity, spec.getTemplate()); } } else if (entity instanceof ReplicationController) { ReplicationController resource = (ReplicationController) entity; ReplicationControllerSpec spec = resource.getSpec(); if (spec != null) { return enableDebugging(entity, spec.getTemplate()); } } else if (entity instanceof DeploymentConfig) { DeploymentConfig resource = (DeploymentConfig) entity; DeploymentConfigSpec spec = resource.getSpec(); if (spec != null) { return enableDebugging(entity, spec.getTemplate()); } } return false; }
private boolean enableDebug(HasMetadata entity) { if (entity instanceof Deployment) { Deployment resource = (Deployment) entity; DeploymentSpec spec = resource.getSpec(); if (spec != null) { return enableDebugging(entity, spec.getTemplate()); } } else if (entity instanceof ReplicaSet) { ReplicaSet resource = (ReplicaSet) entity; ReplicaSetSpec spec = resource.getSpec(); if (spec != null) { return enableDebugging(entity, spec.getTemplate()); } } else if (entity instanceof ReplicationController) { ReplicationController resource = (ReplicationController) entity; ReplicationControllerSpec spec = resource.getSpec(); if (spec != null) { return enableDebugging(entity, spec.getTemplate()); } } else if (entity instanceof DeploymentConfig) { DeploymentConfig resource = (DeploymentConfig) entity; DeploymentConfigSpec spec = resource.getSpec(); if (spec != null) { return enableDebugging(entity, spec.getTemplate()); } } return false; }
public void addRegistryToImageNameIfNotPresent(Iterable<HasMetadata> items, String registry) throws Exception { if (items != null) { for (HasMetadata item : items) { if (item instanceof KubernetesList) { KubernetesList list = (KubernetesList) item; addRegistryToImageNameIfNotPresent(list.getItems(), registry); } else if (item instanceof Template) { Template template = (Template) item; addRegistryToImageNameIfNotPresent(template.getObjects(), registry); } else if (item instanceof Pod) { List<Container> containers = ((Pod) item).getSpec().getContainers(); prefixRegistryIfNotPresent(containers, registry); } else if (item instanceof ReplicationController) { List<Container> containers = ((ReplicationController) item).getSpec().getTemplate().getSpec().getContainers(); prefixRegistryIfNotPresent(containers, registry); } else if (item instanceof ReplicaSet) { List<Container> containers = ((ReplicaSet) item).getSpec().getTemplate().getSpec().getContainers(); prefixRegistryIfNotPresent(containers, registry); } else if (item instanceof DeploymentConfig) { List<Container> containers = ((DeploymentConfig) item).getSpec().getTemplate().getSpec().getContainers(); prefixRegistryIfNotPresent(containers, registry); } else if (item instanceof Deployment) { List<Container> containers = ((Deployment) item).getSpec().getTemplate().getSpec().getContainers(); prefixRegistryIfNotPresent(containers, registry); } } } }
public void addRegistryToImageNameIfNotPresent(Iterable<HasMetadata> items, String registry) { if (items != null) { for (HasMetadata item : items) { if (item instanceof KubernetesList) { KubernetesList list = (KubernetesList) item; addRegistryToImageNameIfNotPresent(list.getItems(), registry); } else if (item instanceof Template) { Template template = (Template) item; addRegistryToImageNameIfNotPresent(template.getObjects(), registry); } else if (item instanceof Pod) { List<Container> containers = ((Pod) item).getSpec().getContainers(); prefixRegistryIfNotPresent(containers, registry); } else if (item instanceof ReplicationController) { List<Container> containers = ((ReplicationController) item).getSpec().getTemplate().getSpec().getContainers(); prefixRegistryIfNotPresent(containers, registry); } else if (item instanceof ReplicaSet) { List<Container> containers = ((ReplicaSet) item).getSpec().getTemplate().getSpec().getContainers(); prefixRegistryIfNotPresent(containers, registry); } else if (item instanceof DeploymentConfig) { List<Container> containers = ((DeploymentConfig) item).getSpec().getTemplate().getSpec().getContainers(); prefixRegistryIfNotPresent(containers, registry); } else if (item instanceof Deployment) { List<Container> containers = ((Deployment) item).getSpec().getTemplate().getSpec().getContainers(); prefixRegistryIfNotPresent(containers, registry); } } } }
public void addRegistryToImageNameIfNotPresent(Iterable<HasMetadata> items, String registry) { if (items != null) { for (HasMetadata item : items) { if (item instanceof KubernetesList) { KubernetesList list = (KubernetesList) item; addRegistryToImageNameIfNotPresent(list.getItems(), registry); } else if (item instanceof Template) { Template template = (Template) item; addRegistryToImageNameIfNotPresent(template.getObjects(), registry); } else if (item instanceof Pod) { List<Container> containers = ((Pod) item).getSpec().getContainers(); prefixRegistryIfNotPresent(containers, registry); } else if (item instanceof ReplicationController) { List<Container> containers = ((ReplicationController) item).getSpec().getTemplate().getSpec().getContainers(); prefixRegistryIfNotPresent(containers, registry); } else if (item instanceof ReplicaSet) { List<Container> containers = ((ReplicaSet) item).getSpec().getTemplate().getSpec().getContainers(); prefixRegistryIfNotPresent(containers, registry); } else if (item instanceof DeploymentConfig) { List<Container> containers = ((DeploymentConfig) item).getSpec().getTemplate().getSpec().getContainers(); prefixRegistryIfNotPresent(containers, registry); } else if (item instanceof Deployment) { List<Container> containers = ((Deployment) item).getSpec().getTemplate().getSpec().getContainers(); prefixRegistryIfNotPresent(containers, registry); } } } }