|
9 | 9 | import java.util.HashMap; |
10 | 10 | import java.util.List; |
11 | 11 | import java.util.Map; |
| 12 | +import java.util.Optional; |
12 | 13 | import java.util.logging.Level; |
13 | 14 | import java.util.stream.Collectors; |
14 | 15 |
|
|
22 | 23 | import io.kubernetes.client.openapi.models.V1Deployment; |
23 | 24 | import io.kubernetes.client.openapi.models.V1DeploymentCondition; |
24 | 25 | import io.kubernetes.client.openapi.models.V1DeploymentList; |
| 26 | +import io.kubernetes.client.openapi.models.V1DeploymentStatus; |
25 | 27 | import io.kubernetes.client.openapi.models.V1Job; |
26 | 28 | import io.kubernetes.client.openapi.models.V1JobCondition; |
27 | 29 | import io.kubernetes.client.openapi.models.V1JobList; |
@@ -661,18 +663,17 @@ public static boolean isDeploymentReady(String deploymentName, |
661 | 663 | String namespace) throws ApiException { |
662 | 664 | boolean status = false; |
663 | 665 | V1Deployment deployment = getDeployment(deploymentName, label, namespace); |
664 | | - if (deployment != null) { |
665 | | - // get the deploymentCondition with the 'Available' type field |
666 | | - V1DeploymentCondition v1DeploymentRunningCondition = deployment.getStatus().getConditions().stream() |
667 | | - .filter(v1DeploymentCondition -> "Available".equals(v1DeploymentCondition.getType())) |
668 | | - .findAny() |
669 | | - .orElse(null); |
670 | 666 |
|
671 | | - if (v1DeploymentRunningCondition != null) { |
672 | | - status = v1DeploymentRunningCondition.getStatus().equalsIgnoreCase("true"); |
673 | | - } |
| 667 | + V1DeploymentCondition v1DeploymentRunningCondition = Optional.ofNullable(deployment) |
| 668 | + .map(V1Deployment::getStatus).map(V1DeploymentStatus::getConditions) |
| 669 | + .orElse(null).stream() |
| 670 | + .filter(v1DeploymentCondition -> "Available".equals(v1DeploymentCondition.getType())) |
| 671 | + .findAny() |
| 672 | + .orElse(null); |
| 673 | + if (v1DeploymentRunningCondition != null) { |
| 674 | + status = v1DeploymentRunningCondition.getStatus().equalsIgnoreCase("true"); |
674 | 675 | } else { |
675 | | - getLogger().info("Deployment doesn't exist"); |
| 676 | + getLogger().info("Can't check deployment status"); |
676 | 677 | } |
677 | 678 | return status; |
678 | 679 | } |
|
0 commit comments