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 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();
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(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; }
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 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; }