Skip to content

Commit

Permalink
control-service: set build job impagePullPolicity to default to IfNot…
Browse files Browse the repository at this point in the history
…Present (#549)

We rarely change the version (tag) of the builder job image. There's not
point of trying to pull it every time , so this is setting it to
IfNotPresent. This way we can limit the chance of hitting docker limits.

It's made configurable using
`datajobs.deployment.builder.imagePullPolicy` system property in case in
some environments it is necessary.

Testing Done: integration test passed

Signed-off-by: Antoni Ivanov <[email protected]>
  • Loading branch information
antoniivanov authored Dec 1, 2021
1 parent 777f9f0 commit bff4b91
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
public class JobImageBuilder {
private static final Logger log = LoggerFactory.getLogger(JobImageBuilder.class);

static final String BUILDER_IMAGE_PULL_POLICY = "Always";
private static final int BUILDER_TIMEOUT_SECONDS = 1800;
private static final String REGISTRY_TYPE_ECR = "ecr";
private static final String REGISTRY_TYPE_GENERIC = "generic";
Expand Down Expand Up @@ -59,7 +58,9 @@ public class JobImageBuilder {
@Value("${datajobs.deployment.dataJobBaseImage:python:3.9-slim}")
private String deploymentDataJobBaseImage;
@Value("${datajobs.deployment.builder.extraArgs:}")
private String extraArgs;
private String builderJobExtraArgs;
@Value("${datajobs.deployment.builder.imagePullPolicy:IfNotPresent}")
private String builderJobImagePullPolicy;
@Value("${datajobs.git.ssl.enabled}")
private boolean gitDataJobsSslEnabled;

Expand Down Expand Up @@ -151,7 +152,7 @@ public boolean buildImage(String imageName, DataJob dataJob, JobDeployment jobDe
args,
null,
null,
BUILDER_IMAGE_PULL_POLICY,
builderJobImagePullPolicy,
kubernetesResources.builderRequests(),
kubernetesResources.builderLimits());

Expand Down Expand Up @@ -217,7 +218,7 @@ private Map<String, String> getBuildParameters(DataJob dataJob, JobDeployment jo
entry("JOB_GITHASH", jobVersion),
entry("IMAGE_REGISTRY_PATH", dockerRepositoryUrl),
entry("BASE_IMAGE", deploymentDataJobBaseImage),
entry("EXTRA_ARGUMENTS", extraArgs),
entry("EXTRA_ARGUMENTS", builderJobExtraArgs),
entry("GIT_SSL_ENABLED", Boolean.toString(gitDataJobsSslEnabled))
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,8 @@ datajobs.executions.cleanupJob.executionsTtlSeconds=${DATAJOBS_EXECUTION_TTL_SEC

# https://javaee.github.io/javamail/docs/api/com/sun/mail/smtp/package-summary.html
mail.smtp.host=smtp.vmware.com

# Set imagePullPolicy of the job-builder image
# Correspond to those defined by kubernetes
# See https://kubernetes.io/docs/concepts/containers/images/#image-pull-policy
datajobs.deployment.builder.imagePullPolicy=IfNotPresent
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void setUp() {
ReflectionTestUtils.setField(jobImageBuilder, "dockerRepositoryUrl", "test-docker-repository");
ReflectionTestUtils.setField(jobImageBuilder, "registryType", "ecr");
ReflectionTestUtils.setField(jobImageBuilder, "deploymentDataJobBaseImage", "python:3.7-slim");
ReflectionTestUtils.setField(jobImageBuilder, "extraArgs", "");
ReflectionTestUtils.setField(jobImageBuilder, "builderJobExtraArgs", "");

JobConfig jobConfig = new JobConfig();
jobConfig.setDbDefaultType(TEST_DB_DEFAULT_TYPE);
Expand Down Expand Up @@ -88,7 +88,7 @@ public void buildImage_notExist_success() throws InterruptedException, ApiExcept

verify(kubernetesService).createJob(
eq(TEST_BUILDER_JOB_NAME), eq(TEST_BUILDER_IMAGE_NAME), eq(false), any(), any(),
any(), any(), eq(JobImageBuilder.BUILDER_IMAGE_PULL_POLICY), any(), any());
any(), any(), any(), any(), any());

verify(kubernetesService).deleteJob(TEST_BUILDER_JOB_NAME);
Assertions.assertTrue(result);
Expand All @@ -114,7 +114,7 @@ public void buildImage_builderRunning_oldBuilderDeleted() throws InterruptedExce
verify(kubernetesService, times(2)).deleteJob(TEST_BUILDER_IMAGE_NAME);
verify(kubernetesService).createJob(
eq(TEST_BUILDER_JOB_NAME), eq(TEST_BUILDER_IMAGE_NAME), eq(false), any(), any(),
any(), any(), eq(JobImageBuilder.BUILDER_IMAGE_PULL_POLICY), any(), any());
any(), any(), any(), any(), any());
Assertions.assertTrue(result);
}

Expand Down Expand Up @@ -156,7 +156,7 @@ public void buildImage_jobFailed_failure() throws InterruptedException, ApiExcep

verify(kubernetesService).createJob(
eq(TEST_BUILDER_JOB_NAME), eq(TEST_BUILDER_IMAGE_NAME), eq(false), any(), any(),
any(), any(), eq(JobImageBuilder.BUILDER_IMAGE_PULL_POLICY), any(), any());
any(), any(), any(), any(), any());


// verify(kubernetesService).deleteJob(TEST_BUILDER_JOB_NAME); // not called in case of an error
Expand Down

0 comments on commit bff4b91

Please sign in to comment.