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

OP-22350 Upgraded the orca from 1.33.2 to 1.33.3 #53

Closed
wants to merge 3 commits into from
Closed
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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ subprojects {
repositories {
mavenLocal()
maven {
url "https://nexus1.opsmx.net/repository/maven-snapshots/"
url "NEXUS_URL"
credentials {
username = "NEXUS_USERNAME"
password = "NEXUS_PASSWORD"
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,15 @@ public PipelineExecution restartStage(

private PipelineExecution updatePreconditionStageExpression(
Map restartDetails, PipelineExecution execution) {
List<Map> preconditionList = getPreconditionsFromStage(restartDetails);
if (preconditionList.isEmpty()) {
Map<String, List<Map>> preconditionMap = getPreconditionsFromStage(restartDetails);
if (preconditionMap.isEmpty()) {
return execution;
}

for (StageExecution stage : execution.getStages()) {
if (stage.getType() != null && stage.getType().equalsIgnoreCase("checkPreconditions")) {
if (stage.getContext().get("preconditions") != null) {
stage.getContext().replace("preconditions", preconditionList);
stage.getContext().replace("preconditions", preconditionMap.get(stage.getRefId()));
repository.storeStage(stage);
log.info("Updated preconditions for CheckPreconditions stage");
}
Expand All @@ -158,8 +158,8 @@ private PipelineExecution updatePreconditionStageExpression(
return execution;
}

private List<Map> getPreconditionsFromStage(Map restartDetails) {
List<Map> preconditionList = new ArrayList();
private Map<String, List<Map>> getPreconditionsFromStage(Map restartDetails) {
Map<String, List<Map>> preconditionMap = new HashMap<>();
Map pipelineConfigMap = new HashMap(restartDetails);

List<String> keysToRetain = new ArrayList();
Expand All @@ -173,12 +173,13 @@ private List<Map> getPreconditionsFromStage(Map restartDetails) {
List<Map> pipelineStageList = pipelineStageMap.get(keysToRetain.get(0));
for (Map stageMap : pipelineStageList) {
if (stageMap.get("type").toString().equalsIgnoreCase("checkPreconditions")) {
preconditionList = (List<Map>) stageMap.get("preconditions");
preconditionMap.put(
(String) stageMap.get("refId"), (List<Map>) stageMap.get("preconditions"));
log.info("Retrieved preconditions for CheckPreconditions stage");
}
}
}
return preconditionList;
return preconditionMap;
}

private PipelineExecution doInternal(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ final class CompoundExecutionOperatorTest {
private static final String PIPELINE = "mypipeline";
private static final String EXECUTION_ID = "EXECUTION_ID";
private static final String STAGE_ID = "STAGE_ID";
private static final String UPSTREAM_STAGE = "UPSTREAM_STAGE";
private static final String UPSTREAM_STAGE_ID = "UPSTREAM_STAGE_ID";
private static final int PRECONDITION_STAGE_LIST_SIZE = 2;
private final ExecutionRepository repository = mock(ExecutionRepository.class);
private final ExecutionRunner runner = mock(ExecutionRunner.class);
private final RetrySupport retrySupport = mock(RetrySupport.class);
Expand Down Expand Up @@ -76,6 +79,46 @@ void restartStageWithValidExpression() {
assertEquals(APPLICATION, updatedExecution.getApplication());
}

@Test
void restartUpstreamStageWithMultiplePreconditionStages() {
// ARRANGE
StageExecution upstreamStage = buildUpstreamStage();
List<StageExecution> preconditionStages = new ArrayList<>(PRECONDITION_STAGE_LIST_SIZE);
List<StageExecution> executionStages = execution.getStages();
executionStages.add(upstreamStage);

for (int i = 0; i < PRECONDITION_STAGE_LIST_SIZE; i++) {
StageExecution preconditionStage =
buildPreconditionStage("expression_" + i, "precondition_" + i, "precondition_stage_" + i);
preconditionStages.add(preconditionStage);
executionStages.add(preconditionStage);
}

Map<String, Object> restartDetails =
Map.of(
"application", APPLICATION,
"name", PIPELINE,
"executionId", EXECUTION_ID,
"stages", buildExpectedRestartStageList(preconditionStages, upstreamStage));

when(repository.retrieve(any(), anyString())).thenReturn(execution);
when(repository.handlesPartition(execution.getPartition())).thenReturn(true);

// ACT
PipelineExecution updatedExecution =
executionOperator.restartStage(EXECUTION_ID, STAGE_ID, restartDetails);

// ASSERT
assertEquals(APPLICATION, updatedExecution.getApplication());
for (int i = 0, size = preconditionStages.size(); i < size; i++) {
StageExecution originalPreconditionStage = preconditionStages.get(i);
StageExecution updatedPreconditionStage = updatedExecution.getStages().get(i + 1);
assertEquals(originalPreconditionStage.getContext(), updatedPreconditionStage.getContext());
assertEquals(originalPreconditionStage.getType(), updatedPreconditionStage.getType());
assertEquals(originalPreconditionStage.getName(), updatedPreconditionStage.getName());
}
}

@Test
void restartStageWithNoPreconditions() {

Expand Down Expand Up @@ -135,6 +178,55 @@ private PipelineExecution buildExpectedExecution(
return execution;
}

private List<Map<String, Object>> buildExpectedRestartStageList(
List<StageExecution> preconditionStages, StageExecution upstreamStage) {
List<Map<String, Object>> restartStageList = new ArrayList<>(preconditionStages.size() + 1);

Map<String, Object> upstreamStageMap =
Map.of(
"name", upstreamStage.getName(),
"type", upstreamStage.getType());
restartStageList.add(upstreamStageMap);

for (StageExecution stage : preconditionStages) {
Map<String, Object> stageMap =
Map.of(
"name", stage.getName(),
"type", stage.getType(),
"preconditions", stage.getContext().get("preconditions"));
restartStageList.add(stageMap);
}
return restartStageList;
}

private StageExecution buildPreconditionStage(
String stageStatus, String stageId, String preConditionStageName) {
StageExecution preconditionStage = new StageExecutionImpl();
preconditionStage.setId(stageId);
preconditionStage.setType("checkPreconditions");
preconditionStage.setName(preConditionStageName);
Map<String, Object> contextMap = new HashMap<>();
contextMap.put("stageName", UPSTREAM_STAGE);
contextMap.put("stageStatus", stageStatus);
List<Map<String, Object>> preconditionList = new ArrayList<>();
Map<String, Object> preconditionMap = new HashMap<>();
preconditionMap.put("context", contextMap);
preconditionMap.put("failPipeline", true);
preconditionMap.put("type", "stageStatus");
preconditionList.add(preconditionMap);
contextMap.put("preconditions", preconditionList);
preconditionStage.setContext(contextMap);
return preconditionStage;
}

private StageExecution buildUpstreamStage() {
StageExecution upstreamStage = new StageExecutionImpl();
upstreamStage.setId(UPSTREAM_STAGE_ID);
upstreamStage.setType("manualJudgment");
upstreamStage.setName(UPSTREAM_STAGE);
return upstreamStage;
}

private Map buildExpectedRestartDetailsMap(String expression) {
Map restartDetails = new HashMap<>();
List<Map> pipelineStageList = new ArrayList();
Expand Down
1 change: 1 addition & 0 deletions orca-igor/orca-igor.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ dependencies {
testImplementation(project(":orca-test-groovy"))
testImplementation("org.springframework:spring-test")
testImplementation("io.spinnaker.fiat:fiat-core:$fiatVersion")
testImplementation("com.github.tomakehurst:wiremock-jre8-standalone")
testImplementation "cglib:cglib-nodep:3.3.0"

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Map<String, Object> getPropertyFileWithJobAsQueryParam(
@Path("buildNumber") Integer buildNumber,
@Path("fileName") String fileName,
@Path("master") String master,
@Query(value = "job") String job);
@Query(encodeValue = false, value = "job") String job);

@GET("/{repoType}/{projectKey}/{repositorySlug}/compareCommits")
List compareCommits(
Expand All @@ -105,7 +105,7 @@ List<Artifact> getArtifactsWithJobAsQueryParam(
@Path("buildNumber") Integer buildNumber,
@Query("propertyFile") String propertyFile,
@Path("master") String master,
@Query(value = "job") String job);
@Query(value = "job", encodeValue = false) String job);

@POST("/gcb/builds/create/{account}")
GoogleCloudBuild createGoogleCloudBuild(
Expand Down
Loading
Loading