Skip to content

Commit 70109be

Browse files
committed
Improve deployment verification
With the exception of progress deadline, it now uses the same algorith as "kubectl rollout status": https://github.com/kubernetes/kubectl/blob/f89fc21e9c51d313e923eb93d1ae83754be62019/pkg/polymorphichelpers/rollout_status.go#L80-L88 While at it, rename minimum replicas to desired replicas as per Kubernetes terminology. Minimum replicas are more used in Horizontal Pod Autoscaling, not the Deployment configuration.
1 parent 31ab687 commit 70109be

File tree

3 files changed

+26
-13
lines changed

3 files changed

+26
-13
lines changed

src/main/java/com/google/jenkins/plugins/k8sengine/KubernetesVerifiers.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,11 @@ public VerificationResult verify(KubectlWrapper kubectl, Manifests.ManifestObjec
139139
* available replicas (status.availableReplicas).
140140
*/
141141
private static class DeploymentVerifier implements Verifier {
142-
private static final String AVAILABLE_REPLICAS = "availableReplicas";
143-
private static final String MINIMUM_REPLICAS_JSONPATH = "spec.replicas";
144142
private static final String STATUS_JSONPATH = "status";
143+
private static final String AVAILABLE_REPLICAS = "availableReplicas";
144+
private static final String UPDATED_REPLICAS = "updatedReplicas";
145+
private static final String REPLICAS = "replicas";
146+
private static final String DESIRED_REPLICAS_JSONPATH = "spec.replicas";
145147

146148
/**
147149
* Verifies that the deployment was applied to the GKE cluster.
@@ -164,19 +166,25 @@ public VerificationResult verify(KubectlWrapper kubectl, Manifests.ManifestObjec
164166
return errorResult(e, object);
165167
}
166168

167-
Integer minReplicas = JsonPath.read(json, MINIMUM_REPLICAS_JSONPATH);
169+
Integer desiredReplicas = JsonPath.read(json, DESIRED_REPLICAS_JSONPATH);
168170
Map<String, Object> status = JsonPath.read(json, STATUS_JSONPATH);
169171
Integer availableReplicas = (Integer) status.getOrDefault(AVAILABLE_REPLICAS, 0);
172+
Integer updatedReplicas = (Integer) status.getOrDefault(UPDATED_REPLICAS, 0);
173+
Integer replicas = (Integer) status.getOrDefault(REPLICAS, 0);
170174
boolean verified =
171-
minReplicas != null
172-
&& availableReplicas != null
173-
&& minReplicas.intValue() <= availableReplicas.intValue();
175+
desiredReplicas != null
176+
&& updatedReplicas.intValue() >= desiredReplicas.intValue()
177+
&& replicas.intValue() <= updatedReplicas.intValue()
178+
&& availableReplicas.intValue() == updatedReplicas.intValue();
174179

175180
log.append("AvailableReplicas = ")
176181
.append(availableReplicas)
177182
.append(",")
178-
.append(" MinimumReplicas = ")
179-
.append(minReplicas)
183+
.append(" UpdatedReplicas = ")
184+
.append(updatedReplicas)
185+
.append(",")
186+
.append(" DesiredReplicas = ")
187+
.append(desiredReplicas)
180188
.append("\n");
181189

182190
return new VerificationResult(log.toString(), verified, object);

src/main/java/com/google/jenkins/plugins/k8sengine/VerificationTask.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ public KubernetesVerifiers.VerificationResult getVerificationResult() {
7676
* @return Self-reference after performing verify.
7777
*/
7878
private VerificationTask verify() {
79-
consoleLogger.println(String.format("Verifying: %s ", manifestObject.describe()));
79+
consoleLogger.println(
80+
Messages.KubernetesEngineBuilder_VerifyingLogPrefix(manifestObject.describe()));
8081
currentResult = KubernetesVerifiers.verify(kubectl, manifestObject);
8182
if (isVerified()) {
8283
consoleLogger.println(currentResult.toString());

src/test/java/com/google/jenkins/plugins/k8sengine/KubernetesVerifiersTest.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,12 @@ public void testGoodDeploymentVerified() throws Exception {
4646
KubernetesVerifiers.verify(kubectl, goodDeployment);
4747
assertTrue(result.isVerified());
4848
Integer availableReplicas = JsonPath.read(goodDeploymentOutput, "status.availableReplicas");
49-
Integer minimumReplicas = JsonPath.read(goodDeploymentOutput, "spec.replicas");
49+
Integer updatedReplicas = JsonPath.read(goodDeploymentOutput, "status.updatedReplicas");
50+
Integer desiredReplicas = JsonPath.read(goodDeploymentOutput, "spec.replicas");
5051
String shouldBeInLog =
5152
String.format(
52-
"AvailableReplicas = %s, MinimumReplicas = %s", availableReplicas, minimumReplicas);
53+
"AvailableReplicas = %s, UpdatedReplicas = %s, DesiredReplicas = %s",
54+
availableReplicas, updatedReplicas, desiredReplicas);
5355
String verificationLog = result.toString();
5456
assertTrue(verificationLog.contains(shouldBeInLog));
5557
}
@@ -70,11 +72,13 @@ public void testBadDeploymentNotVerified() throws Exception {
7072
KubernetesVerifiers.verify(kubectl, badDeployment);
7173
assertFalse(result.isVerified());
7274

73-
Integer minimumReplicas = JsonPath.read(badDeploymentOutput, "spec.replicas");
75+
Integer desiredReplicas = JsonPath.read(badDeploymentOutput, "spec.replicas");
76+
Integer updatedReplicas = JsonPath.read(badDeploymentOutput, "status.updatedReplicas");
7477
Integer availableReplicas = 0;
7578
String shouldBeInLog =
7679
String.format(
77-
"AvailableReplicas = %s, MinimumReplicas = %s", availableReplicas, minimumReplicas);
80+
"AvailableReplicas = %s, UpdatedReplicas = %s, DesiredReplicas = %s",
81+
availableReplicas, updatedReplicas, desiredReplicas);
7882
String verificationLog = result.toString();
7983
assertTrue(verificationLog.contains(shouldBeInLog));
8084
}

0 commit comments

Comments
 (0)