Skip to content

Commit

Permalink
Add support for private image registry
Browse files Browse the repository at this point in the history
  • Loading branch information
cnogradi committed Oct 20, 2023
1 parent fa6fb0d commit 1b06309
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class WorkerConfigs {
private final Map<String, String> workerKubeAnnotations;
private final Map<String, String> workerKubeLabels;
private final List<String> jobImagePullSecrets;
private final String jobImageRegistry;
private final String jobImagePullPolicy;
private final String sidecarImagePullPolicy;
private final String jobSocatImage;
Expand All @@ -41,6 +42,7 @@ public WorkerConfigs(final WorkerEnvironment workerEnvironment,
final Map<String, String> workerKubeAnnotations,
final Map<String, String> workerKubeLabels,
final List<String> jobImagePullSecrets,
final String jobImageRegistry,
final String jobImagePullPolicy,
final String sidecarImagePullPolicy,
final String jobSocatImage,
Expand All @@ -55,6 +57,7 @@ public WorkerConfigs(final WorkerEnvironment workerEnvironment,
this.workerKubeAnnotations = workerKubeAnnotations;
this.workerKubeLabels = workerKubeLabels;
this.jobImagePullSecrets = jobImagePullSecrets;
this.jobImageRegistry = jobImageRegistry;
this.jobImagePullPolicy = jobImagePullPolicy;
this.sidecarImagePullPolicy = sidecarImagePullPolicy;
this.jobSocatImage = jobSocatImage;
Expand All @@ -78,6 +81,7 @@ public WorkerConfigs(final Configs configs) {
configs.getJobKubeAnnotations(),
configs.getJobKubeLabels(),
configs.getJobKubeMainContainerImagePullSecrets(),
null,
configs.getJobKubeMainContainerImagePullPolicy(),
configs.getJobKubeSidecarContainerImagePullPolicy(),
configs.getJobKubeSocatImage(),
Expand Down Expand Up @@ -118,6 +122,10 @@ public List<String> getJobImagePullSecrets() {
return jobImagePullSecrets;
}

public String getJobImageRegistry() {
return jobImageRegistry;
}

public String getJobImagePullPolicy() {
return jobImagePullPolicy;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ record WorkerConfigsDefaults(WorkerEnvironment workerEnvironment,
@Value("${airbyte.worker.isolated.kube.node-selectors}") String isolatedNodeSelectors,
@Value("${airbyte.worker.isolated.kube.use-custom-node-selector}") boolean useCustomNodeSelector,
@Value("${airbyte.worker.job.kube.main.container.image-pull-secret}") List<String> mainContainerImagePullSecret,
@Value("${airbyte.worker.job.kube.main.container.image-registry}") String mainContainerImageRegistry,
@Value("${airbyte.worker.job.kube.main.container.image-pull-policy}") String mainContainerImagePullPolicy,
@Value("${airbyte.worker.job.kube.sidecar.container.image-pull-policy}") String sidecarContainerImagePullPolicy,
@Value("${airbyte.worker.job.kube.images.socat}") String socatImage,
Expand Down Expand Up @@ -249,6 +250,7 @@ private WorkerConfigs getConfig(final KubeResourceKey key) {
annotations,
splitKVPairsFromEnvString(kubeResourceConfig.getLabels()),
workerConfigsDefaults.mainContainerImagePullSecret(),
workerConfigsDefaults.mainContainerImageRegistry(),
workerConfigsDefaults.mainContainerImagePullPolicy(),
workerConfigsDefaults.sidecarContainerImagePullPolicy(),
workerConfigsDefaults.socatImage(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ airbyte:
socat: ${UNUSED_VALUE:}
main:
container:
image-registry: ${UNUSED_VALUE:}
image-pull-policy: ${UNUSED_VALUE:}
image-pull-secret: ${UNUSED_VALUE:}
sidecar:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,10 @@ public Process create(final ResourceType resourceType,
rebasePath(jobRoot).toString(), // rebases the job root on the job data mount
"--log-driver",
"none");
final String containerName = ProcessFactory.createProcessName(imageName, jobType, jobId, attempt, DOCKER_NAME_LEN_LIMIT);
final WorkerConfigs workerConfigs = workerConfigsProvider.getConfig(resourceType);
final String registry = workerConfigs.getJobImageRegistry();
final String image = null == registry || imageName.startsWith(registry) ? imageName : registry + "/" + imageName;
final String containerName = ProcessFactory.createProcessName(image, jobType, jobId, attempt, DOCKER_NAME_LEN_LIMIT);
final ResourceRequirements resourceRequirements = connectorResourceRequirements.main();
LOGGER.info("Creating docker container = {} with resources {} and allowedHosts {}", containerName, resourceRequirements, allowedHosts);
cmd.add("--name");
Expand All @@ -158,7 +161,6 @@ public Process create(final ResourceType resourceType,
cmd.add(String.format("%s:%s", localMountSource, LOCAL_MOUNT_DESTINATION));
}

final WorkerConfigs workerConfigs = workerConfigsProvider.getConfig(resourceType);
final Map<String, String> allEnvMap = MoreMaps.merge(jobMetadata, workerConfigs.getEnvMap());
for (final Map.Entry<String, String> envEntry : allEnvMap.entrySet()) {
cmd.add("-e");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ public Process create(

final Context featureFlagContext = createFeatureFlagContext(connectionId, workspaceId, imageName);

final String registry = workerConfigs.getJobImageRegistry();
final String image = null == registry || imageName.startsWith(registry) ? imageName : registry + "/" + imageName;

return new KubePodProcess(
processRunnerHost,
fabricClient,
Expand All @@ -162,7 +165,7 @@ public Process create(
namespace,
serviceAccount,
schedulerName.isBlank() ? null : schedulerName,
imageName,
image,
workerConfigs.getJobImagePullPolicy(),
workerConfigs.getSidecarImagePullPolicy(),
stdoutLocalPort,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ airbyte:
socat: ${JOB_KUBE_SOCAT_IMAGE:`alpine/socat:1.7.4.3-r0`}
main:
container:
image-registry: ${JOB_KUBE_MAIN_CONTAINER_IMAGE_REGISTRY:}
image-pull-policy: ${JOB_KUBE_MAIN_CONTAINER_IMAGE_PULL_POLICY:IfNotPresent}
image-pull-secret: ${JOB_KUBE_MAIN_CONTAINER_IMAGE_PULL_SECRET:}
sidecar:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ airbyte:
socat: ${JOB_KUBE_SOCAT_IMAGE:`alpine/socat:1.7.4.3-r0`}
main:
container:
image-registry: ${JOB_KUBE_MAIN_CONTAINER_IMAGE_REGISTRY:}
image-pull-policy: ${JOB_KUBE_MAIN_CONTAINER_IMAGE_PULL_POLICY:IfNotPresent}
image-pull-secret: ${JOB_KUBE_MAIN_CONTAINER_IMAGE_PULL_SECRET:}
sidecar:
Expand Down
1 change: 1 addition & 0 deletions airbyte-server/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ airbyte:
socat: ${JOB_KUBE_SOCAT_IMAGE:`alpine/socat:1.7.4.3-r0`}
main:
container:
image-registry: ${JOB_KUBE_MAIN_CONTAINER_IMAGE_REGISTRY:}
image-pull-policy: ${JOB_KUBE_MAIN_CONTAINER_IMAGE_PULL_POLICY:IfNotPresent}
image-pull-secret: ${JOB_KUBE_MAIN_CONTAINER_IMAGE_PULL_SECRET:}
sidecar:
Expand Down
1 change: 1 addition & 0 deletions airbyte-workers/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ airbyte:
socat: ${JOB_KUBE_SOCAT_IMAGE:`alpine/socat:1.7.4.3-r0`}
main:
container:
image-registry: ${JOB_KUBE_MAIN_CONTAINER_IMAGE_REGISTRY:}
image-pull-policy: ${JOB_KUBE_MAIN_CONTAINER_IMAGE_PULL_POLICY:IfNotPresent}
image-pull-secret: ${JOB_KUBE_MAIN_CONTAINER_IMAGE_PULL_SECRET:}
namespace: ${JOB_KUBE_NAMESPACE:default}
Expand Down

0 comments on commit 1b06309

Please sign in to comment.