@Override int getDesiredReplicas(ReplicaSet item) { return item.getSpec().getReplicas(); }
@Override public HasMetadata convert(HasMetadata item, boolean trimImageInContainerSpec, boolean enableAutomaticTrigger) { ReplicaSet resource = (ReplicaSet) item; ReplicationControllerBuilder builder = new ReplicationControllerBuilder(); builder.withMetadata(resource.getMetadata()); ReplicaSetSpec spec = resource.getSpec(); if (spec != null) { ReplicationControllerFluent.SpecNested<ReplicationControllerBuilder> specBuilder = builder.withNewSpec(); Integer replicas = spec.getReplicas(); if (replicas != null) { specBuilder.withReplicas(replicas); } LabelSelector selector = spec.getSelector(); if (selector != null) { Map<String, String> matchLabels = selector.getMatchLabels(); if (matchLabels != null && !matchLabels.isEmpty()) { specBuilder.withSelector(matchLabels); } } PodTemplateSpec template = spec.getTemplate(); if (template != null) { specBuilder.withTemplate(template); } specBuilder.endSpec(); } return builder.build(); } }
@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()); }
@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(); }
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; }
ReplicaSetSpec spec = resource.getSpec(); if (spec != null) { selector = spec.getSelector();
ReplicaSetSpec spec = resource.getSpec(); if (spec != null) { if (enableDebugging(entity, spec.getTemplate())) { kubernetes.extensions().replicaSets().inNamespace(namespace).withName(name).replace(resource);
@Override protected int getReplicas(ReplicaSet obj) { return obj.getSpec().getReplicas(); }
ReplicaSetSpec spec = resource.getSpec(); if (spec != null) { if (updateImageName(entity, spec.getTemplate(), imagePrefix, imageName)) { kubernetes.extensions().replicaSets().inNamespace(namespace).withName(name).replace(resource);
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(); }