public DeploymentStatusBuilder(DeploymentStatusFluent<?> fluent,DeploymentStatus instance,Boolean validationEnabled){ this.fluent = fluent; fluent.withAvailableReplicas(instance.getAvailableReplicas()); fluent.withObservedGeneration(instance.getObservedGeneration()); fluent.withReplicas(instance.getReplicas()); fluent.withUnavailableReplicas(instance.getUnavailableReplicas()); fluent.withUpdatedReplicas(instance.getUpdatedReplicas()); this.validationEnabled = validationEnabled; } public DeploymentStatusBuilder(DeploymentStatus instance){
public DeploymentStatusBuilder(DeploymentStatusFluent<?> fluent,Boolean validationEnabled){ this(fluent, new DeploymentStatus(), validationEnabled); } public DeploymentStatusBuilder(DeploymentStatusFluent<?> fluent,DeploymentStatus instance){
public static boolean isDeploymentReady(Deployment d) { Utils.checkNotNull(d, "Deployment can't be null."); DeploymentSpec spec = d.getSpec(); DeploymentStatus status = d.getStatus(); if (status == null || status.getReplicas() == null || status.getAvailableReplicas() == 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.getReplicas() && spec.getReplicas().intValue() <= status.getAvailableReplicas(); }
public int getScalingFactor(Service service, String groupName) throws ApolloNotFoundException { io.fabric8.kubernetes.api.model.extensions.Deployment kubernetesDeployment = getKubernetesDeployment(service, Optional.of(groupName)); if (kubernetesDeployment == null) { throw new ApolloNotFoundException("Could not find deployment for environment " + environment.getId() + ", service " + service.getId() + " and group " + groupName + ", can't return the status!"); } return Optional.ofNullable(kubernetesDeployment.getStatus().getAvailableReplicas()).orElse(0); }
public void run() { try { Deployment deployment = get(); //If the deployment is gone, we shouldn't wait. if (deployment == null) { if (count == 0) { queue.put(true); return; } else { queue.put(new IllegalStateException("Can't wait for Deployment: " + checkName(getItem()) + " in namespace: " + checkName(getItem()) + " to scale. Resource is no longer available.")); return; } } replicasRef.set(deployment.getStatus().getReplicas()); int currentReplicas = deployment.getStatus().getReplicas() != null ? deployment.getStatus().getReplicas() : 0; long generation = deployment.getMetadata().getGeneration() != null ? deployment.getMetadata().getGeneration() : 0; long observedGeneration = deployment.getStatus() != null && deployment.getStatus().getObservedGeneration() != null ? deployment.getStatus().getObservedGeneration() : -1; if (observedGeneration >= generation && Objects.equals(deployment.getSpec().getReplicas(), currentReplicas)) { queue.put(true); } else { LOG.debug("Only {}/{} pods scheduled for Deployment: {} in namespace: {} seconds so waiting...", deployment.getStatus().getReplicas(), deployment.getSpec().getReplicas(), deployment.getMetadata().getName(), namespace); } } catch (Throwable t) { LOG.error("Error while waiting for Deployment to be scaled.", t); } } };
io.fabric8.kubernetes.api.model.extensions.DeploymentStatus deploymentStatus = returnedDeployment.get().getStatus(); Integer totalReplicas = deploymentStatus.getReplicas(); updateDeploymentStatus(deployment); } else { int updatedReplicas = deploymentStatus.getUpdatedReplicas(); logger.info("Monitoring of deployment id {}: out of {} replicas, {} are updated", deployment.getId(), totalReplicas, updatedReplicas);
public void run() { Deployment deployment = oper.getMandatory(); if (observedGeneration <= deployment.getStatus().getObservedGeneration()) { countDownLatch.countDown(); } } };
@Override public Boolean call() { Deployment dep = client.extensions().deployments().inNamespace(namespace).withName(deploymentName).get(); DeploymentStatus status = (dep == null) ? null : dep.getStatus(); Integer replicas = (status == null) ? null : status.getAvailableReplicas(); return replicas != null && replicas.intValue() == replicas; }
@Override public boolean reap() { Deployment deployment = oper.cascading(false).edit().editSpec().withReplicas(0).endSpec().done(); waitForObservedGeneration(deployment.getStatus().getObservedGeneration()); reapMatchingReplicaSets(deployment.getSpec().getSelector()); return false; }
public DeploymentStatusBuilder(DeploymentStatus instance,Boolean validationEnabled){ this.fluent = this; this.withAvailableReplicas(instance.getAvailableReplicas()); this.withObservedGeneration(instance.getObservedGeneration()); this.withReplicas(instance.getReplicas()); this.withUnavailableReplicas(instance.getUnavailableReplicas()); this.withUpdatedReplicas(instance.getUpdatedReplicas()); this.validationEnabled = validationEnabled; }
@Override public String getFailureMessage() { Deployment dep = client.extensions().deployments().inNamespace(namespace).withName(deploymentName).get(); DeploymentStatus status = (dep == null) ? null : dep.getStatus(); return "Namespace=" + namespace + "; deploymentName= " + deploymentName + "; Deployment=" + dep + "; status=" + status + "; availableReplicas=" + (status == null ? "null" : status.getAvailableReplicas()); } };
public DeploymentStatusBuilder(Boolean validationEnabled){ this(new DeploymentStatus(), validationEnabled); } public DeploymentStatusBuilder(DeploymentStatusFluent<?> fluent){
public DeploymentStatusFluentImpl(DeploymentStatus instance){ this.withAvailableReplicas(instance.getAvailableReplicas()); this.withObservedGeneration(instance.getObservedGeneration()); this.withReplicas(instance.getReplicas()); this.withUnavailableReplicas(instance.getUnavailableReplicas()); this.withUpdatedReplicas(instance.getUpdatedReplicas()); }
public A withNewStatus(Integer availableReplicas,Long observedGeneration,Integer replicas,Integer unavailableReplicas,Integer updatedReplicas){ return (A)withStatus(new DeploymentStatus(availableReplicas, observedGeneration, replicas, unavailableReplicas, updatedReplicas)); }
public KubernetesDeploymentStatus getCurrentStatus(Service service, Optional<String> groupName) { io.fabric8.kubernetes.api.model.extensions.Deployment deployment = getKubernetesDeployment(service, groupName); if (deployment == null) { logger.warn("Could not find deployment for environment {} and service {}, can't return the status!", environment.getId(), service.getId()); return null; } List<PodStatus> podStatusList = kubernetesClient .pods() .inNamespace(environment.getKubernetesNamespace()) .withLabel(ApolloToKubernetes.getApolloDeploymentUniqueIdentifierKey(), ApolloToKubernetes.getApolloPodUniqueIdentifier(environment, service, groupName)) .list() .getItems() .stream() .map(pod -> pod.getMetadata().getName()) .map(this::getPodStatus) .collect(Collectors.toList()); KubernetesDeploymentStatus kubernetesDeploymentStatus = new KubernetesDeploymentStatus(); kubernetesDeploymentStatus.setServiceId(service.getId()); kubernetesDeploymentStatus.setEnvironmentId(environment.getId()); kubernetesDeploymentStatus.setGitCommitSha(deployment.getMetadata().getLabels().get(ApolloToKubernetes.getApolloCommitShaKey())); kubernetesDeploymentStatus.setReplicas(deployment.getStatus().getReplicas()); kubernetesDeploymentStatus.setAvailableReplicas(deployment.getStatus().getAvailableReplicas()); kubernetesDeploymentStatus.setUpdatedReplicas(deployment.getStatus().getUpdatedReplicas()); kubernetesDeploymentStatus.setUnavailableReplicas(deployment.getStatus().getUnavailableReplicas()); kubernetesDeploymentStatus.setPodStatuses(podStatusList); groupName.ifPresent(kubernetesDeploymentStatus::setGroupName); return kubernetesDeploymentStatus; }
public DeploymentStatus build(){ DeploymentStatus buildable = new DeploymentStatus(fluent.getAvailableReplicas(),fluent.getObservedGeneration(),fluent.getReplicas(),fluent.getUnavailableReplicas(),fluent.getUpdatedReplicas()); validate(buildable); return buildable; }