Skip to content

Commit

Permalink
fix(blueGreen): Scaling replicaSets should not be considered for dele…
Browse files Browse the repository at this point in the history
…tion (#4728) (#4730)

(cherry picked from commit 9c8126b)

Co-authored-by: Christos Arvanitis <[email protected]>
  • Loading branch information
mergify[bot] and christosarvanitis authored May 29, 2024
1 parent f0a0837 commit b303a9b
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,16 @@ ImmutableList<String> getOldManifestNames(DeployedManifest dm) {
boolean previousDeploymentNeitherStableNorFailed(String account, String location, String name) {
var oldManifest = this.oortService.getManifest(account, location, name, false);

Map<String, Double> statusSpec =
(Map<String, Double>) oldManifest.getManifest().getOrDefault("status", emptyMap());
if (statusSpec.containsKey("readyReplicas") && statusSpec.containsKey("availableReplicas")) {
var readyReplicas = statusSpec.get("readyReplicas");
var availableReplicas = statusSpec.get("availableReplicas");
if (readyReplicas > 0 && availableReplicas > 0) {
return false;
}
}

var status = oldManifest.getStatus();
var notStable = !status.getStable().isState();
var notFailed = !status.getFailed().isState();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,58 @@ void rolloutBlueGreenStrategyDeletesOldManifest() {
.containsExactly("replicaSet my-rs-v000");
}

@Test
@DisplayName(
"blue/green deployment should trigger old manifest disable if it not all replicas are available")
void rolloutBlueGreenStrategyDuringScalingDisablesOldManifest() {
givenManifestIsNotStableDueToScaling();
when(oortService.getClusterManifests(ACCOUNT, NAMESAPCE, "replicaSet", APPLICATION, CLUSTER))
.thenReturn(
ImmutableList.of(
ManifestCoordinates.builder()
.name("my-rs-v000")
.kind("replicaSet")
.namespace(NAMESAPCE)
.build(),
ManifestCoordinates.builder()
.name("my-rs-v001")
.kind("replicaSet")
.namespace(NAMESAPCE)
.build()));
Map<String, Object> context =
getContext(
DeployManifestContext.builder()
.trafficManagement(
DeployManifestContext.TrafficManagement.builder()
.enabled(true)
.options(
DeployManifestContext.TrafficManagement.Options.builder()
.strategy(ManifestStrategyType.BLUE_GREEN)
.build())
.build())
.build());
StageExecutionImpl stage =
new StageExecutionImpl(
new PipelineExecutionImpl(ExecutionType.PIPELINE, APPLICATION),
DeployManifestStage.PIPELINE_CONFIG_TYPE,
context);
assertThat(getAfterStages(stage))
.extracting(StageExecution::getType)
.containsExactly(DisableManifestStage.PIPELINE_CONFIG_TYPE);
assertThat(getAfterStages(stage))
.extracting(s -> s.getContext().get("account"))
.containsExactly(ACCOUNT);
assertThat(getAfterStages(stage))
.extracting(s -> s.getContext().get("app"))
.containsExactly(APPLICATION);
assertThat(getAfterStages(stage))
.extracting(s -> s.getContext().get("location"))
.containsExactly(NAMESAPCE);
assertThat(getAfterStages(stage))
.extracting(s -> s.getContext().get("manifestName"))
.containsExactly("replicaSet my-rs-v000");
}

@Test
void rolloutStrategyHighlander() {
when(oortService.getClusterManifests(ACCOUNT, NAMESAPCE, "replicaSet", APPLICATION, CLUSTER))
Expand Down Expand Up @@ -377,6 +429,15 @@ private void givenManifestIsStable() {

var manifest =
Manifest.builder()
.manifest(
ImmutableMap.of(
"status",
ImmutableMap.of(
"availableReplicas", 3.0,
"fullyLabeledReplicas", 3.0,
"observedGeneration", 1.0,
"readyReplicas", 3.0,
"replicas", 3.0)))
.status(
Manifest.Status.builder()
.stable(Manifest.Condition.emptyTrue())
Expand All @@ -390,6 +451,37 @@ private void givenManifestIsStable() {
private void givenManifestIsNotStable() {
var manifest =
Manifest.builder()
.manifest(
ImmutableMap.of(
"status",
ImmutableMap.of(
"availableReplicas", 0.0,
"fullyLabeledReplicas", 0.0,
"observedGeneration", 1.0,
"readyReplicas", 0.0,
"replicas", 3.0)))
.status(
Manifest.Status.builder()
.stable(Manifest.Condition.emptyFalse())
.failed(Manifest.Condition.emptyFalse())
.build())
.build();

givenManifestIs(manifest);
}

private void givenManifestIsNotStableDueToScaling() {
var manifest =
Manifest.builder()
.manifest(
ImmutableMap.of(
"status",
ImmutableMap.of(
"availableReplicas", 2.0,
"fullyLabeledReplicas", 2.0,
"observedGeneration", 1.0,
"readyReplicas", 2.0,
"replicas", 3.0)))
.status(
Manifest.Status.builder()
.stable(Manifest.Condition.emptyFalse())
Expand Down

0 comments on commit b303a9b

Please sign in to comment.