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

control-service: deployment cannot be suspended #2941

Merged
merged 2 commits into from
Nov 29, 2023
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 @@ -121,7 +121,7 @@ public void testDataJobDeploymentCrudOperations() throws Exception {

executeDisableDeploymentWrongTeam();

verifyDeploymentDisabled(jobDeploymentName);
verifyDeploymentDisabled();

verifyDeploymentFieldsAfterDisable(testJobVersionSha);

Expand Down Expand Up @@ -319,14 +319,14 @@ private void executeDisableDeploymentWrongTeam() throws Exception {
.andExpect(status().isNotFound());
}

private void verifyDeploymentDisabled(String jobDeploymentName) {
private void verifyDeploymentDisabled() {
waitUntil(
() -> {
Optional<JobDeploymentStatus> deploymentOptional =
dataJobsKubernetesService.readCronJob(jobDeploymentName);
Assertions.assertTrue(deploymentOptional.isPresent());
JobDeploymentStatus deployment = deploymentOptional.get();
return !deployment.getEnabled();
var result = getJobDeployment();
DataJobDeploymentStatus jobDeployment =
mapper.readValue(
result.getResponse().getContentAsString(), DataJobDeploymentStatus.class);
return !jobDeployment.getEnabled();
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void testSynchronizeDataJob() throws Exception {
String testJobVersionSha = testDataJobVersion.getVersionSha();
Assertions.assertFalse(StringUtils.isBlank(testJobVersionSha));

boolean jobEnabled = false;
boolean jobEnabled = true;
DesiredDataJobDeployment desiredDataJobDeployment =
createDesiredDataJobDeployment(testJobVersionSha, jobEnabled);

Expand Down Expand Up @@ -149,7 +149,7 @@ public void testSynchronizeDataJob() throws Exception {
Assertions.assertEquals(lastDeployedDateInitial, lastDeployedDateShouldNotBeChanged);

// Tries to redeploy job with changes
jobEnabled = true;
jobEnabled = false;
desiredDataJobDeployment = updateDataJobDeployment(jobEnabled);
dataJobsSynchronizer.synchronizeDataJob(
dataJob, desiredDataJobDeployment, actualDataJobDeployment, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,10 @@ public void updateDeployment(
dockerRegistryService.dataJobImage(
desiredJobDeployment.getDataJobName(), desiredJobDeployment.getGitCommitSha());

if (jobImageBuilder.buildImage(
imageName, dataJob, desiredJobDeployment, actualJobDeployment, sendNotification)) {
// If the job suspension operation is performed, we don't want to build the image.
if (Boolean.FALSE.equals(desiredJobDeployment.getEnabled())
|| jobImageBuilder.buildImage(
imageName, dataJob, desiredJobDeployment, actualJobDeployment, sendNotification)) {
ActualDataJobDeployment actualJobDeploymentResult =
jobImageDeployer.scheduleJob(
dataJob,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public Set<String> listCronJobs() throws ApiException {
v1CronJobs.getItems().stream()
.map(j -> j.getMetadata().getName())
.collect(Collectors.toSet());
log.debug("K8s V1 cron jobs: {}", v1CronJobNames);
log.trace("K8s V1 cron jobs: {}", v1CronJobNames);
} catch (ApiException e) {
if (e.getCode()
== 404) { // as soon as the minimum supported k8s version is >=1.21 then we should remove
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class DeploymentServiceV2TestIT {

@MockBean private JobImageBuilder jobImageBuilder;

@MockBean private JobImageDeployerV2 jobImageDeployer;

@Test
public void updateDeployment_withDesiredDeploymentStatusUserError_shouldSkipDeployment()
throws IOException, InterruptedException, ApiException {
Expand Down Expand Up @@ -69,6 +71,34 @@ public void updateDeployment_withDesiredDeploymentStatusNone_shouldStartDeployme
.buildImage(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.eq(false));
}

@Test
public void
updateDeployment_withDesiredDeploymentEnabledFalseAndActualDeploymentEnabledTrueAndBuildImageSucceededFalse_shouldUpdateDeployment()
throws IOException, InterruptedException, ApiException {
updateDeployment(false, true, false, 1);
}

@Test
public void
updateDeployment_withDesiredDeploymentEnabledFalseAndActualDeploymentEnabledFalseAndBuildImageSucceededFalse_shouldUpdateDeployment()
throws IOException, InterruptedException, ApiException {
updateDeployment(false, false, false, 1);
}

@Test
public void
updateDeployment_withDesiredDeploymentEnabledTrueAndActualDeploymentEnabledFalseAndBuildImageSucceededTrue_shouldUpdateDeployment()
throws IOException, InterruptedException, ApiException {
updateDeployment(true, false, true, 1);
}

@Test
public void
updateDeployment_withDesiredDeploymentEnabledTrueAndActualDeploymentEnabledFalseAndBuildImageSucceededFalse_shouldUpdateDeployment()
throws IOException, InterruptedException, ApiException {
updateDeployment(true, false, false, 0);
}

private void updateDeployment(
DeploymentStatus deploymentStatus, int deploymentProgressStartedInvocations)
throws IOException, InterruptedException, ApiException {
Expand Down Expand Up @@ -96,4 +126,37 @@ private void updateDeployment(
Mockito.verify(deploymentProgress, Mockito.times(deploymentProgressStartedInvocations))
.started(dataJob.getJobConfig(), desiredDataJobDeployment);
}

private void updateDeployment(
boolean desiredDeploymentEnabled,
boolean actualDeploymentEnabled,
boolean buildImageSucceeded,
int deploymentProgressStartedInvocations)
throws IOException, InterruptedException, ApiException {
DesiredDataJobDeployment desiredDataJobDeployment = new DesiredDataJobDeployment();
desiredDataJobDeployment.setEnabled(desiredDeploymentEnabled);
desiredDataJobDeployment.setStatus(DeploymentStatus.NONE);

ActualDataJobDeployment actualDeployment = new ActualDataJobDeployment();
actualDeployment.setEnabled(actualDeploymentEnabled);

DataJob dataJob = new DataJob();
dataJob.setJobConfig(new JobConfig());

Mockito.when(
jobImageBuilder.buildImage(
Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any()))
.thenReturn(buildImageSucceeded);

deploymentService.updateDeployment(dataJob, desiredDataJobDeployment, actualDeployment, true);

Mockito.verify(jobImageDeployer, Mockito.times(deploymentProgressStartedInvocations))
.scheduleJob(
Mockito.any(),
Mockito.any(),
Mockito.any(),
Mockito.anyBoolean(),
Mockito.anyBoolean(),
Mockito.anyString());
}
}