Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,11 @@
* 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.
Expand All @@ -162,18 +164,24 @@
return errorResult(e, object);
}

Integer minReplicas = JsonPath.read(json, MINIMUM_REPLICAS_JSONPATH);
Integer desiredReplicas = JsonPath.read(json, DESIRED_REPLICAS_JSONPATH);
Map<String, Object> status = JsonPath.read(json, STATUS_JSONPATH);
Integer availableReplicas = (Integer) status.getOrDefault(AVAILABLE_REPLICAS, 0);
boolean verified = minReplicas != null
&& availableReplicas != null
&& minReplicas.intValue() <= availableReplicas.intValue();
Integer updatedReplicas = (Integer) status.getOrDefault(UPDATED_REPLICAS, 0);
Integer replicas = (Integer) status.getOrDefault(REPLICAS, 0);
boolean verified = desiredReplicas != null

Check warning on line 172 in src/main/java/com/google/jenkins/plugins/k8sengine/KubernetesVerifiers.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 172 is only partially covered, one branch is missing
&& updatedReplicas.intValue() >= desiredReplicas.intValue()

Check warning on line 173 in src/main/java/com/google/jenkins/plugins/k8sengine/KubernetesVerifiers.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 173 is only partially covered, one branch is missing
&& replicas.intValue() <= updatedReplicas.intValue()

Check warning on line 174 in src/main/java/com/google/jenkins/plugins/k8sengine/KubernetesVerifiers.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 174 is only partially covered, one branch is missing
&& 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
* @return Self-reference after performing verify.
*/
private VerificationTask verify() {
consoleLogger.println(String.format("Verifying: %s ", manifestObject.describe()));
consoleLogger.println(Messages.KubernetesEngineBuilder_VerifyingLogPrefix(manifestObject.describe()));

Check warning on line 79 in src/main/java/com/google/jenkins/plugins/k8sengine/VerificationTask.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 79 is not covered by tests
currentResult = KubernetesVerifiers.verify(kubectl, manifestObject);
if (isVerified()) {
consoleLogger.println(currentResult.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ public void testGoodDeploymentVerified() throws Exception {
KubernetesVerifiers.VerificationResult result = KubernetesVerifiers.verify(kubectl, goodDeployment);
assertTrue(result.isVerified());
Integer availableReplicas = JsonPath.read(goodDeploymentOutput, "status.availableReplicas");
Integer minimumReplicas = JsonPath.read(goodDeploymentOutput, "spec.replicas");
String shouldBeInLog =
String.format("AvailableReplicas = %s, MinimumReplicas = %s", availableReplicas, minimumReplicas);
Integer updatedReplicas = JsonPath.read(goodDeploymentOutput, "status.updatedReplicas");
Integer desiredReplicas = JsonPath.read(goodDeploymentOutput, "spec.replicas");
String shouldBeInLog = String.format(
"AvailableReplicas = %s, UpdatedReplicas = %s, DesiredReplicas = %s",
availableReplicas, updatedReplicas, desiredReplicas);
String verificationLog = result.toString();
assertTrue(verificationLog.contains(shouldBeInLog));
}
Expand All @@ -65,10 +67,12 @@ public void testBadDeploymentNotVerified() throws Exception {
KubernetesVerifiers.VerificationResult result = 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);
String shouldBeInLog = String.format(
"AvailableReplicas = %s, UpdatedReplicas = %s, DesiredReplicas = %s",
availableReplicas, updatedReplicas, desiredReplicas);
String verificationLog = result.toString();
assertTrue(verificationLog.contains(shouldBeInLog));
}
Expand Down