Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve verifications to verify rollout deployments #321

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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 @@ 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.
Expand All @@ -162,18 +164,24 @@ 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<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
&& 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ 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");
Integer updatedReplicas = JsonPath.read(goodDeploymentOutput, "status.updatedReplicas");
Integer desiredReplicas = JsonPath.read(goodDeploymentOutput, "spec.replicas");
String shouldBeInLog =
String.format("AvailableReplicas = %s, MinimumReplicas = %s", availableReplicas, minimumReplicas);
String.format(
"AvailableReplicas = %s, UpdatedReplicas = %s, DesiredReplicas = %s",
availableReplicas, updatedReplicas, desiredReplicas);
String verificationLog = result.toString();
assertTrue(verificationLog.contains(shouldBeInLog));
}
Expand All @@ -65,10 +68,13 @@ 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.format(
"AvailableReplicas = %s, UpdatedReplicas = %s, DesiredReplicas = %s",
availableReplicas, updatedReplicas, desiredReplicas);
String verificationLog = result.toString();
assertTrue(verificationLog.contains(shouldBeInLog));
}
Expand Down