diff --git a/src/main/java/com/google/jenkins/plugins/k8sengine/KubernetesVerifiers.java b/src/main/java/com/google/jenkins/plugins/k8sengine/KubernetesVerifiers.java index e576471a..2a227ef8 100644 --- a/src/main/java/com/google/jenkins/plugins/k8sengine/KubernetesVerifiers.java +++ b/src/main/java/com/google/jenkins/plugins/k8sengine/KubernetesVerifiers.java @@ -139,9 +139,11 @@ public VerificationResult verify(KubectlWrapper kubectl, Manifests.ManifestObjec * available replicas (status.availableReplicas). */ private static class DeploymentVerifier implements Verifier { - private static final String AVAILABLE_REPLICAS = "availableReplicas"; - private static final String MINIMUM_REPLICAS_JSONPATH = "spec.replicas"; private static final String STATUS_JSONPATH = "status"; + private static final String AVAILABLE_REPLICAS = "availableReplicas"; + private static final String UPDATED_REPLICAS = "updatedReplicas"; + private static final String REPLICAS = "replicas"; + private static final String DESIRED_REPLICAS_JSONPATH = "spec.replicas"; /** * Verifies that the deployment was applied to the GKE cluster. @@ -164,19 +166,25 @@ public VerificationResult verify(KubectlWrapper kubectl, Manifests.ManifestObjec return errorResult(e, object); } - Integer minReplicas = JsonPath.read(json, MINIMUM_REPLICAS_JSONPATH); + Integer desiredReplicas = JsonPath.read(json, DESIRED_REPLICAS_JSONPATH); Map status = JsonPath.read(json, STATUS_JSONPATH); Integer availableReplicas = (Integer) status.getOrDefault(AVAILABLE_REPLICAS, 0); + Integer updatedReplicas = (Integer) status.getOrDefault(UPDATED_REPLICAS, 0); + Integer replicas = (Integer) status.getOrDefault(REPLICAS, 0); boolean verified = - minReplicas != null - && availableReplicas != null - && minReplicas.intValue() <= availableReplicas.intValue(); + desiredReplicas != null + && updatedReplicas.intValue() >= desiredReplicas.intValue() + && replicas.intValue() <= updatedReplicas.intValue() + && availableReplicas.intValue() == updatedReplicas.intValue(); log.append("AvailableReplicas = ") .append(availableReplicas) .append(",") - .append(" MinimumReplicas = ") - .append(minReplicas) + .append(" UpdatedReplicas = ") + .append(updatedReplicas) + .append(",") + .append(" DesiredReplicas = ") + .append(desiredReplicas) .append("\n"); return new VerificationResult(log.toString(), verified, object); diff --git a/src/main/java/com/google/jenkins/plugins/k8sengine/VerificationTask.java b/src/main/java/com/google/jenkins/plugins/k8sengine/VerificationTask.java index 16506d5d..4520b14e 100644 --- a/src/main/java/com/google/jenkins/plugins/k8sengine/VerificationTask.java +++ b/src/main/java/com/google/jenkins/plugins/k8sengine/VerificationTask.java @@ -76,7 +76,8 @@ public KubernetesVerifiers.VerificationResult getVerificationResult() { * @return Self-reference after performing verify. */ private VerificationTask verify() { - consoleLogger.println(String.format("Verifying: %s ", manifestObject.describe())); + consoleLogger.println( + Messages.KubernetesEngineBuilder_VerifyingLogPrefix(manifestObject.describe())); currentResult = KubernetesVerifiers.verify(kubectl, manifestObject); if (isVerified()) { consoleLogger.println(currentResult.toString()); diff --git a/src/test/java/com/google/jenkins/plugins/k8sengine/KubernetesVerifiersTest.java b/src/test/java/com/google/jenkins/plugins/k8sengine/KubernetesVerifiersTest.java index 4bc3c4d2..c3013579 100644 --- a/src/test/java/com/google/jenkins/plugins/k8sengine/KubernetesVerifiersTest.java +++ b/src/test/java/com/google/jenkins/plugins/k8sengine/KubernetesVerifiersTest.java @@ -46,10 +46,12 @@ public void testGoodDeploymentVerified() throws Exception { KubernetesVerifiers.verify(kubectl, goodDeployment); assertTrue(result.isVerified()); Integer availableReplicas = JsonPath.read(goodDeploymentOutput, "status.availableReplicas"); - Integer minimumReplicas = JsonPath.read(goodDeploymentOutput, "spec.replicas"); + Integer updatedReplicas = JsonPath.read(goodDeploymentOutput, "status.updatedReplicas"); + Integer desiredReplicas = JsonPath.read(goodDeploymentOutput, "spec.replicas"); String shouldBeInLog = String.format( - "AvailableReplicas = %s, MinimumReplicas = %s", availableReplicas, minimumReplicas); + "AvailableReplicas = %s, UpdatedReplicas = %s, DesiredReplicas = %s", + availableReplicas, updatedReplicas, desiredReplicas); String verificationLog = result.toString(); assertTrue(verificationLog.contains(shouldBeInLog)); } @@ -70,11 +72,13 @@ public void testBadDeploymentNotVerified() throws Exception { KubernetesVerifiers.verify(kubectl, badDeployment); assertFalse(result.isVerified()); - Integer minimumReplicas = JsonPath.read(badDeploymentOutput, "spec.replicas"); + Integer desiredReplicas = JsonPath.read(badDeploymentOutput, "spec.replicas"); + Integer updatedReplicas = JsonPath.read(badDeploymentOutput, "status.updatedReplicas"); Integer availableReplicas = 0; String shouldBeInLog = String.format( - "AvailableReplicas = %s, MinimumReplicas = %s", availableReplicas, minimumReplicas); + "AvailableReplicas = %s, UpdatedReplicas = %s, DesiredReplicas = %s", + availableReplicas, updatedReplicas, desiredReplicas); String verificationLog = result.toString(); assertTrue(verificationLog.contains(shouldBeInLog)); }